You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2015/04/12 17:46:25 UTC

thrift git commit: THRIFT-2850 CMake for Apache Thrift add test/cpp and lib/py

Repository: thrift
Updated Branches:
  refs/heads/master 79e971e7d -> 2659381e7


THRIFT-2850 CMake for Apache Thrift
add test/cpp and lib/py


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/2659381e
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/2659381e
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/2659381e

Branch: refs/heads/master
Commit: 2659381e7f94b825c0b1ff6e80a119035a4a0de5
Parents: 79e971e
Author: Roger Meier <ro...@apache.org>
Authored: Sun Apr 12 16:10:35 2015 +0200
Committer: Roger Meier <ro...@apache.org>
Committed: Sun Apr 12 16:10:35 2015 +0200

----------------------------------------------------------------------
 CMakeLists.txt                  | 11 ++++++
 build/cmake/DefineOptions.cmake | 10 ++++--
 build/cmake/FindLibevent.cmake  | 39 ++++++++++++++++++++
 build/cmake/README.md           |  2 +-
 test/cpp/CMakeLists.txt         | 70 ++++++++++++++++++++++++++++++++++++
 5 files changed, 129 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/2659381e/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3fe0f92..f20d069 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -61,6 +61,10 @@ find_package(Threads)
 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 @@ endif()
 
 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 @@ if(WITH_JAVA)
     add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/java)
 endif()
 
+if(WITH_PYTHON)
+    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/lib/py)
+endif()
+
 PRINT_CONFIG_SUMMARY()

http://git-wip-us.apache.org/repos/asf/thrift/blob/2659381e/build/cmake/DefineOptions.cmake
----------------------------------------------------------------------
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 @@ CMAKE_DEPENDENT_OPTION(WITH_C_GLIB "Build C (GLib) library" ON
 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 configuration Summary")
 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}")

http://git-wip-us.apache.org/repos/asf/thrift/blob/2659381e/build/cmake/FindLibevent.cmake
----------------------------------------------------------------------
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
+  )

http://git-wip-us.apache.org/repos/asf/thrift/blob/2659381e/build/cmake/README.md
----------------------------------------------------------------------
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 @@ just do this:
 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 @@ to generate an installer and distribution package do this:
 * 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

http://git-wip-us.apache.org/repos/asf/thrift/blob/2659381e/test/cpp/CMakeLists.txt
----------------------------------------------------------------------
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
+)