diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f75a604f9925d08f8121977abb28e2ecc112b136..0aabb6a729351c494488494dbfb8d40687eddabf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -8,6 +8,7 @@ stages: ############ YAML ANCHORS ############ .print_variables_template: &print_variables_definition # Print variables + - echo $WOLF_CORE_BRANCH - echo $CI_COMMIT_BRANCH - echo $WOLF_LASER_BRANCH - echo $LASERSCANUTILS_BRANCH @@ -95,9 +96,12 @@ stages: - if [ -d laser_scan_utils ]; then - echo "directory laser_scan_utils exists" - cd laser_scan_utils + - git checkout main + - git pull + - git checkout $LASERSCANUTILS_BRANCH - git pull - else - - git clone https://gitlab.iri.upc.edu/labrobotica/algorithms/laser_scan_utils.git + - git clone -b $LASERSCANUTILS_BRANCH https://gitlab.iri.upc.edu/labrobotica/algorithms/laser_scan_utils.git - cd laser_scan_utils - fi - mkdir -pv build diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a8ad1eab8d460fd4c256b2f48b0bed9106b361e..8687647283fcf148c50d38ba5de14afa9e3efb8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,6 @@ # Pre-requisites about cmake itself -CMAKE_MINIMUM_REQUIRED(VERSION 2.8) +CMAKE_MINIMUM_REQUIRED(VERSION 3.10) -if(COMMAND cmake_policy) - cmake_policy(SET CMP0005 NEW) - cmake_policy(SET CMP0003 NEW) -endif(COMMAND cmake_policy) # MAC OSX RPATH SET(CMAKE_MACOSX_RPATH 1) @@ -14,9 +10,11 @@ set(PLUGIN_NAME wolf${PROJECT_NAME}) MESSAGE("Starting ${PROJECT_NAME} CMakeLists ...") +# Paths SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin) SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib) -SET(CMAKE_INSTALL_PREFIX /usr/local) +set(INCLUDE_INSTALL_DIR include/iri-algorithms/wolf) +set(LIB_INSTALL_DIR lib/) IF (NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "DEBUG") @@ -69,10 +67,6 @@ if(BUILD_TESTS) enable_testing() endif() -#CMAKE modules -SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules") -MESSAGE(STATUS ${CMAKE_MODULE_PATH}) - # Some wolf compilation options IF((CMAKE_BUILD_TYPE MATCHES DEBUG) OR (CMAKE_BUILD_TYPE MATCHES debug) OR (CMAKE_BUILD_TYPE MATCHES Debug)) set(_WOLF_DEBUG true) @@ -81,14 +75,19 @@ ENDIF() option(_WOLF_TRACE "Enable wolf tracing macro" ON) # ============ DEPENDENCIES ============ -FIND_PACKAGE(wolfcore REQUIRED) -FIND_PACKAGE(laser_scan_utils REQUIRED) -FIND_PACKAGE(csm QUIET) +FIND_PACKAGE(wolfcore REQUIRED CONFIG) +FIND_PACKAGE(laser_scan_utils REQUIRED CONFIG) +# found only to set the XXX_FOUND variables +# -> It would be better to look for them in the the laser_scan_utils target FIND_PACKAGE(falkolib QUIET) +find_package(PkgConfig) +pkg_check_modules(csm QUIET csm) +# link_directories(${csm_LIBRARY_DIRS}) # ============ CONFIG.H ============ -string(TOUPPER ${PROJECT_NAME} UPPER_NAME) set(_WOLF_ROOT_DIR ${CMAKE_SOURCE_DIR}) +# variable used to compile the config.h.in file +string(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UPPER) # Define the directory where will be the configured config.h SET(WOLF_CONFIG_DIR ${PROJECT_BINARY_DIR}/conf/${PROJECT_NAME}/internal) @@ -108,8 +107,6 @@ message("CONFIG DIRECTORY ${PROJECT_BINARY_DIR}") include_directories("${PROJECT_BINARY_DIR}/conf") # ============ INCLUDES ============ -INCLUDE_DIRECTORIES(${wolfcore_INCLUDE_DIRS}) -INCLUDE_DIRECTORIES(${laser_scan_utils_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(BEFORE "include") # ============ HEADERS ============ @@ -244,10 +241,10 @@ ENDIF() #Link the created libraries #===============EXAMPLE========================= -TARGET_LINK_LIBRARIES(${PLUGIN_NAME} ${wolfcore_LIBRARIES}) -TARGET_LINK_LIBRARIES(${PLUGIN_NAME} ${laser_scan_utils_LIBRARY}) +TARGET_LINK_LIBRARIES(${PLUGIN_NAME} wolfcore) +TARGET_LINK_LIBRARIES(${PLUGIN_NAME} laser_scan_utils) IF (falkolib_FOUND) - TARGET_LINK_LIBRARIES(${PLUGIN_NAME} ${wolfcore_LIBRARIES} ${laser_scan_utils_LIBRARY} ${falkolib_LIBRARY}) + TARGET_LINK_LIBRARIES(${PLUGIN_NAME} ${falkolib_LIBRARY}) ENDIF(falkolib_FOUND) #Build tests @@ -257,45 +254,67 @@ IF(BUILD_TESTS) add_subdirectory(test) ENDIF(BUILD_TESTS) + #install library #============================================================= INSTALL(TARGETS ${PLUGIN_NAME} EXPORT ${PLUGIN_NAME}Targets - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) + RUNTIME DESTINATION bin + LIBRARY DESTINATION ${LIB_INSTALL_DIR} + ARCHIVE DESTINATION ${LIB_INSTALL_DIR} +) +install(EXPORT ${PLUGIN_NAME}Targets DESTINATION lib/${PLUGIN_NAME}/cmake) + +#Â Configure the package installation +include(CMakePackageConfigHelpers) +configure_package_config_file( + ${CMAKE_SOURCE_DIR}/cmake_modules/${PLUGIN_NAME}Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_NAME}Config.cmake + INSTALL_DESTINATION ${LIB_INSTALL_DIR}/${PLUGIN_NAME}/cmake + PATH_VARS INCLUDE_INSTALL_DIR LIB_INSTALL_DIR +) + +install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${PLUGIN_NAME}Config.cmake + DESTINATION + ${LIB_INSTALL_DIR}/${PLUGIN_NAME}/cmake +) + +# Specifies include directories to use when compiling the plugin target +# This way, include_directories does not need to be called in plugins depending on this one +target_include_directories(${PLUGIN_NAME} INTERFACE + $<INSTALL_INTERFACE:${INCLUDE_INSTALL_DIR}> +) -install(EXPORT ${PLUGIN_NAME}Targets DESTINATION lib/cmake/${PLUGIN_NAME}) #install headers INSTALL(FILES ${HDRS_CAPTURE} - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/capture) + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/capture) INSTALL(FILES ${HDRS_FACTOR} - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/factor) + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/factor) INSTALL(FILES ${HDRS_FEATURE} - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/feature) + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/feature) INSTALL(FILES ${HDRS_LANDMARK} - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/landmark) + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/landmark) INSTALL(FILES ${HDRS_MATH} - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/math) + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/math) INSTALL(FILES ${HDRS_PROCESSOR} - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/processor) + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/processor) INSTALL(FILES ${HDRS_SENSOR} - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/sensor) + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/sensor) INSTALL(FILES ${HDRS_STATE_BLOCK} - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/state_block) + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/state_block) FILE(WRITE laser.found "") INSTALL(FILES laser.found - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}) + DESTINATION ${INCLUDE_INSTALL_DIR}) INSTALL(FILES "${WOLF_CONFIG_DIR}/config.h" - DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/internal) - -INSTALL(FILES "${CMAKE_SOURCE_DIR}/cmake_modules/${PLUGIN_NAME}Config.cmake" DESTINATION "lib/cmake/${PLUGIN_NAME}") + DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/internal) INSTALL(DIRECTORY ${SPDLOG_INCLUDE_DIRS} DESTINATION "include/iri-algorithms/") export(PACKAGE ${PLUGIN_NAME}) -FIND_PACKAGE(Doxygen) +FIND_PACKAGE(Doxygen MODULE) FIND_PATH(IRI_DOC_DIR doxygen.conf ${CMAKE_SOURCE_DIR}/doc/iri_doc/) IF (IRI_DOC_DIR) diff --git a/cmake_modules/Findcsm.cmake b/cmake_modules/Findcsm.cmake deleted file mode 100755 index 6dafd97ded05ef9df2b4b19b318639855fa48af5..0000000000000000000000000000000000000000 --- a/cmake_modules/Findcsm.cmake +++ /dev/null @@ -1,64 +0,0 @@ -FIND_PATH( - csm_INCLUDE_DIR - NAMES algos.h - PATHS /usr/local/include/csm) -IF(csm_INCLUDE_DIR) - MESSAGE("Found csm include dirs: ${csm_INCLUDE_DIR}") -ELSE(csm_INCLUDE_DIR) - MESSAGE("Couldn't find csm include dirs") -ENDIF(csm_INCLUDE_DIR) - -FIND_LIBRARY( - csm_LIBRARY - NAMES libcsm.so libcsm.dylib - PATHS /usr/local/lib) -IF(csm_LIBRARY) - MESSAGE("Found csm lib: ${csm_LIBRARY}") -ELSE(csm_LIBRARY) - MESSAGE("Couldn't find csm lib") -ENDIF(csm_LIBRARY) - -IF (csm_INCLUDE_DIR AND csm_LIBRARY) - SET(csm_FOUND TRUE) - ELSE(csm_INCLUDE_DIR AND csm_LIBRARY) - set(csm_FOUND FALSE) -ENDIF (csm_INCLUDE_DIR AND csm_LIBRARY) - -IF (csm_FOUND) - IF (NOT csm_FIND_QUIETLY) - MESSAGE(STATUS "Found csm: ${csm_LIBRARY}") - ENDIF (NOT csm_FIND_QUIETLY) -ELSE (csm_FOUND) - IF (csm_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find csm") - ENDIF (csm_FIND_REQUIRED) -ENDIF (csm_FOUND) - - -macro(csm_report_not_found REASON_MSG) - set(csm_FOUND FALSE) - unset(csm_INCLUDE_DIR) - unset(csm_LIBRARIES) - - # Reset the CMake module path to its state when this script was called. - set(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH}) - - # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by - # FindPackage() use the camelcase library name, not uppercase. - if (csm_FIND_QUIETLY) - message(STATUS "Failed to find csm- " ${REASON_MSG} ${ARGN}) - elseif (csm_FIND_REQUIRED) - message(FATAL_ERROR "Failed to find csm - " ${REASON_MSG} ${ARGN}) - else() - # Neither QUIETLY nor REQUIRED, use SEND_ERROR which emits an error - # that prevents generation, but continues configuration. - message(SEND_ERROR "Failed to find csm - " ${REASON_MSG} ${ARGN}) - endif () - return() -endmacro(csm_report_not_found) - -if(NOT csm_FOUND) - csm_report_not_found("Something went wrong while setting up csm.") -endif(NOT csm_FOUND) -# Set the include directories for csm (itself). -set(csm_FOUND TRUE) \ No newline at end of file diff --git a/cmake_modules/wolflaserConfig.cmake b/cmake_modules/wolflaserConfig.cmake deleted file mode 100644 index 3344e8e033dcd453defca02e0c177f3bc9cce28c..0000000000000000000000000000000000000000 --- a/cmake_modules/wolflaserConfig.cmake +++ /dev/null @@ -1,91 +0,0 @@ -#edit the following line to add the librarie's header files -FIND_PATH( - wolflaser_INCLUDE_DIRS - NAMES laser.found - PATHS /usr/local/include/iri-algorithms/wolf/plugin_laser) -IF(wolflaser_INCLUDE_DIRS) - MESSAGE("Found laser include dirs: ${wolflaser_INCLUDE_DIRS}") -ELSE(wolflaser_INCLUDE_DIRS) - MESSAGE("Couldn't find laser include dirs") -ENDIF(wolflaser_INCLUDE_DIRS) - -FIND_LIBRARY( - wolflaser_LIBRARIES - NAMES libwolflaser.so - PATHS /usr/local/lib) -IF(wolflaser_LIBRARIES) - MESSAGE("Found laser lib: ${wolflaser_LIBRARIES}") -ELSE(wolflaser_LIBRARIES) - MESSAGE("Couldn't find wolf laser lib") -ENDIF(wolflaser_LIBRARIES) - -IF (wolflaser_INCLUDE_DIRS AND wolflaser_LIBRARIES) - SET(wolflaser_FOUND TRUE) - ELSE(wolflaser_INCLUDE_DIRS AND wolflaser_LIBRARIES) - set(wolflaser_FOUND FALSE) -ENDIF (wolflaser_INCLUDE_DIRS AND wolflaser_LIBRARIES) - -IF (wolflaser_FOUND) - IF (NOT wolflaser_FIND_QUIETLY) - MESSAGE(STATUS "Found laser: ${wolflaser_LIBRARIES}") - ENDIF (NOT wolflaser_FIND_QUIETLY) -ELSE (wolflaser_FOUND) - IF (wolflaser_FIND_REQUIRED) - MESSAGE(FATAL_ERROR "Could not find wolf laser") - ENDIF (wolflaser_FIND_REQUIRED) -ENDIF (wolflaser_FOUND) - - -macro(wolf_report_not_found REASON_MSG) - set(wolflaser_FOUND FALSE) - unset(wolflaser_INCLUDE_DIRS) - unset(wolflaser_LIBRARIES) - - # Reset the CMake module path to its state when this script was called. - set(CMAKE_MODULE_PATH ${CALLERS_CMAKE_MODULE_PATH}) - - # Note <package>_FIND_[REQUIRED/QUIETLY] variables defined by - # FindPackage() use the camelcase library name, not uppercase. - if (wolflaser_FIND_QUIETLY) - message(STATUS "Failed to find wolf laser- " ${REASON_MSG} ${ARGN}) - elseif(wolflaser_FIND_REQUIRED) - message(FATAL_ERROR "Failed to find wolf laser - " ${REASON_MSG} ${ARGN}) - else() - # Neither QUIETLY nor REQUIRED, use SEND_ERROR which emits an error - # that prevents generation, but continues configuration. - message(SEND_ERROR "Failed to find wolf laser - " ${REASON_MSG} ${ARGN}) - endif () - return() -endmacro(wolf_report_not_found) - -if(NOT wolflaser_FOUND) - wolf_report_not_found("Something went wrong while setting up wolf vision.") -endif(NOT wolflaser_FOUND) -# Set the include directories for wolf (itself). -set(wolflaser_FOUND TRUE) - -# Now we gather all the required dependencies for Wolf Laser - -FIND_PACKAGE(laser_scan_utils REQUIRED) -list(APPEND wolflaser_INCLUDE_DIRS ${laser_scan_utils_INCLUDE_DIRS}) -list(APPEND wolflaser_LIBRARIES ${laser_scan_utils_LIBRARY}) - -#Making sure Wolf is looked for -if(NOT wolf_FOUND) - FIND_PACKAGE(wolfcore REQUIRED) - - #We reverse in order to insert at the start - list(REVERSE wolflaser_INCLUDE_DIRS) - list(APPEND wolflaser_INCLUDE_DIRS ${wolfcore_INCLUDE_DIRS}) - list(REVERSE wolflaser_INCLUDE_DIRS) - - list(REVERSE wolflaser_LIBRARIES) - list(APPEND wolflaser_LIBRARIES ${wolfcore_LIBRARIES}) - list(REVERSE wolflaser_LIBRARIES) - -endif() - -# provide both INCLUDE_DIR and INCLUDE_DIRS -SET(wolflaser_INCLUDE_DIR ${wolflaser_INCLUDE_DIRS}) -# provide both LIBRARY and LIBRARIES -SET(wolflaser_LIBRARY ${wolflaser_LIBRARIES}) \ No newline at end of file diff --git a/cmake_modules/wolflaserConfig.cmake.in b/cmake_modules/wolflaserConfig.cmake.in new file mode 100644 index 0000000000000000000000000000000000000000..b079ac9ac39e5aa16a16f30982abb9c13047e3c0 --- /dev/null +++ b/cmake_modules/wolflaserConfig.cmake.in @@ -0,0 +1,13 @@ +set(@PLUGIN_NAME@_VERSION 0.0.1) + + +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +FIND_DEPENDENCY(wolfcore REQUIRED) +FIND_DEPENDENCY(laser_scan_utils REQUIRED) +FIND_DEPENDENCY(Eigen3 3.3 REQUIRED) + +include("${CMAKE_CURRENT_LIST_DIR}/@PLUGIN_NAME@Targets.cmake") + +check_required_components(@PLUGIN_NAME@) \ No newline at end of file diff --git a/internal/config.h.in b/internal/config.h.in index 7014ca320e5c5fea1f59a6fe5d9d1ea0987bf95e..35f3468331656ba09a63ad7f26e5c0fb78c8d5bc 100644 --- a/internal/config.h.in +++ b/internal/config.h.in @@ -24,13 +24,13 @@ // which will be added to the include path for compilation, // and installed with the public wolf headers. -#ifndef WOLF_INTERNAL_${UPPER_NAME}_CONFIG_H_ -#define WOLF_INTERNAL_${UPPER_NAME}_CONFIG_H_ +#ifndef WOLF_INTERNAL_${PROJECT_NAME_UPPER}_CONFIG_H_ +#define WOLF_INTERNAL_${PROJECT_NAME_UPPER}_CONFIG_H_ #cmakedefine _WOLF_DEBUG #cmakedefine _WOLF_TRACE -#define _WOLF_${UPPER_NAME}_ROOT_DIR "${_WOLF_ROOT_DIR}" +#define _WOLF_${PROJECT_NAME_UPPER}_ROOT_DIR "${_WOLF_ROOT_DIR}" #endif /* WOLF_INTERNAL_CONFIG_H_ */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c75a1957be69ff023966f3c9d0c59dd1fd7eb0f6..1d3f41289deb112f091202b31669f289598b7832 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,37 +1,26 @@ # Retrieve googletest from github & compile add_subdirectory(gtest) -# Include gtest directory. -include_directories(${GTEST_INCLUDE_DIRS}) - ############# USE THIS TEST AS AN EXAMPLE ################# # # # Create a specific test executable for gtest_example # -wolf_add_gtest(gtest_example gtest_example.cpp) # -target_link_libraries(gtest_example ${PLUGIN_NAME}) # +# wolf_add_gtest(gtest_example gtest_example.cpp) # # # ########################################################### wolf_add_gtest(gtest_landmark_polyline gtest_landmark_polyline.cpp) -target_link_libraries(gtest_landmark_polyline ${PLUGIN_NAME}) if(csm_FOUND) wolf_add_gtest(gtest_processor_odom_icp gtest_processor_odom_icp.cpp) - target_link_libraries(gtest_processor_odom_icp ${PLUGIN_NAME} ${wolf_LIBRARY}) - wolf_add_gtest(gtest_processor_loop_closure_icp gtest_processor_loop_closure_icp.cpp) - target_link_libraries(gtest_processor_loop_closure_icp ${PLUGIN_NAME} ${wolf_LIBRARY}) endif(csm_FOUND) wolf_add_gtest(gtest_polyline_2d gtest_polyline_2d.cpp) -target_link_libraries(gtest_polyline_2d ${PLUGIN_NAME}) if(falkolib_FOUND) wolf_add_gtest(gtest_processor_loop_closure_falko gtest_processor_loop_closure_falko.cpp) - target_link_libraries(gtest_processor_loop_closure_falko ${PLUGIN_NAME} ${wolf_LIBRARY}) if(csm_FOUND) wolf_add_gtest(gtest_processor_loop_closure_falko_icp gtest_processor_loop_closure_falko_icp.cpp) - target_link_libraries(gtest_processor_loop_closure_falko_icp ${PLUGIN_NAME} ${wolf_LIBRARY}) endif(csm_FOUND) endif(falkolib_FOUND) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 559756b02472653c655c44152c452ba8767ef6f2..6209d341bcd32308bd522ab1990eb0cc82692012 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -1,65 +1,73 @@ -cmake_minimum_required(VERSION 2.8.8) -project(gtest_builder C CXX) +if(${CMAKE_VERSION} VERSION_LESS "3.11.0") + message("CMake version less than 3.11.0") -# We need thread support -#find_package(Threads REQUIRED) + # Enable ExternalProject CMake module + include(ExternalProject) -# Enable ExternalProject CMake module -include(ExternalProject) + set(GTEST_FORCE_SHARED_CRT ON) + set(GTEST_DISABLE_PTHREADS ON) # without this in ubuntu 18.04 we get linking errors -set(GTEST_FORCE_SHARED_CRT ON) -set(GTEST_DISABLE_PTHREADS OFF) + # Download GoogleTest + ExternalProject_Add(googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG v1.8.x + # TIMEOUT 1 # We'll try this + CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs + -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs + -DCMAKE_CXX_FLAGS=${MSVC_COMPILER_DEFS} + -Dgtest_force_shared_crt=${GTEST_FORCE_SHARED_CRT} + -Dgtest_disable_pthreads=${GTEST_DISABLE_PTHREADS} + -DBUILD_GTEST=ON + PREFIX "${CMAKE_CURRENT_BINARY_DIR}" + # Disable install step + INSTALL_COMMAND "" + UPDATE_DISCONNECTED 1 # 1: do not update googletest; 0: update googletest via github + ) -# For some reason I need to disable PTHREADS -# with g++ (Ubuntu 4.9.3-8ubuntu2~14.04) 4.9.3 -# This is a known issue for MinGW : -# https://github.com/google/shaderc/pull/174 -#if(MINGW) - set(GTEST_DISABLE_PTHREADS ON) -#endif() + # Get GTest source and binary directories from CMake project -# Download GoogleTest -ExternalProject_Add(googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.8.x - # TIMEOUT 1 # We'll try this - CMAKE_ARGS -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG:PATH=DebugLibs - -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE:PATH=ReleaseLibs - -DCMAKE_CXX_FLAGS=${MSVC_COMPILER_DEFS} - -Dgtest_force_shared_crt=${GTEST_FORCE_SHARED_CRT} - -Dgtest_disable_pthreads=${GTEST_DISABLE_PTHREADS} - -DBUILD_GTEST=ON - PREFIX "${CMAKE_CURRENT_BINARY_DIR}" - # Disable install step - INSTALL_COMMAND "" - UPDATE_DISCONNECTED 1 # 1: do not update googletest; 0: update googletest via github -) + # Specify include dir + ExternalProject_Get_Property(googletest source_dir) + set(GTEST_INCLUDE_DIRS ${source_dir}/googletest/include PARENT_SCOPE) -# Get GTest source and binary directories from CMake project + # Specify MainTest's link libraries + ExternalProject_Get_Property(googletest binary_dir) + set(GTEST_LIBS_DIR ${binary_dir}/googlemock/gtest PARENT_SCOPE) -# Specify include dir -ExternalProject_Get_Property(googletest source_dir) -set(GTEST_INCLUDE_DIRS ${source_dir}/googletest/include PARENT_SCOPE) + # Create a libgtest target to be used as a dependency by test programs + add_library(libgtest IMPORTED STATIC GLOBAL) + add_dependencies(libgtest googletest) -# Specify MainTest's link libraries -ExternalProject_Get_Property(googletest binary_dir) -set(GTEST_LIBS_DIR ${binary_dir}/googlemock/gtest PARENT_SCOPE) + # Set libgtest properties + set_target_properties(libgtest PROPERTIES + "IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a" + "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" + ) -# Create a libgtest target to be used as a dependency by test programs -add_library(libgtest IMPORTED STATIC GLOBAL) -add_dependencies(libgtest googletest) +else() -# Set libgtest properties -set_target_properties(libgtest PROPERTIES - "IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a" - "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" -) + message("CMake version equal or greater than 3.11.0") + include(FetchContent) + + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG main) + + SET(INSTALL_GTEST OFF) # Disable installation of googletest + FetchContent_MakeAvailable(googletest) + +endif() + function(wolf_add_gtest target) add_executable(${target} ${ARGN}) - add_dependencies(${target} libgtest) - target_link_libraries(${target} libgtest) - - #WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin + if(${CMAKE_VERSION} VERSION_LESS "3.11.0") + add_dependencies(${target} libgtest) + target_link_libraries(${target} libgtest ${PLUGIN_NAME}) + target_include_directories(${target} PUBLIC ${GTEST_INCLUDE_DIRS}) + else() + target_link_libraries(${target} gtest_main ${PLUGIN_NAME}) + endif() add_test(NAME ${target} COMMAND ${target}) endfunction()