diff --git a/CMakeLists.txt b/CMakeLists.txt index 7260c41..9755d99 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,19 @@ cmake_minimum_required(VERSION 2.8.3) project(hueplusplus) -# uninstall target +# options to set +option(hueplusplus_TESTS "Build tests" OFF) + +# get the correct installation directory for add_library() to work +if(WIN32 AND NOT CYGWIN) + set(DEF_INSTALL_CMAKE_DIR cmake) +else() + set(DEF_INSTALL_CMAKE_DIR lib/cmake/hueplusplus) +endif() +set(INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") + + +# target for uninstall if(NOT TARGET uninstall) configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" @@ -12,8 +24,7 @@ if(NOT TARGET uninstall) COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) endif() -option(hueplusplus_TESTS "Build tests" OFF) - +# if we are on a apple machine this is needed if (1 AND APPLE) set(CMAKE_MACOSX_RPATH 1) endif() diff --git a/hueplusplus/CMakeLists.txt b/hueplusplus/CMakeLists.txt index 051cded..dbe8212 100755 --- a/hueplusplus/CMakeLists.txt +++ b/hueplusplus/CMakeLists.txt @@ -11,12 +11,14 @@ set(hueplusplus_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/UPnP.cpp ) +# on windows we want to compile the winHttpHandler if(WIN32) set(hueplusplus_SOURCES ${hueplusplus_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/winHttpHandler.cpp ) endif() +# whereas on linux we want the linHttpHandler if(UNIX) set(hueplusplus_SOURCES ${hueplusplus_SOURCES} @@ -24,16 +26,27 @@ if(UNIX) ) endif() +# hueplusplus shared library add_library(hueplusplusshared SHARED ${hueplusplus_SOURCES}) set_property(TARGET hueplusplusshared PROPERTY CXX_STANDARD 14) set_property(TARGET hueplusplusshared PROPERTY CXX_EXTENSIONS OFF) +# hueplusplus static library add_library(hueplusplusstatic STATIC ${hueplusplus_SOURCES}) set_property(TARGET hueplusplusstatic PROPERTY CXX_STANDARD 14) set_property(TARGET hueplusplusstatic PROPERTY CXX_EXTENSIONS OFF) install(TARGETS hueplusplusstatic DESTINATION lib) install(FILES ${hueplusplus_HEADERS} DESTINATION include) +# Export the package for use from the build-tree +# (this registers the build-tree with a global CMake-registry) +export(PACKAGE hueplusplus) +# Create the hueplusplus-config.cmake +configure_file (hueplusplus-config.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hueplusplus-config.cmake" @ONLY) +# Install hueplusplus-config.cmake +install(FILES "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/hueplusplus-config.cmake" DESTINATION "${INSTALL_CMAKE_DIR}" COMPONENT dev) + +# if the user decided to use tests add the subdirectory if(hueplusplus_TESTS) set(HuePlusPlus_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) add_subdirectory("test") diff --git a/hueplusplus/hueplusplus-config.cmake.in b/hueplusplus/hueplusplus-config.cmake.in new file mode 100644 index 0000000..dc1490f --- /dev/null +++ b/hueplusplus/hueplusplus-config.cmake.in @@ -0,0 +1,7 @@ +# -config file of the hueplusplus package +# It defines the following +# hueplusplus_FOUND - which indicates that the module was found +# hueplusplus_INCLUDE_DIR + +set(hueplusplus_FOUND TRUE) +set(hueplusplus_INCLUDE_DIR "@INSTALL_INCLUDE_DIR@") diff --git a/hueplusplus/test/CMakeLists.txt b/hueplusplus/test/CMakeLists.txt index 2df4ba7..6938fac 100755 --- a/hueplusplus/test/CMakeLists.txt +++ b/hueplusplus/test/CMakeLists.txt @@ -2,13 +2,15 @@ configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt) execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} . RESULT_VARIABLE result -WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" ) + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" +) if(result) message(FATAL_ERROR "CMake step for googletest failed: ${result}") endif() execute_process(COMMAND "${CMAKE_COMMAND}" --build . RESULT_VARIABLE result -WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" ) + WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/hueplusplus/test/googletest-download" +) if(result) message(FATAL_ERROR "Build step for googletest failed: ${result}") endif() @@ -20,7 +22,8 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) # Add googletest directly to our build. This defines # the gtest and gtest_main targets. add_subdirectory(${CMAKE_BINARY_DIR}/googletest-src EXCLUDE_FROM_ALL - ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL) + ${CMAKE_BINARY_DIR}/googletest-build EXCLUDE_FROM_ALL +) # The gtest/gtest_main targets carry header search path # dependencies automatically when using CMake 2.8.11 or @@ -29,9 +32,14 @@ if (CMAKE_VERSION VERSION_LESS 2.8.11) include_directories("${gtest_SOURCE_DIR}/include" EXCLUDE_FROM_ALL) endif() -# get all test sources. Maybe use something else than GLOB -file(GLOB TEST_SOURCES test_*) +# define all test sources +set(TEST_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/test_Main.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_Hue.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test_UPnP.cpp +) +# test executable add_executable(test_HuePlusPlus ${TEST_SOURCES} ${hueplusplus_SOURCES}) target_link_libraries(test_HuePlusPlus gtest gmock) # prevent Main.cpp from defining main() @@ -40,16 +48,15 @@ target_include_directories(test_HuePlusPlus PUBLIC ${GTest_INCLUDE_DIRS}) target_include_directories(test_HuePlusPlus PUBLIC ${HuePlusPlus_INCLUDE_DIR}) set_property(TARGET test_HuePlusPlus PROPERTY CXX_STANDARD 14) set_property(TARGET test_HuePlusPlus PROPERTY CXX_EXTENSIONS OFF) +# add custom target to make it simple to run the tests add_custom_target("unittest" - # make test_HuePlusPlus executable COMMAND "make" test_HuePlusPlus - # Run the executable COMMAND "${CMAKE_BINARY_DIR}/hueplusplus/test/test_HuePlusPlus" ) -# Check for prerequisites +# Check for coverage test prerequisites find_program( GCOV_PATH gcov ) find_program( LCOV_PATH lcov ) @@ -74,6 +81,7 @@ if(LCOV_PATH AND GCOV_PATH) # testcov_HuePlusPlus PROPERTIES # LINK_FLAGS "-O0 -g -Lgcov -fprofile-arcs -ftest-coverage" #) + # exclude some special files we do not want to profile set(COVERAGE_EXCLUDES '/usr/*' # unix '*/build/*'