]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | # |
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 | |
21 | set(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 | ||
39 | if(BUILD_TESTING) | |
40 | list(APPEND haskell_soruces | |
41 | test/Spec.hs | |
42 | test/BinarySpec.hs | |
43 | test/CompactSpec.hs | |
44 | test/JSONSpec.hs | |
45 | ) | |
46 | set(hs_enable_test "--enable-tests") | |
47 | endif() | |
48 | ||
49 | set(haskell_artifacts thrift_cabal.stamp) | |
50 | # Adding *.hi files so that any missing file triggers the build | |
51 | foreach(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() | |
59 | endforeach() | |
60 | ||
61 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") | |
62 | set(hs_optimize -O0) | |
63 | else() | |
64 | set(hs_optimize -O1) | |
65 | endif() | |
66 | ||
67 | add_custom_command( | |
68 | OUTPUT ${haskell_artifacts} | |
69 | COMMAND ${CABAL} update | |
70 | # Build dependencies first without --builddir, otherwise it fails. | |
71 | 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 | |
74 | 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 | ||
80 | add_custom_target(haskell_library ALL | |
81 | DEPENDS ${haskell_artifacts}) | |
82 | ||
83 | if(BUILD_TESTING) | |
84 | add_test(NAME HaskellCabalCheck | |
85 | COMMAND ${CABAL} check | |
86 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) | |
87 | 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) | |
93 | endif() |