blob: 7653ed6dc8773982257d7a70cc8bec7c408094c2 [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
Nobuaki Sukegawaef2b5282015-12-11 02:24:17 +090044 test/JSONSpec.hs
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090045 )
46 set(hs_enable_test "--enable-tests")
47endif()
48
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090049set(haskell_artifacts thrift_cabal.stamp)
50# Adding *.hi files so that any missing file triggers the build
51foreach(SRC ${haskell_sources})
52 get_filename_component(EX ${SRC} EXT)
53 if(${EX} STREQUAL ".hs")
54 file(RELATIVE_PATH REL ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/${SRC})
55 get_filename_component(DIR ${REL} DIRECTORY)
56 get_filename_component(BASE ${REL} NAME_WE)
57 list(APPEND haskell_artifacts dist/build/${DIR}/${BASE}.hi)
58 endif()
59endforeach()
60
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090061if(CMAKE_BUILD_TYPE STREQUAL "Debug")
62 set(hs_optimize -O0)
Nobuaki Sukegawae8c71d82015-11-23 19:51:37 +090063elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090064 set(hs_optimize -O1)
Nobuaki Sukegawae8c71d82015-11-23 19:51:37 +090065endif()
66
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090067add_custom_command(
68 OUTPUT ${haskell_artifacts}
69 COMMAND ${CABAL} update
70 # Build dependencies first without --builddir, otherwise it fails.
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090071 COMMAND ${CABAL} install --only-dependencies ${hs_enable_test}
72 COMMAND ${CABAL} configure ${hs_optimize} ${hs_enable_test} --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
73 COMMAND ${CABAL} build --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090074 COMMAND ${CABAL} install --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
75 COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/thrift_cabal.stamp
76 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
77 DEPENDS ${haskell_sources}
78 COMMENT "Building Haskell library")
79
80add_custom_target(haskell_library ALL
81 DEPENDS ${haskell_artifacts})
82
83if(BUILD_TESTING)
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090084 add_test(NAME HaskellCabalCheck
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090085 COMMAND ${CABAL} check
86 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Nobuaki Sukegawa7c7d6792015-12-09 03:22:35 +090087 add_test(NAME HaskellCabalTest
88 # Cabal fails to find built executable when --builddir is specified.
89 # So we invoke the executable directly.
90 # COMMAND ${CABAL} test --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
91 # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
92 COMMAND dist/build/spec/spec)
Nobuaki Sukegawa27378fa2015-10-29 00:41:39 +090093endif()