Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 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 |
Gregor Reitzenstein | a718ad4 | 2017-05-10 10:02:54 +0200 | [diff] [blame] | 36 | thrift.cabal |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 37 | ) |
| 38 | |
Nobuaki Sukegawa | 7c7d679 | 2015-12-09 03:22:35 +0900 | [diff] [blame] | 39 | if(BUILD_TESTING) |
| 40 | list(APPEND haskell_soruces |
| 41 | test/Spec.hs |
| 42 | test/BinarySpec.hs |
| 43 | test/CompactSpec.hs |
Nobuaki Sukegawa | ef2b528 | 2015-12-11 02:24:17 +0900 | [diff] [blame] | 44 | test/JSONSpec.hs |
Nobuaki Sukegawa | 7c7d679 | 2015-12-09 03:22:35 +0900 | [diff] [blame] | 45 | ) |
| 46 | set(hs_enable_test "--enable-tests") |
| 47 | endif() |
| 48 | |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 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 | |
Nobuaki Sukegawa | 7c7d679 | 2015-12-09 03:22:35 +0900 | [diff] [blame] | 61 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 62 | set(hs_optimize -O0) |
Nobuaki Sukegawa | e8c71d8 | 2015-11-23 19:51:37 +0900 | [diff] [blame] | 63 | elseif(CMAKE_BUILD_TYPE STREQUAL "Release") |
Nobuaki Sukegawa | 7c7d679 | 2015-12-09 03:22:35 +0900 | [diff] [blame] | 64 | set(hs_optimize -O1) |
Nobuaki Sukegawa | e8c71d8 | 2015-11-23 19:51:37 +0900 | [diff] [blame] | 65 | endif() |
| 66 | |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 67 | add_custom_command( |
| 68 | OUTPUT ${haskell_artifacts} |
| 69 | COMMAND ${CABAL} update |
| 70 | # Build dependencies first without --builddir, otherwise it fails. |
Nobuaki Sukegawa | 7c7d679 | 2015-12-09 03:22:35 +0900 | [diff] [blame] | 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 |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 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) |
Nobuaki Sukegawa | 7c7d679 | 2015-12-09 03:22:35 +0900 | [diff] [blame] | 84 | add_test(NAME HaskellCabalCheck |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 85 | COMMAND ${CABAL} check |
| 86 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) |
Nobuaki Sukegawa | 7c7d679 | 2015-12-09 03:22:35 +0900 | [diff] [blame] | 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) |
Nobuaki Sukegawa | 27378fa | 2015-10-29 00:41:39 +0900 | [diff] [blame] | 93 | endif() |