Skip to content
Snippets Groups Projects
Commit 2d4022b5 authored by Mederic Fourmy's avatar Mederic Fourmy
Browse files

Merge branch '22-adapt-to-core-cmakelists-txt-refactor' into 'devel'

Resolve "Adapt to core CMakeLists.txt refactor"

Closes #22

See merge request !33
parents d565d4f5 a95008f9
No related branches found
No related tags found
2 merge requests!36After cmake and const refactor,!33Resolve "Adapt to core CMakeLists.txt refactor"
...@@ -5,6 +5,7 @@ stages: ...@@ -5,6 +5,7 @@ stages:
############ YAML ANCHORS ############ ############ YAML ANCHORS ############
.print_variables_template: &print_variables_definition .print_variables_template: &print_variables_definition
# Print variables # Print variables
- echo $WOLF_CORE_BRANCH
- echo $CI_COMMIT_BRANCH - echo $CI_COMMIT_BRANCH
- echo $WOLF_VISION_BRANCH - echo $WOLF_VISION_BRANCH
......
# Pre-requisites about cmake itself # 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 # MAC OSX RPATH
SET(CMAKE_MACOSX_RPATH true) SET(CMAKE_MACOSX_RPATH true)
# The project name # The project name
PROJECT(vision) PROJECT(vision)
set(PLUGIN_NAME wolf${PROJECT_NAME}) set(PLUGIN_NAME "wolf${PROJECT_NAME}")
MESSAGE("Starting ${PROJECT_NAME} CMakeLists ...") MESSAGE("Starting ${PROJECT_NAME} CMakeLists ...")
# Paths
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin) SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib) 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) IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "DEBUG") SET(CMAKE_BUILD_TYPE "DEBUG")
...@@ -68,10 +66,6 @@ if(BUILD_TESTS) ...@@ -68,10 +66,6 @@ if(BUILD_TESTS)
enable_testing() enable_testing()
endif() endif()
#CMAKE modules
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake_modules")
MESSAGE(STATUS ${CMAKE_MODULE_PATH})
# Some wolf compilation options # Some wolf compilation options
IF((CMAKE_BUILD_TYPE MATCHES DEBUG) OR (CMAKE_BUILD_TYPE MATCHES debug) OR (CMAKE_BUILD_TYPE MATCHES Debug)) IF((CMAKE_BUILD_TYPE MATCHES DEBUG) OR (CMAKE_BUILD_TYPE MATCHES debug) OR (CMAKE_BUILD_TYPE MATCHES Debug))
set(_WOLF_DEBUG true) set(_WOLF_DEBUG true)
...@@ -80,8 +74,10 @@ ENDIF() ...@@ -80,8 +74,10 @@ ENDIF()
option(_WOLF_TRACE "Enable wolf tracing macro" ON) option(_WOLF_TRACE "Enable wolf tracing macro" ON)
# ============ DEPENDENCIES ================== # ============ DEPENDENCIES ==================
FIND_PACKAGE(wolfcore REQUIRED) FIND_PACKAGE(wolfcore REQUIRED CONFIG)
FIND_PACKAGE(OpenCV REQUIRED) FIND_PACKAGE(OpenCV REQUIRED CONFIG
COMPONENTS core imgcodecs highgui features2d calib3d video
)
IF(OpenCV_FOUND) IF(OpenCV_FOUND)
MESSAGE(STATUS "Found OpenCV: ${OpenCV_INCLUDE_DIRS}") MESSAGE(STATUS "Found OpenCV: ${OpenCV_INCLUDE_DIRS}")
ELSEIF() ELSEIF()
...@@ -89,8 +85,9 @@ ELSEIF() ...@@ -89,8 +85,9 @@ ELSEIF()
ENDIF() ENDIF()
# ============ config.h ================== # ============ config.h ==================
string(TOUPPER ${PROJECT_NAME} UPPER_NAME)
set(_WOLF_ROOT_DIR ${CMAKE_SOURCE_DIR}) 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 # Define the directory where will be the configured config.h
SET(WOLF_CONFIG_DIR ${PROJECT_BINARY_DIR}/conf/${PROJECT_NAME}/internal) SET(WOLF_CONFIG_DIR ${PROJECT_BINARY_DIR}/conf/${PROJECT_NAME}/internal)
...@@ -110,8 +107,6 @@ message("CONFIG DIRECTORY ${PROJECT_BINARY_DIR}") ...@@ -110,8 +107,6 @@ message("CONFIG DIRECTORY ${PROJECT_BINARY_DIR}")
include_directories("${PROJECT_BINARY_DIR}/conf") include_directories("${PROJECT_BINARY_DIR}/conf")
# ============ INCLUDES ================== # ============ INCLUDES ==================
INCLUDE_DIRECTORIES(${wolfcore_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(BEFORE "include") INCLUDE_DIRECTORIES(BEFORE "include")
# ============ HEADERS ============ # ============ HEADERS ============
...@@ -189,10 +184,20 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") ...@@ -189,10 +184,20 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# using GCC # using GCC
endif() endif()
#Link the created libraries # Link the created libraries
#===============EXAMPLE========================= #===============EXAMPLE=========================
TARGET_LINK_LIBRARIES(${PLUGIN_NAME} ${wolfcore_LIBRARIES}) TARGET_LINK_LIBRARIES(${PLUGIN_NAME} wolfcore)
TARGET_LINK_LIBRARIES(${PLUGIN_NAME} ${OpenCV_LIBS}) # For OpenCV, link with respect to each required components, found in the find_package command
# The required components have the same name as the include files e.g. <opencv2/core.hpp>
# or the opencv2 subdirectory in which they are found, e.g. <opencv2/video/tracking.hpp>
TARGET_LINK_LIBRARIES(${PLUGIN_NAME}
opencv_core
opencv_imgcodecs
opencv_highgui
opencv_features2d
opencv_calib3d
opencv_video
)
#Build demos #Build demos
#===============EXAMPLE========================= #===============EXAMPLE=========================
...@@ -211,40 +216,60 @@ ENDIF(BUILD_TESTS) ...@@ -211,40 +216,60 @@ ENDIF(BUILD_TESTS)
#install library #install library
#============================================================= #=============================================================
INSTALL(TARGETS ${PLUGIN_NAME} EXPORT ${PLUGIN_NAME}Targets INSTALL(TARGETS ${PLUGIN_NAME} EXPORT ${PLUGIN_NAME}Targets
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
LIBRARY DESTINATION lib LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION lib) 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 headers
INSTALL(FILES ${HDRS_CAPTURE} 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} 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} 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} 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} 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} 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} INSTALL(FILES ${HDRS_SENSOR}
DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/sensor) DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/sensor)
FILE(WRITE ${PROJECT_NAME}.found "")
INSTALL(FILES ${PROJECT_NAME}.found
DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME})
INSTALL(FILES "${WOLF_CONFIG_DIR}/config.h" INSTALL(FILES "${WOLF_CONFIG_DIR}/config.h"
DESTINATION include/iri-algorithms/wolf/plugin_${PROJECT_NAME}/${PROJECT_NAME}/internal) DESTINATION ${INCLUDE_INSTALL_DIR}/${PROJECT_NAME}/internal)
INSTALL(FILES "${CMAKE_SOURCE_DIR}/cmake_modules/${PLUGIN_NAME}Config.cmake" DESTINATION "lib/cmake/${PLUGIN_NAME}")
INSTALL(DIRECTORY ${SPDLOG_INCLUDE_DIRS} DESTINATION "include/iri-algorithms/") INSTALL(DIRECTORY ${SPDLOG_INCLUDE_DIRS} DESTINATION "include/iri-algorithms/")
export(PACKAGE ${PLUGIN_NAME}) export(PACKAGE ${PLUGIN_NAME})
FIND_PACKAGE(Doxygen) FIND_PACKAGE(Doxygen MODULE)
FIND_PATH(IRI_DOC_DIR doxygen.conf ${CMAKE_SOURCE_DIR}/doc/iri_doc/) FIND_PATH(IRI_DOC_DIR doxygen.conf ${CMAKE_SOURCE_DIR}/doc/iri_doc/)
IF (IRI_DOC_DIR) IF (IRI_DOC_DIR)
......
#edit the following line to add the librarie's header files
FIND_PATH(
wolfvision_INCLUDE_DIRS
NAMES vision.found
PATHS /usr/local/include/iri-algorithms/wolf/plugin_vision)
IF(wolfvision_INCLUDE_DIRS)
MESSAGE("Found vision include dirs: ${wolfvision_INCLUDE_DIRS}")
ELSE(wolfvision_INCLUDE_DIRS)
MESSAGE("Couldn't find vision include dirs")
ENDIF(wolfvision_INCLUDE_DIRS)
FIND_LIBRARY(
wolfvision_LIBRARIES
NAMES libwolfvision.so libwolfvision.dylib
PATHS /usr/local/lib)
IF(wolfvision_LIBRARIES)
MESSAGE("Found vision lib: ${wolfvision_LIBRARIES}")
ELSE(wolfvision_LIBRARIES)
MESSAGE("Couldn't find wolf vision lib")
ENDIF(wolfvision_LIBRARIES)
IF (wolfvision_INCLUDE_DIRS AND wolfvision_LIBRARIES)
SET(wolfvision_FOUND TRUE)
ELSE(wolfvision_INCLUDE_DIRS AND wolfvision_LIBRARIES)
set(wolfvision_FOUND FALSE)
ENDIF (wolfvision_INCLUDE_DIRS AND wolfvision_LIBRARIES)
IF (wolfvision_FOUND)
IF (NOT wolfvision_FIND_QUIETLY)
MESSAGE(STATUS "Found vision: ${wolfvision_LIBRARIES}")
ENDIF (NOT wolfvision_FIND_QUIETLY)
ELSE (wolfvision_FOUND)
IF (wolfvision_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find wolf vision")
ENDIF (wolfvision_FIND_REQUIRED)
ENDIF (wolfvision_FOUND)
macro(wolf_report_not_found REASON_MSG)
set(wolfvision_FOUND FALSE)
unset(wolfvision_INCLUDE_DIRS)
unset(wolfvision_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 (wolfvision_FIND_QUIETLY)
message(STATUS "Failed to find wolfvision- " ${REASON_MSG} ${ARGN})
elseif (wolfvision_FIND_REQUIRED)
message(FATAL_ERROR "Failed to find wolfvision - " ${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 wolfvision - " ${REASON_MSG} ${ARGN})
endif ()
return()
endmacro(wolf_report_not_found)
if(NOT wolfvision_FOUND)
wolf_report_not_found("Something went wrong while setting up wolf vision.")
endif(NOT wolfvision_FOUND)
# Set the include directories for wolf (itself).
set(wolfvision_FOUND TRUE)
# Now we gather all the required dependencies for Wolf Laser
FIND_PACKAGE(OpenCV REQUIRED)
list(APPEND wolfvision_INCLUDE_DIRS ${OpenCV_INCLUDE_DIRS})
list(APPEND wolfvision_LIBRARIES ${OpenCV_LIBS})
#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 wolfvision_INCLUDE_DIRS)
list(APPEND wolfvision_INCLUDE_DIRS ${wolfcore_INCLUDE_DIRS})
list(REVERSE wolfvision_INCLUDE_DIRS)
list(REVERSE wolfvision_LIBRARIES)
list(APPEND wolfvision_LIBRARIES ${wolfcore_LIBRARIES})
list(REVERSE wolfvision_LIBRARIES)
endif()
# provide both INCLUDE_DIR and INCLUDE_DIRS
SET(wolfvision_INCLUDE_DIR ${wolfvision_INCLUDE_DIRS})
# provide both LIBRARY and LIBRARIES
SET(wolfvision_LIBRARY ${wolfvision_LIBRARIES})
\ No newline at end of file
set(@PLUGIN_NAME@_VERSION 0.0.1)
@PACKAGE_INIT@
set_and_check(@PLUGIN_NAME@_INCLUDE_DIR "@PACKAGE_INCLUDE_INSTALL_DIR@")
set(@PLUGIN_NAME@_INCLUDE_DIRS @PLUGIN_NAME@_INCLUDE_DIR)
set_and_check(@PLUGIN_NAME@_LIB_INSTALL_DIR "@PACKAGE_LIB_INSTALL_DIR@")
set(@PLUGIN_NAME@_LIB_INSTALL_DIRS @PLUGIN_NAME@_LIB_INSTALL_DIR)
# forwards the correct parameters given to FIND_DEPENDENCIES
include(CMakeFindDependencyMacro)
FIND_DEPENDENCY(OpenCV REQUIRED)
include("${CMAKE_CURRENT_LIST_DIR}/@PLUGIN_NAME@Targets.cmake")
check_required_components(@PLUGIN_NAME@)
\ No newline at end of file
if (OpenCV_FOUND)
if (${OpenCV_VERSION_MAJOR} GREATER 1)
message("-- [INFO] Found OpenCV support")
ADD_DEFINITIONS(-DHAVE_OPENCV_H)
SET(USE_CV true)
else(${OpenCV_VERSION_MAJOR} GREATER 1)
message("[WARN] OpenCV support not installed. Minimum 2.4 version required.")
message("[WARN] Current version ${OpenCV_VERSION_MAJOR}")
endif(${OpenCV_VERSION_MAJOR} GREATER 1)
else(OpenCV_FOUND)
message("[WARN] OpenCV support not installed. Minimum 2.4 version required.")
endif(OpenCV_FOUND)
ADD_EXECUTABLE(demo_visual_odometry demo_visual_odometry.cpp) ADD_EXECUTABLE(demo_visual_odometry demo_visual_odometry.cpp)
TARGET_LINK_LIBRARIES(demo_visual_odometry ${PLUGIN_NAME} ${OpenCV_LIBS}) TARGET_LINK_LIBRARIES(demo_visual_odometry ${PLUGIN_NAME} ${OpenCV_LIBS})
\ No newline at end of file
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
// Opencv includes // Opencv includes
#include <opencv2/core.hpp> #include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp> #include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/features2d.hpp> #include <opencv2/features2d.hpp>
#include <opencv2/calib3d/calib3d.hpp> #include <opencv2/calib3d/calib3d.hpp>
#include <opencv2/video/tracking.hpp> #include <opencv2/video/tracking.hpp>
......
...@@ -24,13 +24,13 @@ ...@@ -24,13 +24,13 @@
// which will be added to the include path for compilation, // which will be added to the include path for compilation,
// and installed with the public wolf headers. // and installed with the public wolf headers.
#ifndef WOLF_INTERNAL_${UPPER_NAME}_CONFIG_H_ #ifndef WOLF_INTERNAL_${PROJECT_NAME_UPPER}_CONFIG_H_
#define WOLF_INTERNAL_${UPPER_NAME}_CONFIG_H_ #define WOLF_INTERNAL_${PROJECT_NAME_UPPER}_CONFIG_H_
#cmakedefine _WOLF_DEBUG #cmakedefine _WOLF_DEBUG
#cmakedefine _WOLF_TRACE #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_ */ #endif /* WOLF_INTERNAL_CONFIG_H_ */
# Retrieve googletest from github & compile # Retrieve googletest from github & compile
add_subdirectory(gtest) add_subdirectory(gtest)
############# USE THIS TEST AS AN EXAMPLE #################
# Include gtest directory. # #
include_directories(${GTEST_INCLUDE_DIRS}) # Create a specific test executable for gtest_example #
# wolf_add_gtest(gtest_example gtest_example.cpp) #
# #
###########################################################
wolf_add_gtest(gtest_pinhole gtest_pinhole.cpp) wolf_add_gtest(gtest_pinhole gtest_pinhole.cpp)
target_link_libraries(gtest_pinhole ${PLUGIN_NAME})
wolf_add_gtest(gtest_capture_image gtest_capture_image.cpp) wolf_add_gtest(gtest_capture_image gtest_capture_image.cpp)
target_link_libraries(gtest_capture_image ${PLUGIN_NAME})
wolf_add_gtest(gtest_feature_point_image gtest_feature_point_image.cpp) wolf_add_gtest(gtest_feature_point_image gtest_feature_point_image.cpp)
target_link_libraries(gtest_feature_point_image ${PLUGIN_NAME})
wolf_add_gtest(gtest_sensor_camera gtest_sensor_camera.cpp) wolf_add_gtest(gtest_sensor_camera gtest_sensor_camera.cpp)
target_link_libraries(gtest_sensor_camera ${PLUGIN_NAME})
wolf_add_gtest(gtest_processor_visual_odometry gtest_processor_visual_odometry.cpp)
target_link_libraries(gtest_processor_visual_odometry ${PLUGIN_NAME})
# # FactorTrifocal test
# wolf_add_gtest(gtest_factor_trifocal gtest_factor_trifocal.cpp)
# target_link_libraries(gtest_factor_trifocal ${PLUGIN_NAME})
# # FactorFeatureEpipolar test
# wolf_add_gtest(gtest_factor_epipolar gtest_factor_epipolar.cpp)
# target_link_libraries(gtest_factor_epipolar ${PLUGIN_NAME})
# # ProcessorBundleAdjustment test
# wolf_add_gtest(gtest_processor_bundle_adjustment gtest_processor_bundle_adjustment.cpp)
# target_link_libraries(gtest_processor_bundle_adjustment ${PLUGIN_NAME})
# # FactorPixelHp test -> depends on processor_bundle_adjustment.cpp wolf_add_gtest(gtest_processor_visual_odometry gtest_processor_visual_odometry.cpp)
# wolf_add_gtest(gtest_factor_pixel_hp gtest_factor_pixel_hp.cpp) \ No newline at end of file
# target_link_libraries(gtest_factor_pixel_hp ${PLUGIN_NAME})
cmake_minimum_required(VERSION 2.8.8) if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
project(gtest_builder C CXX) message("CMake version less than 3.11.0")
# We need thread support # Enable ExternalProject CMake module
#find_package(Threads REQUIRED) include(ExternalProject)
# Enable ExternalProject CMake module set(GTEST_FORCE_SHARED_CRT ON)
include(ExternalProject) set(GTEST_DISABLE_PTHREADS ON) # without this in ubuntu 18.04 we get linking errors
set(GTEST_FORCE_SHARED_CRT ON) # Download GoogleTest
set(GTEST_DISABLE_PTHREADS OFF) 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 # Get GTest source and binary directories from CMake project
# 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()
# Download GoogleTest # Specify include dir
ExternalProject_Add(googletest ExternalProject_Get_Property(googletest source_dir)
GIT_REPOSITORY https://github.com/google/googletest.git set(GTEST_INCLUDE_DIRS ${source_dir}/googletest/include PARENT_SCOPE)
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
)
# 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 # Create a libgtest target to be used as a dependency by test programs
ExternalProject_Get_Property(googletest source_dir) add_library(libgtest IMPORTED STATIC GLOBAL)
set(GTEST_INCLUDE_DIRS ${source_dir}/googletest/include PARENT_SCOPE) add_dependencies(libgtest googletest)
# Specify MainTest's link libraries # Set libgtest properties
ExternalProject_Get_Property(googletest binary_dir) set_target_properties(libgtest PROPERTIES
set(GTEST_LIBS_DIR ${binary_dir}/googlemock/gtest PARENT_SCOPE) "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 else()
add_library(libgtest IMPORTED STATIC GLOBAL)
add_dependencies(libgtest googletest)
# Set libgtest properties message("CMake version equal or greater than 3.11.0")
set_target_properties(libgtest PROPERTIES
"IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a"
"IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}"
)
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) function(wolf_add_gtest target)
add_executable(${target} ${ARGN}) add_executable(${target} ${ARGN})
add_dependencies(${target} libgtest) if(${CMAKE_VERSION} VERSION_LESS "3.11.0")
target_link_libraries(${target} libgtest) add_dependencies(${target} libgtest)
target_link_libraries(${target} libgtest ${PLUGIN_NAME})
#WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin target_include_directories(${target} PUBLIC ${GTEST_INCLUDE_DIRS})
else()
target_link_libraries(${target} PUBLIC gtest_main ${PLUGIN_NAME})
endif()
add_test(NAME ${target} COMMAND ${target}) add_test(NAME ${target} COMMAND ${target})
endfunction() endfunction()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment