Skip to content

Commit 7608ef5

Browse files
committed
Merge pull request #259 from datastax/344
344: Make libssh2 optional when building tests
2 parents a9b62b0 + a36c6da commit 7608ef5

30 files changed

+408
-193
lines changed

CMakeLists.txt

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ if(POLICY CMP0042)
1313
cmake_policy(SET CMP0042 OLD)
1414
endif()
1515

16+
# Force OLD style of implicitly dereferencing variables
17+
if(POLICY CMP0054)
18+
cmake_policy(SET CMP0054 OLD)
19+
endif()
20+
1621
# Title the project and define the versioning
1722
project(${PROJECT_NAME_STR} C CXX)
1823

@@ -60,6 +65,8 @@ option(CASS_BUILD_STATIC "Build static library" OFF)
6065
option(CASS_BUILD_EXAMPLES "Build examples" OFF)
6166
option(CASS_BUILD_DOCS "Build documentation" OFF)
6267
option(CASS_BUILD_TESTS "Build tests" OFF)
68+
option(CASS_BUILD_INTEGRATION_TESTS "Build integration tests" OFF)
69+
option(CASS_BUILD_UNIT_TESTS "Build unit tests" OFF)
6370
option(CASS_INSTALL_HEADER "Install header file" ON)
6471
option(CASS_MULTICORE_COMPILATION "Enable multicore compilation" OFF)
6572
option(CASS_USE_STATIC_LIBS "Link static libraries when building executables" OFF)
@@ -69,8 +76,18 @@ option(CASS_USE_OPENSSL "Use OpenSSL" ON)
6976
option(CASS_USE_TCMALLOC "Use tcmalloc" OFF)
7077
option(CASS_USE_SPARSEHASH "Use sparsehash" OFF)
7178
option(CASS_USE_ZLIB "Use zlib" OFF)
79+
option(CASS_USE_LIBSSH2 "Use libssh2 for integration tests" ON)
7280

81+
# Handle testing dependencies
7382
if(CASS_BUILD_TESTS)
83+
# Enable integration and unit tests for backwards compatibility
84+
set(CASS_BUILD_INTEGRATION_TESTS ON)
85+
set(CASS_BUILD_UNIT_TESTS ON)
86+
endif()
87+
if(CASS_BUILD_INTEGRATION_TESTS)
88+
set(CASS_USE_OPENSSL ON) # Required for integration tests
89+
endif()
90+
if(CASS_BUILD_UNIT_TESTS)
7491
set(CASS_BUILD_STATIC ON) # Required for unit tests
7592
endif()
7693

@@ -142,7 +159,7 @@ set(CASS_LIBS ${CASS_LIBS} ${LIBUV_LIBRARY})
142159
#------------------------
143160

144161
# Boost
145-
if(CASS_USE_BOOST_ATOMIC OR CASS_BUILD_TESTS)
162+
if(CASS_USE_BOOST_ATOMIC OR CASS_BUILD_INTEGRATION_TESTS OR CASS_BUILD_UNIT_TESTS)
146163
# Allow for boost directory to be specified on the command line
147164
set(ENV{BOOST_ROOT} "${PROJECT_SOURCE_DIR}/lib/boost/")
148165
if(BOOST_ROOT_DIR)
@@ -178,7 +195,7 @@ if(CASS_USE_BOOST_ATOMIC OR CASS_BUILD_TESTS)
178195
endif()
179196

180197
# Ensure unit and integration test boost components exist
181-
if(CASS_BUILD_TESTS)
198+
if(CASS_BUILD_UNIT_TESTS OR CASS_BUILD_INTEGRATION_TESTS)
182199
find_package(Boost ${CASS_MINIMUM_BOOST_VERSION} COMPONENTS chrono date_time filesystem log log_setup system regex thread unit_test_framework)
183200
if(NOT Boost_FOUND)
184201
message(FATAL_ERROR "Boost [chrono, date_time, filesystem, log, log_setup, system, regex, thread, and unit_test_framework] are required to build tests")
@@ -295,21 +312,24 @@ endif()
295312
#--------------------
296313

