summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml4
-rw-r--r--CMakeLists.txt7
-rw-r--r--build/cmake/DefineOptions.cmake11
-rw-r--r--build/cmake/FindCabal.cmake30
-rw-r--r--build/cmake/FindGHC.cmake36
-rw-r--r--lib/hs/CMakeLists.txt69
-rw-r--r--test/hs/CMakeLists.txt107
7 files changed, 262 insertions, 2 deletions
diff --git a/.travis.yml b/.travis.yml
index 587d79597..5be7c340f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -79,9 +79,9 @@ env:
CMAKE_CONFIG=""
ALL_DEPS="yes"
- TEST_NAME="C++/boost-threads (CMake + CPack)"
- CMAKE_CONFIG="-DWITH_C_GLIB=OFF -DWITH_JAVA=OFF -DWITH_BOOSTTHREADS=ON"
+ CMAKE_CONFIG="-DWITH_C_GLIB=OFF -DWITH_JAVA=OFF -DWITH_HASKELL=OFF -DWITH_BOOSTTHREADS=ON"
- TEST_NAME="C++/std-threads (CMake + CPack)"
- CMAKE_CONFIG="-DCMAKE_CXX_FLAGS=-std=c++0x -DWITH_C_GLIB=OFF -DWITH_JAVA=OFF -DWITH_STDTHREADS=ON"
+ CMAKE_CONFIG="-DCMAKE_CXX_FLAGS=-std=c++0x -DWITH_C_GLIB=OFF -DWITH_JAVA=OFF -DWITH_HASKELL=OFF -DWITH_STDTHREADS=ON"
- TEST_NAME="compiler (mingw32-gcc, CMake + CPack)"
CMAKE_CONFIG="-DCMAKE_TOOLCHAIN_FILE=../build/cmake/mingw32-toolchain.cmake -DBUILD_COMPILER=ON -DBUILD_LIBRARIES=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF"
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 44f65afbf..f3005f56e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -100,4 +100,11 @@ if(BUILD_PYTHON)
endif()
endif()
+if(BUILD_HASKELL)
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/hs)
+ if(BUILD_TESTING)
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/hs)
+ endif()
+endif()
+
PRINT_CONFIG_SUMMARY()
diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake
index 62e240f36..0aad240ef 100644
--- a/build/cmake/DefineOptions.cmake
+++ b/build/cmake/DefineOptions.cmake
@@ -86,6 +86,13 @@ find_package(PythonLibs QUIET) # for Python.h
CMAKE_DEPENDENT_OPTION(BUILD_PYTHON "Build Python library" ON
"BUILD_LIBRARIES;WITH_PYTHON;PYTHONLIBS_FOUND" OFF)
+# Haskell
+option(WITH_HASKELL "Build Haskell Thrift library" ON)
+find_package(GHC QUIET)
+find_package(Cabal QUIET)
+CMAKE_DEPENDENT_OPTION(BUILD_HASKELL "Build GHC library" ON
+ "BUILD_LIBRARIES;WITH_HASKELL;GHC_FOUND;CABAL_FOUND" OFF)
+
# Common library options
option(WITH_SHARED_LIB "Build shared libraries" ON)
option(WITH_STATIC_LIB "Build static libraries" ON)
@@ -129,6 +136,10 @@ MESSAGE_DEP(ANT_FOUND "Ant missing")
message(STATUS " Build Python library: ${BUILD_PYTHON}")
MESSAGE_DEP(WITH_PYTHON "Disabled by via WITH_PYTHON=OFF")
MESSAGE_DEP(PYTHONLIBS_FOUND "Python libraries missing")
+message(STATUS " Build Haskell library: ${BUILD_HASKELL}")
+MESSAGE_DEP(WITH_HASKELL "Disabled by via WITH_HASKELL=OFF")
+MESSAGE_DEP(GHC_FOUND "GHC missing")
+MESSAGE_DEP(CABAL_FOUND "Cabal missing")
message(STATUS " Library features:")
message(STATUS " Build shared libraries: ${WITH_SHARED_LIB}")
message(STATUS " Build static libraries: ${WITH_STATIC_LIB}")
diff --git a/build/cmake/FindCabal.cmake b/build/cmake/FindCabal.cmake
new file mode 100644
index 000000000..fed337bd4
--- /dev/null
+++ b/build/cmake/FindCabal.cmake
@@ -0,0 +1,30 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+# Cabal_FOUND - system has Cabal
+# Cabal - the Cabal executable
+#
+# It will search the environment variable CABAL_HOME if it is set
+
+include(FindPackageHandleStandardArgs)
+
+find_program(CABAL NAMES cabal PATHS $ENV{HOME}/.cabal/bin $ENV{CABAL_HOME}/bin)
+find_package_handle_standard_args(CABAL DEFAULT_MSG CABAL)
+mark_as_advanced(CABAL)
diff --git a/build/cmake/FindGHC.cmake b/build/cmake/FindGHC.cmake
new file mode 100644
index 000000000..48738472c
--- /dev/null
+++ b/build/cmake/FindGHC.cmake
@@ -0,0 +1,36 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+
+# GHC_FOUND - system has GHC
+# GHC - the GHC executable
+# RUN_HASKELL_FOUND - system has runhaskell
+# RUN_HASKELL - the runhaskell executable
+#
+# It will search the environment variable GHC_HOME if it is set
+
+include(FindPackageHandleStandardArgs)
+
+find_program(GHC NAMES ghc PATHS $ENV{GHC_HOME}/bin)
+find_package_handle_standard_args(GHC DEFAULT_MSG GHC)
+mark_as_advanced(GHC)
+
+find_program(RUN_HASKELL NAMES runhaskell PATHS $ENV{GHC_HOME}/bin)
+find_package_handle_standard_args(RUN_HASKELL DEFAULT_MSG RUN_HASKELL)
+mark_as_advanced(RUN_HASKELL)
diff --git a/lib/hs/CMakeLists.txt b/lib/hs/CMakeLists.txt
new file mode 100644
index 000000000..f28cb3748
--- /dev/null
+++ b/lib/hs/CMakeLists.txt
@@ -0,0 +1,69 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Rebuild when any of these files changes
+set(haskell_sources
+ src/Thrift.hs
+ src/Thrift/Arbitraries.hs
+ src/Thrift/Protocol.hs
+ src/Thrift/Protocol/Binary.hs
+ src/Thrift/Protocol/Compact.hs
+ src/Thrift/Protocol/JSON.hs
+ src/Thrift/Server.hs
+ src/Thrift/Transport.hs
+ src/Thrift/Transport/Empty.hs
+ src/Thrift/Transport/Framed.hs
+ src/Thrift/Transport/Handle.hs
+ src/Thrift/Transport/HttpClient.hs
+ src/Thrift/Transport/IOBuffer.hs
+ src/Thrift/Types.hs
+ Thrift.cabal
+)
+
+set(haskell_artifacts thrift_cabal.stamp)
+# Adding *.hi files so that any missing file triggers the build
+foreach(SRC ${haskell_sources})
+ get_filename_component(EX ${SRC} EXT)
+ if(${EX} STREQUAL ".hs")
+ file(RELATIVE_PATH REL ${CMAKE_CURRENT_SOURCE_DIR}/src ${CMAKE_CURRENT_SOURCE_DIR}/${SRC})
+ get_filename_component(DIR ${REL} DIRECTORY)
+ get_filename_component(BASE ${REL} NAME_WE)
+ list(APPEND haskell_artifacts dist/build/${DIR}/${BASE}.hi)
+ endif()
+endforeach()
+
+add_custom_command(
+ OUTPUT ${haskell_artifacts}
+ COMMAND ${CABAL} update
+ # Build dependencies first without --builddir, otherwise it fails.
+ COMMAND ${CABAL} install --dependencies-only
+ COMMAND ${CABAL} install --builddir=${CMAKE_CURRENT_BINARY_DIR}/dist
+ COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/thrift_cabal.stamp
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+ DEPENDS ${haskell_sources}
+ COMMENT "Building Haskell library")
+
+add_custom_target(haskell_library ALL
+ DEPENDS ${haskell_artifacts})
+
+if(BUILD_TESTING)
+ add_test(NAME CabalCheck
+ COMMAND ${CABAL} check
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+endif()
diff --git a/test/hs/CMakeLists.txt b/test/hs/CMakeLists.txt
new file mode 100644
index 000000000..d353950cb
--- /dev/null
+++ b/test/hs/CMakeLists.txt
@@ -0,0 +1,107 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+set(hs_test_gen
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ConstantsDemo_Consts.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ConstantsDemo_Types.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/DebugProtoTest_Consts.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/DebugProtoTest_Types.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/EmptyService_Client.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/EmptyService.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/EmptyService_Iface.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Include_Consts.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Include_Types.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Inherited_Client.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Inherited.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Inherited_Iface.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ReverseOrderService_Client.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ReverseOrderService.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ReverseOrderService_Iface.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/SecondService_Client.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/SecondService.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/SecondService_Iface.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ServiceForExceptionWithAMap_Client.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ServiceForExceptionWithAMap.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ServiceForExceptionWithAMap_Iface.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Srv_Client.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Srv.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Srv_Iface.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ThriftTest_Client.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ThriftTest_Consts.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ThriftTest.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ThriftTest_Iface.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/ThriftTest_Types.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Yowza_Client.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Yowza.hs
+ ${CMAKE_CURRENT_BINARY_DIR}/gen-hs/Yowza_Iface.hs
+)
+
+set(hs_crosstest_apps
+ ${CMAKE_CURRENT_BINARY_DIR}/TestServer
+ ${CMAKE_CURRENT_BINARY_DIR}/TestClient
+)
+set(hs_crosstest_args
+ -igen-hs
+ -odir=${CMAKE_CURRENT_BINARY_DIR}
+ -hidir=${CMAKE_CURRENT_BINARY_DIR}
+)
+add_custom_command(
+ OUTPUT ${hs_crosstest_apps}
+ COMMAND ${GHC} ${hs_crosstest_args} ${CMAKE_CURRENT_SOURCE_DIR}/TestServer.hs -o TestServer
+ COMMAND ${GHC} ${hs_crosstest_args} ${CMAKE_CURRENT_SOURCE_DIR}/TestClient.hs -o TestClient
+ DEPENDS ${hs_test_gen} haskell_library TestServer.hs TestClient.hs
+)
+add_custom_target(haskell_crosstest ALL
+ COMMENT "Building Haskell cross test executables"
+ DEPENDS ${hs_crosstest_apps}
+)
+
+set(hs_test_sources
+ ConstantsDemo_Main.hs
+ DebugProtoTest_Main.hs
+ Include_Main.hs
+ ThriftTest_Main.hs
+)
+set(hs_test_args
+ -Wall
+ -XScopedTypeVariables
+ -i${PROJECT_SOURCE_DIR}/lib/hs/src
+ -i${CMAKE_CURRENT_BINARY_DIR}/gen-hs
+)
+add_custom_target(haskell_tests ALL DEPENDS ${hs_test_gen})
+foreach(SRC ${hs_test_sources})
+ get_filename_component(BASE ${SRC} NAME_WE)
+ add_test(NAME HaskellTests-${BASE}
+ COMMAND ${RUN_HASKELL} ${hs_test_args} ${SRC}
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+endforeach()
+
+set(hs_test_gen_sources
+ ${PROJECT_SOURCE_DIR}/test/ConstantsDemo.thrift
+ ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
+ ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+ ${PROJECT_SOURCE_DIR}/test/Include.thrift
+)
+add_custom_command(OUTPUT ${hs_test_gen}
+ COMMAND thrift-compiler --gen hs ${PROJECT_SOURCE_DIR}/test/ConstantsDemo.thrift
+ COMMAND thrift-compiler --gen hs ${PROJECT_SOURCE_DIR}/test/DebugProtoTest.thrift
+ COMMAND thrift-compiler --gen hs ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+ COMMAND thrift-compiler --gen hs ${PROJECT_SOURCE_DIR}/test/Include.thrift
+ DEPENDS thrift-compiler ${hs_test_gen_sources}
+)