blob: b5d1d205299f85230e6e2cd621812ef968e5c84d [file] [log] [blame]
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +09001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
20# Rebuild when any of these files changes
21set(haskell_sources
22 src/Thrift.hs
23 src/Thrift/Arbitraries.hs
24 src/Thrift/Protocol.hs
25 src/Thrift/Protocol/Binary.hs
26 src/Thrift/Protocol/Compact.hs
27 src/Thrift/Protocol/JSON.hs
28 src/Thrift/Server.hs
29 src/Thrift/Transport.hs
30 src/Thrift/Transport/Empty.hs
31 src/Thrift/Transport/Framed.hs
32 src/Thrift/Transport/Handle.hs
33 src/Thrift/Transport/HttpClient.hs
34 src/Thrift/Transport/IOBuffer.hs
35 src/Thrift/Types.hs
36 Thrift.cabal
37)
38
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090039if(BUILD_TESTING)
40 list(APPEND haskell_soruces
41 test/Spec.hs
42 test/BinarySpec.hs
43 test/CompactSpec.hs
44 )
45 set(hs_enable_test "--enable-tests")
46endif()
47
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090048set(haskell_artifacts thrift_cabal.stamp)
49# Adding *.hi files so that any missing file triggers the build
50foreach(SRC ${haskell_sources})
51 get_filename_component(EX ${SRC} EXT)
52 if(${EX} STREQUAL ".hs")
53 file(RELATIVE_PATH REL ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/${SRC})
54 get_filename_component(DIR ${REL} DIRECTORY)
55 get_filename_component(BASE ${REL} NAME_WE)
56 list(APPEND haskell_artifacts dist/build/${DIR}/${BASE}.hi)
57 endif()
58endforeach()
59
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090060if(CMAKE_BUILD_TYPE STREQUAL "Debug")
61 set(hs_optimize -O0)
Nobuaki Sukegawae8c71d82015-11-23 19:51:37 +090062elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090063 set(hs_optimize -O1)
Nobuaki Sukegawae8c71d82015-11-23 19:51:37 +090064endif()
65
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090066add_custom_command(
67 OUTPUT ${haskell_artifacts}
68 COMMAND ${CABAL} update
69 # Build dependencies first without --builddir, otherwise it fails.
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090070 COMMAND ${CABAL} install --only-dependencies ${hs_enable_test}
71 COMMAND ${CABAL} configure ${hs_optimize} ${hs_enable_test} --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
72 COMMAND ${CABAL} build --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090073 COMMAND ${CABAL} install --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
74 COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/thrift_cabal.stamp
75 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
76 DEPENDS ${haskell_sources}
77 COMMENT "Building Haskell library")
78
79add_custom_target(haskell_library ALL
80 DEPENDS ${haskell_artifacts})
81
82if(BUILD_TESTING)
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090083 add_test(NAME HaskellCabalCheck
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090084 COMMAND ${CABAL} check
85 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090086 add_test(NAME HaskellCabalTest
87 # Cabal fails to find built executable when --builddir is specified.
88 # So we invoke the executable directly.
89 # COMMAND ${CABAL} test --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
90 # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
91 COMMAND dist/build/spec/spec)
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090092endif()