blob: f28cb3748ba913d41c986ca635a75e0c3eddb1c0 [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
39set(haskell_artifacts thrift_cabal.stamp)
40# Adding *.hi files so that any missing file triggers the build
41foreach(SRC ${haskell_sources})
42 get_filename_component(EX ${SRC} EXT)
43 if(${EX} STREQUAL ".hs")
44 file(RELATIVE_PATH REL ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/${SRC})
45 get_filename_component(DIR ${REL} DIRECTORY)
46 get_filename_component(BASE ${REL} NAME_WE)
47 list(APPEND haskell_artifacts dist/build/${DIR}/${BASE}.hi)
48 endif()
49endforeach()
50
51add_custom_command(
52 OUTPUT ${haskell_artifacts}
53 COMMAND ${CABAL} update
54 # Build dependencies first without --builddir, otherwise it fails.
55 COMMAND ${CABAL} install --dependencies-only
56 COMMAND ${CABAL} install --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
57 COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/thrift_cabal.stamp
58 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
59 DEPENDS ${haskell_sources}
60 COMMENT "Building Haskell library")
61
62add_custom_target(haskell_library ALL
63 DEPENDS ${haskell_artifacts})
64
65if(BUILD_TESTING)
66 add_test(NAME CabalCheck
67 COMMAND ${CABAL} check
68 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
69endif()