Commit 425f609fcc9c1f18618756e1cf3b29abc2c50860
Committed by
Moritz Wirger
1 parent
4f2efcab
add new functionality to CMakeLists
- cleanup and document CMakeLists - add hueplusplus-config.cmake to make it easier to use hueplusplus by simply calling find_package - remove GLOB in test/CMakeLists.txt and exchange with set
Showing
4 changed files
with
50 additions
and
11 deletions
CMakeLists.txt
| 1 | 1 | cmake_minimum_required(VERSION 2.8.3) |
| 2 | 2 | project(hueplusplus) |
| 3 | 3 | |
| 4 | -# uninstall target | |
| 4 | +# options to set | |
| 5 | +option(hueplusplus_TESTS "Build tests" OFF) | |
| 6 | + | |
| 7 | +# get the correct installation directory for add_library() to work | |
| 8 | +if(WIN32 AND NOT CYGWIN) | |
| 9 | + set(DEF_INSTALL_CMAKE_DIR cmake) | |
| 10 | +else() | |
| 11 | + set(DEF_INSTALL_CMAKE_DIR lib/cmake/hueplusplus) | |
| 12 | +endif() | |
| 13 | +set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") | |
| 14 | + | |
| 15 | + | |
| 16 | +# target for uninstall | |
| 5 | 17 | if(NOT TARGET uninstall) |
| 6 | 18 | configure_file( |
| 7 | 19 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" |
| ... | ... | @@ -12,8 +24,7 @@ if(NOT TARGET uninstall) |
| 12 | 24 | COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) |
| 13 | 25 | endif() |
| 14 | 26 | |
| 15 | -option(hueplusplus_TESTS "Build tests" OFF) | |
| 16 | - | |
| 27 | +# if we are on a apple machine this is needed | |
| 17 | 28 | if (1 AND APPLE) |
| 18 | 29 | set(CMAKE_MACOSX_RPATH 1) |
| 19 | 30 | endif() | ... | ... |
hueplusplus/CMakeLists.txt
| ... | ... | @@ -11,12 +11,14 @@ set(hueplusplus_SOURCES |
| 11 | 11 | ${CMAKE_CURRENT_SOURCE_DIR}/UPnP.cpp |
| 12 | 12 | ) |
| 13 | 13 | |
| 14 | +# on windows we want to compile the winHttpHandler | |
| 14 | 15 | if(WIN32) |
| 15 | 16 | set(hueplusplus_SOURCES |
| 16 | 17 | ${hueplusplus_SOURCES} |
| 17 | 18 | ${CMAKE_CURRENT_SOURCE_DIR}/winHttpHandler.cpp |
| 18 | 19 | ) |
| 19 | 20 | endif() |
| 21 | +# whereas on linux we want the linHttpHandler | |
| 20 | 22 | if(UNIX) |
| 21 | 23 | set(hueplusplus_SOURCES |
| 22 | 24 | ${hueplusplus_SOURCES} |
| ... | ... | @@ -24,16 +26,27 @@ if(UNIX) |
| 24 | 26 | ) |
| 25 | 27 | endif() |
| 26 | 28 | |
| 29 | +# hueplusplus shared library | |
| 27 | 30 | add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES}) |
| 28 | 31 | set_property(TARGET hueplusplusshared PROPERTY CXX_STANDARD 14) |
| 29 | 32 | set_property(TARGET hueplusplusshared PROPERTY CXX_EXTENSIONS OFF) |
| 30 | 33 | |
| 34 | +# hueplusplus static library | |
| 31 | 35 | add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES}) |
| 32 | 36 | set_property(TARGET hueplusplusstatic PROPERTY CXX_STANDARD 14) |
| 33 | 37 | set_property(TARGET hueplusplusstatic PROPERTY CXX_EXTENSIONS OFF) |
| 34 | 38 | install(TARGETS hueplusplusstatic DESTINATION lib) |
| 35 | 39 | install(FILES ${hueplusplus_HEADERS} DESTINATION include) |
| 36 | 40 | |
| 41 | +# Export the package for use from the build-tree | |
| 42 | +# (this registers the build-tree with a global CMake-registry) | |
| 43 | +export(PACKAGE hueplusplus) | |
| 44 | +# Create the hueplusplus-config.cmake | |
| 45 | +configure_file (hueplusplus-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hueplusplus-config.cmake" @ONLY) | |
| 46 | +# Install hueplusplus-config.cmake | |
| 47 | +install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hueplusplus-config.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) | |
| 48 | + | |
| 49 | +# if the user decided to use tests add the subdirectory | |
| 37 | 50 | if(hueplusplus_TESTS) |
| 38 | 51 | set(HuePlusPlus_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 39 | 52 | add_subdirectory("test") | ... | ... |
hueplusplus/hueplusplus-config.cmake.in
0 → 100644
hueplusplus/test/CMakeLists.txt
| ... | ... | @@ -2,13 +2,15 @@ |
| 2 | 2 | configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) |
| 3 | 3 | execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . |
| 4 | 4 | RESULT_VARIABLE result |
| 5 | -WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" ) | |
| 5 | + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" | |
| 6 | +) | |
| 6 | 7 | if(result) |
| 7 | 8 | message(FATAL_ERROR "CMake step for googletest failed: ${result}") |
| 8 | 9 | endif() |
| 9 | 10 | execute_process(COMMAND "${CMAKE_COMMAND}" --build . |
| 10 | 11 | RESULT_VARIABLE result |
| 11 | -WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" ) | |
| 12 | + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" | |
| 13 | +) | |
| 12 | 14 | if(result) |
| 13 | 15 | message(FATAL_ERROR "Build step for googletest failed: ${result}") |
| 14 | 16 | endif() |
| ... | ... | @@ -20,7 +22,8 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) |
| 20 | 22 | # Add googletest directly to our build. This defines |
| 21 | 23 | # the gtest and gtest_main targets. |
| 22 | 24 | add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src EXCLUDE_FROM_ALL |
| 23 | - ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) | |
| 25 | + ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL | |
| 26 | +) | |
| 24 | 27 | |
| 25 | 28 | # The gtest/gtest_main targets carry header search path |
| 26 | 29 | # dependencies automatically when using CMake 2.8.11 or |
| ... | ... | @@ -29,9 +32,14 @@ if (CMAKE_VERSION VERSION_LESS 2.8.11) |
| 29 | 32 | include_directories("${gtest_SOURCE_DIR}/include" EXCLUDE_FROM_ALL) |
| 30 | 33 | endif() |
| 31 | 34 | |
| 32 | -# get all test sources. Maybe use something else than GLOB | |
| 33 | -file(GLOB TEST_SOURCES test_*) | |
| 35 | +# define all test sources | |
| 36 | +set(TEST_SOURCES | |
| 37 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_Main.cpp | |
| 38 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_Hue.cpp | |
| 39 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_UPnP.cpp | |
| 40 | +) | |
| 34 | 41 | |
| 42 | +# test executable | |
| 35 | 43 | add_executable(test_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) |
| 36 | 44 | target_link_libraries(test_HuePlusPlus gtest gmock) |
| 37 | 45 | # prevent Main.cpp from defining main() |
| ... | ... | @@ -40,16 +48,15 @@ target_include_directories(test_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) |
| 40 | 48 | target_include_directories(test_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) |
| 41 | 49 | set_property(TARGET test_HuePlusPlus PROPERTY CXX_STANDARD 14) |
| 42 | 50 | set_property(TARGET test_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) |
| 51 | +# add custom target to make it simple to run the tests | |
| 43 | 52 | add_custom_target("unittest" |
| 44 | - | |
| 45 | 53 | # make test_HuePlusPlus executable |
| 46 | 54 | COMMAND "make" test_HuePlusPlus |
| 47 | - | |
| 48 | 55 | # Run the executable |
| 49 | 56 | COMMAND "${CMAKE_BINARY_DIR}/hueplusplus/test/test_HuePlusPlus" |
| 50 | 57 | ) |
| 51 | 58 | |
| 52 | -# Check for prerequisites | |
| 59 | +# Check for coverage test prerequisites | |
| 53 | 60 | find_program( GCOV_PATH gcov ) |
| 54 | 61 | find_program( LCOV_PATH lcov ) |
| 55 | 62 | |
| ... | ... | @@ -74,6 +81,7 @@ if(LCOV_PATH AND GCOV_PATH) |
| 74 | 81 | # testcov_HuePlusPlus PROPERTIES |
| 75 | 82 | # LINK_FLAGS "-O0 -g -Lgcov -fprofile-arcs -ftest-coverage" |
| 76 | 83 | #) |
| 84 | + # exclude some special files we do not want to profile | |
| 77 | 85 | set(COVERAGE_EXCLUDES |
| 78 | 86 | '/usr/*' # unix |
| 79 | 87 | '*/build/*' | ... | ... |