THRIFT-2850 CMake for Apache Thrift
add test/cpp and lib/py
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3fe0f92..f20d069 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,6 +61,10 @@
include(CTest)
if(BUILD_TESTING)
message(STATUS "Building with unittests")
+
+ enable_testing()
+ # Define "make check" as alias for "make test"
+ add_custom_target(check COMMAND ctest)
else ()
message(STATUS "Building without tests")
endif ()
@@ -70,6 +74,9 @@
if(WITH_CPP)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/cpp)
+ if(BUILD_TESTING)
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/test/cpp)
+ endif()
endif()
if(WITH_C_GLIB)
@@ -80,4 +87,8 @@
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java)
endif()
+if(WITH_PYTHON)
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py)
+endif()
+
PRINT_CONFIG_SUMMARY()
diff --git a/build/cmake/DefineOptions.cmake b/build/cmake/DefineOptions.cmake
index 457deb6..f2eb76d 100644
--- a/build/cmake/DefineOptions.cmake
+++ b/build/cmake/DefineOptions.cmake
@@ -71,7 +71,12 @@
find_package(Java QUIET)
find_package(Ant QUIET)
CMAKE_DEPENDENT_OPTION(WITH_JAVA "Build Java library" ON
- "BUILD_LIBRARIES;JAVA_FOUND;Ant_FOUND" OFF)
+ "BUILD_LIBRARIES;JAVA_FOUND;ANT_FOUND" OFF)
+
+# Python
+include(FindPythonInterp QUIET)
+CMAKE_DEPENDENT_OPTION(WITH_PYTHON "Build Python library" ON
+ "BUILD_LIBRARIES;PYTHONINTERP_FOUND" OFF)
# Common library options
option(WITH_SHARED_LIB "Build shared libraries" ON)
@@ -92,11 +97,12 @@
message(STATUS " Build Thrift compiler: ${BUILD_COMPILER}")
message(STATUS " Build with unit tests: ${BUILD_TESTING}")
message(STATUS " Build examples: ${BUILD_EXAMPLES}")
-message(STATUS " Build Thrfit libraries: ${BUILD_LIBRARIES}")
+message(STATUS " Build Thrift libraries: ${BUILD_LIBRARIES}")
message(STATUS " Language libraries:")
message(STATUS " Build C++ library: ${WITH_CPP}")
message(STATUS " Build C (GLib) library: ${WITH_C_GLIB}")
message(STATUS " Build Java library: ${WITH_JAVA}")
+message(STATUS " Build Python library: ${WITH_PYTHON}")
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/FindLibevent.cmake b/build/cmake/FindLibevent.cmake
new file mode 100644
index 0000000..1eac315
--- /dev/null
+++ b/build/cmake/FindLibevent.cmake
@@ -0,0 +1,39 @@
+# find LibEvent
+# an event notification library (http://libevent.org/)
+#
+# Usage:
+# LIBEVENT_INCLUDE_DIRS, where to find LibEvent headers
+# LIBEVENT_LIBRARIES, LibEvent libraries
+# Libevent_FOUND, If false, do not try to use libevent
+
+set(LibEvent_EXTRA_PREFIXES /usr/local /opt/local "$ENV{HOME}")
+foreach(prefix ${LibEvent_EXTRA_PREFIXES})
+ list(APPEND LibEvent_INCLUDE_PATHS "${prefix}/include")
+ list(APPEND LibEvent_LIBRARIES_PATHS "${prefix}/lib")
+endforeach()
+
+find_path(LIBEVENT_INCLUDE_DIRS event.h PATHS ${LibEvent_INCLUDE_PATHS})
+find_library(LIBEVENT_LIBRARIES NAMES event PATHS ${LibEvent_LIBRARIES_PATHS})
+
+if (LIBEVENT_LIBRARIES AND LIBEVENT_INCLUDE_DIRS)
+ set(Libevent_FOUND TRUE)
+ set(LIBEVENT_LIBRARIES ${LIBEVENT_LIBRARIES})
+else ()
+ set(Libevent_FOUND FALSE)
+endif ()
+
+if (Libevent_FOUND)
+ if (NOT Libevent_FIND_QUIETLY)
+ message(STATUS "Found libevent: ${LIBEVENT_LIBRARIES}")
+ endif ()
+else ()
+ if (LibEvent_FIND_REQUIRED)
+ message(FATAL_ERROR "Could NOT find libevent.")
+ endif ()
+ message(STATUS "libevent NOT found.")
+endif ()
+
+mark_as_advanced(
+ LIBEVENT_LIBRARIES
+ LIBEVENT_INCLUDE_DIRS
+ )
diff --git a/build/cmake/README.md b/build/cmake/README.md
index a5dde19..d76a96e 100644
--- a/build/cmake/README.md
+++ b/build/cmake/README.md
@@ -21,6 +21,7 @@
if you use a specific toolchain pass it to cmake, the same for options:
cmake -DCMAKE_TOOLCHAIN_FILE=${THRIFT_SRC}/contrib/mingw32-toolchain.cmake ${THRIFT_SRC}
+ cmake -DCMAKE_C_COMPILER=clang-3.5 -DCMAKE_CXX_COMPILER=clang++-3.5 ${THRIFT_SRC}
cmake -DTHRIFT_COMPILER_HS=OFF ${THRIFT_SRC}
cmake -DWITH_ZLIB=ON ${THRIFT_SRC}
@@ -41,7 +42,6 @@
* build test
* with/without language lib/<lang>/
* enable/disable
-* make check (QUESTION: Is test the default CMake target?)
* make cross
* make dist (create an alias to make package_source)
* make doc
diff --git a/test/cpp/CMakeLists.txt b/test/cpp/CMakeLists.txt
new file mode 100755
index 0000000..d993c6d
--- /dev/null
+++ b/test/cpp/CMakeLists.txt
@@ -0,0 +1,70 @@
+#
+# 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(Boost_USE_STATIC_LIBS ON)
+find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options system filesystem)
+include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
+
+#Make sure gen-cpp files can be included
+include_directories("${CMAKE_CURRENT_BINARY_DIR}")
+include_directories("${CMAKE_CURRENT_BINARY_DIR}/gen-cpp")
+include_directories("${PROJECT_SOURCE_DIR}/lib/cpp/src")
+
+
+set(crosstestgencpp_SOURCES
+ gen-cpp/ThriftTest.cpp
+ gen-cpp/ThriftTest_types.cpp
+ gen-cpp/ThriftTest_constants.cpp
+)
+add_library(crosstestgencpp STATIC ${crosstestgencpp_SOURCES})
+target_link_libraries(crosstestgencpp thrift)
+
+set(crossstressgencpp_SOURCES
+ gen-cpp/Service.cpp
+ gen-cpp/StressTest_types.cpp
+ gen-cpp/StressTest_constants.cpp
+)
+add_library(crossstressgencpp STATIC ${crossstressgencpp_SOURCES})
+target_link_libraries(crossstressgencpp thrift)
+
+add_executable(TestServer src/TestServer.cpp)
+target_link_libraries(TestServer thrift thriftnb crosstestgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB})
+
+add_executable(TestClient src/TestClient.cpp)
+target_link_libraries(TestClient thrift thriftnb crosstestgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB})
+
+add_executable(StressTest src/StressTest.cpp)
+target_link_libraries(StressTest thrift thriftnb crossstressgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB})
+add_test(NAME StressTest COMMAND StressTest)
+
+add_executable(StressTestNonBlocking src/StressTestNonBlocking.cpp)
+target_link_libraries(StressTestNonBlocking thrift thriftz thriftnb crossstressgencpp ${Boost_LIBRARIES} ${LIBEVENT_LIB})
+add_test(NAME StressTestNonBlocking COMMAND StressTestNonBlocking)
+
+#
+# Common thrift code generation rules
+#
+
+add_custom_command(OUTPUT gen-cpp/ThriftTest.cpp gen-cpp/ThriftTest_types.cpp gen-cpp/ThriftTest_constants.cpp
+ COMMAND thrift-compiler --gen cpp:templates,cob_style -r ${PROJECT_SOURCE_DIR}/test/ThriftTest.thrift
+)
+
+add_custom_command(OUTPUT gen-cpp/StressTest_types.cpp gen-cpp/StressTest_constants.cpp gen-cpp/Service.cpp
+ COMMAND thrift-compiler --gen cpp ${PROJECT_SOURCE_DIR}/test/StressTest.thrift
+)