Commit fb6049b3e6b125672a3d2667132616904f28ef87
Committed by
Moritz Wirger
1 parent
175c4cde
Add CMakeLists for tests with google test (gtest)
Showing
2 changed files
with
56 additions
and
0 deletions
hueplusplus/test/CMakeLists.txt
0 → 100755
| 1 | +# Download and unpack googletest at configure time | |
| 2 | +configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) | |
| 3 | +execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . | |
| 4 | + RESULT_VARIABLE result | |
| 5 | +WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" ) | |
| 6 | +if(result) | |
| 7 | + message(FATAL_ERROR "CMake step for googletest failed: ${result}") | |
| 8 | +endif() | |
| 9 | +execute_process(COMMAND "${CMAKE_COMMAND}" --build . | |
| 10 | + RESULT_VARIABLE result | |
| 11 | +WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" ) | |
| 12 | +if(result) | |
| 13 | + message(FATAL_ERROR "Build step for googletest failed: ${result}") | |
| 14 | +endif() | |
| 15 | + | |
| 16 | +# Prevent overriding the parent project's compiler/linker | |
| 17 | +# settings on Windows | |
| 18 | +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | |
| 19 | + | |
| 20 | +# Add googletest directly to our build. This defines | |
| 21 | +# the gtest and gtest_main targets. | |
| 22 | +add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src | |
| 23 | + ${CMAKE_BINARY_DIR}/googletest-build) | |
| 24 | + | |
| 25 | +# The gtest/gtest_main targets carry header search path | |
| 26 | +# dependencies automatically when using CMake 2.8.11 or | |
| 27 | +# later. Otherwise we have to add them here ourselves. | |
| 28 | +if (CMAKE_VERSION VERSION_LESS 2.8.11) | |
| 29 | + include_directories("${gtest_SOURCE_DIR}/include") | |
| 30 | +endif() | |
| 31 | + | |
| 32 | +file(GLOB TEST_SOURCES test_*) | |
| 33 | + | |
| 34 | +add_executable(HuePlusPlus_Test ${TEST_SOURCES} ${hueplusplus_SOURCES}) | |
| 35 | +target_link_libraries(HuePlusPlus_Test gtest gmock) | |
| 36 | +# prevent Main.cpp from defining main() | |
| 37 | +target_compile_definitions(HuePlusPlus_Test PUBLIC MAIN_CPP_NO_MAIN_FUNCTION) | |
| 38 | +target_include_directories(HuePlusPlus_Test PUBLIC ${GTest_INCLUDE_DIRS}) | |
| 39 | +target_include_directories(HuePlusPlus_Test PUBLIC ${HuePlusPlus_INCLUDE_DIR}) | |
| 40 | +set_property(TARGET HuePlusPlus_Test PROPERTY CXX_STANDARD 14) | |
| 41 | +set_property(TARGET HuePlusPlus_Test PROPERTY CXX_EXTENSIONS OFF) | ... | ... |
hueplusplus/test/CMakeLists.txt.in
0 → 100755
| 1 | +cmake_minimum_required(VERSION 2.8.2) | |
| 2 | + | |
| 3 | +project(googletest-download NONE) | |
| 4 | + | |
| 5 | +include(ExternalProject) | |
| 6 | +ExternalProject_Add(googletest | |
| 7 | + GIT_REPOSITORY https://github.com/google/googletest.git | |
| 8 | + GIT_TAG master | |
| 9 | + SOURCE_DIR "${CMAKE_BINARY_DIR}/googletest-src" | |
| 10 | + BINARY_DIR "${CMAKE_BINARY_DIR}/googletest-build" | |
| 11 | + CONFIGURE_COMMAND "" | |
| 12 | + BUILD_COMMAND "" | |
| 13 | + INSTALL_COMMAND "" | |
| 14 | + TEST_COMMAND "" | |
| 15 | +) | ... | ... |