297314
# libssh2
298-
if(CASS_BUILD_TESTS)
299-
# Setup the root directory for libssh2
300-
set(LIBSSH2_ROOT "${PROJECT_SOURCE_DIR}/lib/libssh2/" $ENV{LIBSSH2_ROOT})
301-
set(LIBSSH2_ROOT ${LIBSSH2_ROOT} ${LIBSSH2_ROOT_DIR} $ENV{LIBSSH2_ROOT_DIR})
302-
303-
# Discover libssh2
304-
find_package(LIBSSH2 REQUIRED)
305-
if(NOT LIBSSH2_FOUND)
306-
message(FATAL_ERROR "libssh2 are required to build tests")
307-
endif()
308-
309-
# Assign test libraries (additional boost and libssh2 dependencies)
310-
set(CASS_TEST_LIBS ${Boost_LIBRARIES} ${LIBSSH2_LIBRARIES})
311-
if(UNIX)
312-
set(CASS_TEST_LIBS ${CASS_TEST_LIBS} pthread)
315+
if(CASS_BUILD_INTEGRATION_TESTS)
316+
if(CASS_USE_LIBSSH2)
317+
# Setup the root directory for libssh2
318+
set(LIBSSH2_ROOT "${PROJECT_SOURCE_DIR}/lib/libssh2/" $ENV{LIBSSH2_ROOT})
319+
set(LIBSSH2_ROOT ${LIBSSH2_ROOT} ${LIBSSH2_ROOT_DIR} $ENV{LIBSSH2_ROOT_DIR})
320+
321+
# Discover libssh2
322+
find_package(LIBSSH2 QUIET)
323+
if(LIBSSH2_FOUND)
324+
# Assign test libraries (additional boost and libssh2 dependencies)
325+
set(CASS_TEST_LIBS ${Boost_LIBRARIES} ${LIBSSH2_LIBRARIES})
326+
if(UNIX)
327+
set(CASS_TEST_LIBS ${CASS_TEST_LIBS} pthread)
328+
endif()
329+
add_definitions(-DCASS_USE_LIBSSH2)
330+
else()
331+
message(STATUS "libssh2 is Unavailable: Building integration tests without libssh2 support")
332+
endif()
313333
endif()
314334
endif()
315335

@@ -400,8 +420,8 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
400420
string(REPLACE "/INCREMENTAL" "/INCREMENTAL:NO" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
401421

402422
# Create specific linker flags
423+
set(WINDOWS_LINKER_FLAGS "/INCREMENTAL:NO /LTCG /NODEFAULTLIB:LIBCMT.LIB /NODEFAULTLIB:LIBCMTD.LIB")
403424
if(CASS_USE_STATIC_LIBS)
404-
set(WINDOWS_LINKER_FLAGS "/INCREMENTAL:NO /LTCG /NODEFAULTLIB:LIBCMT.LIB /NODEFAULTLIB:LIBCMTD.LIB")
405425
set(PROJECT_CXX_LINKER_FLAGS "${WINDOWS_LINKER_FLAGS}")
406426
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${WINDOWS_LINKER_FLAGS}")
407427
endif()
@@ -631,10 +651,11 @@ set(INSTALL_DLL_EXE_DIR "bin")
631651
#-----------------------------
632652

633653
# Add the unit and integration tests to the build process
634-
if(CASS_BUILD_TESTS)
654+
if(CASS_BUILD_UNIT_TESTS)
635655
# Add the unit test project
636656
add_subdirectory(test/unit_tests)
637-
657+
endif()
658+
if(CASS_BUILD_INTEGRATION_TESTS)
638659
# Add CCM bridge as a dependency for integration tests
639660
add_subdirectory("${PROJECT_SOURCE_DIR}/test/ccm_bridge")
640661
set(CCM_BRIDGE_INCLUDES "${PROJECT_SOURCE_DIR}/test/ccm_bridge/src")

test/ccm_bridge/CMakeLists.txt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.6.4)
33
# Clear INCLUDE_DIRECTORIES to not include project-level includes
44
set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
55

6+
# Force OLD style of leaving VERSION variables untouched
67
if(POLICY CMP0048)
78
cmake_policy(SET CMP0048 OLD)
89
endif()
@@ -30,17 +31,19 @@ file(GLOB CCM_BRIDGE_INC_FILES ${PROJECT_SOURCE_DIR}/src/*.hpp)
3031
file(GLOB CCM_BRIDGE_SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
3132

3233
# Build up the include paths
33-
set(INTEGRATION_TESTS_INCLUDES ${PROJECT_SOURCE_DIR}/src
34-
${Boost_INCLUDE_DIRS}
35-
${LIBSSH2_INCLUDE_DIRS})
34+
set(INTEGRATION_TESTS_INCLUDES ${PROJECT_SOURCE_DIR}/src ${Boost_INCLUDE_DIRS})
35+
if(LIBSSH2_FOUND)
36+
set(INTEGRATION_TESTS_INCLUDES ${INTEGRATION_TESTS_INCLUDES} ${LIBSSH2_INCLUDE_DIRS})
37+
endif()
3638

3739
# Assign the include directories
3840
include_directories(${INTEGRATION_TESTS_INCLUDES})
3941

4042
# Build up the libraries paths
41-
set(INTEGRATION_TESTS_LIBS ${Boost_LIBRARIES}
42-
${LIBSSH2_LIBRARIES}
43-
${OPENSSL_LIBRARIES})
43+
set(INTEGRATION_TESTS_LIBS ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES})
44+
if(LIBSSH2_FOUND)
45+
set(INTEGRATION_TEST_LIBS ${INTEGRATION_TEST_LIBS} ${LIBSSH2_LIBRARIES})
46+
endif()
4447
if(ZLIB_FOUND)
4548
set(INTEGRATION_TESTS_LIBS ${INTEGRATION_TESTS_LIBS} ${ZLIB_LIBRARIES})
4649
endif()

0 commit comments

Comments
 (0)