Commit 8642e827c4d1ffdb37d27607f2544013d5630ccc
Committed by
Moritz Wirger
1 parent
a2898cce
Link static library for tests instead of building sources.
Showing
3 changed files
with
38 additions
and
42 deletions
CMakeLists.txt
| @@ -47,8 +47,8 @@ set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation director | @@ -47,8 +47,8 @@ set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation director | ||
| 47 | # target for uninstall | 47 | # target for uninstall |
| 48 | if(NOT TARGET uninstall) | 48 | if(NOT TARGET uninstall) |
| 49 | configure_file( | 49 | configure_file( |
| 50 | - "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" | ||
| 51 | - "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" | 50 | + "${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" |
| 51 | + "${PROJECT_BINARY_DIR}/cmake_uninstall.cmake" | ||
| 52 | IMMEDIATE @ONLY) | 52 | IMMEDIATE @ONLY) |
| 53 | 53 | ||
| 54 | add_custom_target(uninstall | 54 | add_custom_target(uninstall |
src/CMakeLists.txt
| 1 | -file(GLOB hueplusplus_HEADERS include/*.h include/*.hpp) | ||
| 2 | set(hueplusplus_SOURCES | 1 | set(hueplusplus_SOURCES |
| 3 | - ${CMAKE_CURRENT_SOURCE_DIR}/BaseHttpHandler.cpp | ||
| 4 | - ${CMAKE_CURRENT_SOURCE_DIR}/ExtendedColorHueStrategy.cpp | ||
| 5 | - ${CMAKE_CURRENT_SOURCE_DIR}/ExtendedColorTemperatureStrategy.cpp | ||
| 6 | - ${CMAKE_CURRENT_SOURCE_DIR}/Hue.cpp | ||
| 7 | - ${CMAKE_CURRENT_SOURCE_DIR}/HueCommandAPI.cpp | ||
| 8 | - ${CMAKE_CURRENT_SOURCE_DIR}/HueDeviceTypes.cpp | ||
| 9 | - ${CMAKE_CURRENT_SOURCE_DIR}/HueException.cpp | ||
| 10 | - ${CMAKE_CURRENT_SOURCE_DIR}/HueLight.cpp | ||
| 11 | - ${CMAKE_CURRENT_SOURCE_DIR}/SimpleBrightnessStrategy.cpp | ||
| 12 | - ${CMAKE_CURRENT_SOURCE_DIR}/SimpleColorHueStrategy.cpp | ||
| 13 | - ${CMAKE_CURRENT_SOURCE_DIR}/SimpleColorTemperatureStrategy.cpp | ||
| 14 | - ${CMAKE_CURRENT_SOURCE_DIR}/UPnP.cpp | ||
| 15 | - ${CMAKE_CURRENT_SOURCE_DIR}/Utils.cpp | 2 | + BaseHttpHandler.cpp |
| 3 | + ExtendedColorHueStrategy.cpp | ||
| 4 | + ExtendedColorTemperatureStrategy.cpp | ||
| 5 | + Hue.cpp | ||
| 6 | + HueCommandAPI.cpp | ||
| 7 | + HueDeviceTypes.cpp | ||
| 8 | + HueException.cpp | ||
| 9 | + HueLight.cpp | ||
| 10 | + SimpleBrightnessStrategy.cpp | ||
| 11 | + SimpleColorHueStrategy.cpp | ||
| 12 | + SimpleColorTemperatureStrategy.cpp | ||
| 13 | + UPnP.cpp | ||
| 14 | + Utils.cpp | ||
| 16 | ) | 15 | ) |
| 17 | 16 | ||
| 18 | # on windows we want to compile the WinHttpHandler | 17 | # on windows we want to compile the WinHttpHandler |
| 19 | if(WIN32) | 18 | if(WIN32) |
| 20 | set(hueplusplus_SOURCES | 19 | set(hueplusplus_SOURCES |
| 21 | ${hueplusplus_SOURCES} | 20 | ${hueplusplus_SOURCES} |
| 22 | - ${CMAKE_CURRENT_SOURCE_DIR}/WinHttpHandler.cpp PARENT_SCOPE | 21 | + WinHttpHandler.cpp |
| 23 | ) | 22 | ) |
| 24 | endif() | 23 | endif() |
| 25 | # whereas on linux we want the LinHttpHandler | 24 | # whereas on linux we want the LinHttpHandler |
| 26 | if(UNIX) | 25 | if(UNIX) |
| 27 | set(hueplusplus_SOURCES | 26 | set(hueplusplus_SOURCES |
| 28 | ${hueplusplus_SOURCES} | 27 | ${hueplusplus_SOURCES} |
| 29 | - ${CMAKE_CURRENT_SOURCE_DIR}/LinHttpHandler.cpp PARENT_SCOPE | 28 | + LinHttpHandler.cpp |
| 30 | ) | 29 | ) |
| 31 | endif() | 30 | endif() |
| 32 | if(ESP_PLATFORM) | 31 | if(ESP_PLATFORM) |
| 33 | set(hueplusplus_SOURCES | 32 | set(hueplusplus_SOURCES |
| 34 | ${hueplusplus_SOURCES} | 33 | ${hueplusplus_SOURCES} |
| 35 | - ${CMAKE_CURRENT_SOURCE_DIR}/LinHttpHandler.cpp PARENT_SCOPE | 34 | + LinHttpHandler.cpp |
| 36 | ) | 35 | ) |
| 37 | endif() | 36 | endif() |
| 38 | 37 | ||
| 39 | -# Propagate to parent scope for tests | ||
| 40 | -set(hueplusplus_SOURCES ${hueplusplus_SOURCES} PARENT_SCOPE) | ||
| 41 | - | ||
| 42 | # hueplusplus shared library | 38 | # hueplusplus shared library |
| 43 | add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES}) | 39 | add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES}) |
| 44 | target_compile_features(hueplusplusshared PUBLIC cxx_std_14) | 40 | target_compile_features(hueplusplusshared PUBLIC cxx_std_14) |
| @@ -50,12 +46,12 @@ add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES}) | @@ -50,12 +46,12 @@ add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES}) | ||
| 50 | target_compile_features(hueplusplusstatic PUBLIC cxx_std_14) | 46 | target_compile_features(hueplusplusstatic PUBLIC cxx_std_14) |
| 51 | install(TARGETS hueplusplusstatic DESTINATION lib) | 47 | install(TARGETS hueplusplusstatic DESTINATION lib) |
| 52 | target_include_directories(hueplusplusstatic PUBLIC $<BUILD_INTERFACE:${hueplusplus_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>) | 48 | target_include_directories(hueplusplusstatic PUBLIC $<BUILD_INTERFACE:${hueplusplus_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>) |
| 53 | -install(FILES ${hueplusplus_HEADERS} DESTINATION include/hueplusplus) | 49 | +#install(FILES ${hueplusplus_HEADERS} DESTINATION include/hueplusplus) |
| 54 | 50 | ||
| 55 | # Export the package for use from the build-tree | 51 | # Export the package for use from the build-tree |
| 56 | # (this registers the build-tree with a global CMake-registry) | 52 | # (this registers the build-tree with a global CMake-registry) |
| 57 | export(PACKAGE hueplusplus) | 53 | export(PACKAGE hueplusplus) |
| 58 | # Create the hueplusplus-config.cmake | 54 | # Create the hueplusplus-config.cmake |
| 59 | -configure_file ("${hueplusplus_SOURCE_DIR}/cmake/hueplusplus-config.cmake.in" "${hueplusplus_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hueplusplus-config.cmake" @ONLY) | 55 | +configure_file ("${PROJECT_SOURCE_DIR}/cmake/hueplusplus-config.cmake.in" "${hueplusplus_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hueplusplus-config.cmake" @ONLY) |
| 60 | # Install hueplusplus-config.cmake | 56 | # Install hueplusplus-config.cmake |
| 61 | -install(FILES "${hueplusplus_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hueplusplus-config.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) | 57 | +install(FILES "${PROJECT_BINARY}${CMAKE_FILES_DIRECTORY}/hueplusplus-config.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) |
test/CMakeLists.txt
| @@ -2,14 +2,14 @@ | @@ -2,14 +2,14 @@ | ||
| 2 | configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) | 2 | configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) |
| 3 | execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . | 3 | execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . |
| 4 | RESULT_VARIABLE result | 4 | RESULT_VARIABLE result |
| 5 | - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" | 5 | + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/test/googletest-download" |
| 6 | ) | 6 | ) |
| 7 | if(result) | 7 | if(result) |
| 8 | message(FATAL_ERROR "CMake step for googletest failed: ${result}") | 8 | message(FATAL_ERROR "CMake step for googletest failed: ${result}") |
| 9 | endif() | 9 | endif() |
| 10 | execute_process(COMMAND "${CMAKE_COMMAND}" --build . | 10 | execute_process(COMMAND "${CMAKE_COMMAND}" --build . |
| 11 | RESULT_VARIABLE result | 11 | RESULT_VARIABLE result |
| 12 | - WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" | 12 | + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/test/googletest-download" |
| 13 | ) | 13 | ) |
| 14 | if(result) | 14 | if(result) |
| 15 | message(FATAL_ERROR "Build step for googletest failed: ${result}") | 15 | message(FATAL_ERROR "Build step for googletest failed: ${result}") |
| @@ -27,32 +27,32 @@ add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src EXCLUDE_FROM_ALL | @@ -27,32 +27,32 @@ add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src EXCLUDE_FROM_ALL | ||
| 27 | 27 | ||
| 28 | # define all test sources | 28 | # define all test sources |
| 29 | set(TEST_SOURCES | 29 | set(TEST_SOURCES |
| 30 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_BaseHttpHandler.cpp | ||
| 31 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorHueStrategy.cpp | ||
| 32 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_ExtendedColorTemperatureStrategy.cpp | ||
| 33 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_Hue.cpp | ||
| 34 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_HueLight.cpp | ||
| 35 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_HueCommandAPI.cpp | ||
| 36 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_Main.cpp | ||
| 37 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleBrightnessStrategy.cpp | ||
| 38 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorHueStrategy.cpp | ||
| 39 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_SimpleColorTemperatureStrategy.cpp | ||
| 40 | - ${CMAKE_CURRENT_SOURCE_DIR}/test_UPnP.cpp | 30 | + test_BaseHttpHandler.cpp |
| 31 | + test_ExtendedColorHueStrategy.cpp | ||
| 32 | + test_ExtendedColorTemperatureStrategy.cpp | ||
| 33 | + test_Hue.cpp | ||
| 34 | + test_HueLight.cpp | ||
| 35 | + test_HueCommandAPI.cpp | ||
| 36 | + test_Main.cpp | ||
| 37 | + test_SimpleBrightnessStrategy.cpp | ||
| 38 | + test_SimpleColorHueStrategy.cpp | ||
| 39 | + test_SimpleColorTemperatureStrategy.cpp | ||
| 40 | + test_UPnP.cpp | ||
| 41 | ) | 41 | ) |
| 42 | 42 | ||
| 43 | -set(HuePlusPlus_INCLUDE_DIR "${hueplusplus_SOURCE_DIR}/include") | 43 | +set(HuePlusPlus_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/include") |
| 44 | 44 | ||
| 45 | # test executable | 45 | # test executable |
| 46 | -add_executable(test_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) | 46 | +add_executable(test_HuePlusPlus ${TEST_SOURCES}) |
| 47 | if(DO_CLANG_TIDY) | 47 | if(DO_CLANG_TIDY) |
| 48 | set_target_properties(test_HuePlusPlus PROPERTIES CXX_CLANG_TIDY ${DO_CLANG_TIDY}) | 48 | set_target_properties(test_HuePlusPlus PROPERTIES CXX_CLANG_TIDY ${DO_CLANG_TIDY}) |
| 49 | endif() | 49 | endif() |
| 50 | target_compile_features(test_HuePlusPlus PUBLIC cxx_std_14) | 50 | target_compile_features(test_HuePlusPlus PUBLIC cxx_std_14) |
| 51 | set_property(TARGET test_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) | 51 | set_property(TARGET test_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) |
| 52 | 52 | ||
| 53 | -target_link_libraries(test_HuePlusPlus gtest gmock) | 53 | +target_link_libraries(test_HuePlusPlus PUBLIC hueplusplusstatic) |
| 54 | +target_link_libraries(test_HuePlusPlus PUBLIC gtest gmock) | ||
| 54 | target_include_directories(test_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) | 55 | target_include_directories(test_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) |
| 55 | -target_include_directories(test_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) | ||
| 56 | # add custom target to make it simple to run the tests | 56 | # add custom target to make it simple to run the tests |
| 57 | add_custom_target("unittest" | 57 | add_custom_target("unittest" |
| 58 | # Run the executable | 58 | # Run the executable |