From f6aad81caeda33322d38a7fc5622eec06e03c5cb Mon Sep 17 00:00:00 2001 From: joanvallve <jvallve@iri.upc.edu> Date: Tue, 13 Feb 2024 15:12:40 +0100 Subject: [PATCH] cmake min 3.16 --- CMakeLists.txt | 2 +- test/gtest/CMakeLists.txt | 76 +++++---------------------------------- 2 files changed, 10 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11db195..c83af3b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # Pre-requisites about cmake itself -CMAKE_MINIMUM_REQUIRED(VERSION 3.10) +CMAKE_MINIMUM_REQUIRED(VERSION 3.16) # The project name and the type of project PROJECT(laser_scan_utils) diff --git a/test/gtest/CMakeLists.txt b/test/gtest/CMakeLists.txt index 00fa077..9f9ee1d 100644 --- a/test/gtest/CMakeLists.txt +++ b/test/gtest/CMakeLists.txt @@ -1,73 +1,15 @@ -if(${CMAKE_VERSION} VERSION_LESS "3.11.0") - message("CMake version less than 3.11.0") +include(FetchContent) - # Enable ExternalProject CMake module - include(ExternalProject) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG main) - set(GTEST_FORCE_SHARED_CRT ON) - set(GTEST_DISABLE_PTHREADS ON) # without this in ubuntu 18.04 we get linking errors +SET(INSTALL_GTEST OFF) # Disable installation of googletest +FetchContent_MakeAvailable(googletest) - # 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 - ) - - # Get GTest source and binary directories from CMake project - - # Specify include dir - ExternalProject_Get_Property(googletest source_dir) - set(GTEST_INCLUDE_DIRS ${source_dir}/googletest/include PARENT_SCOPE) - - # Specify MainTest's link libraries - ExternalProject_Get_Property(googletest binary_dir) - set(GTEST_LIBS_DIR ${binary_dir}/googlemock/gtest 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) - - # Set libgtest properties - set_target_properties(libgtest PROPERTIES - "IMPORTED_LOCATION" "${binary_dir}/googlemock/gtest/libgtest.a" - "IMPORTED_LINK_INTERFACE_LIBRARIES" "${CMAKE_THREAD_LIBS_INIT}" - ) - -else() - - 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 v1.8.x) - - SET(INSTALL_GTEST OFF) # Disable installation of googletest - FetchContent_MakeAvailable(googletest) - -endif() - -function(laser_scan_utils_add_gtest target) +function(wolf_add_gtest target) add_executable(${target} ${ARGN}) - if(${CMAKE_VERSION} VERSION_LESS "3.11.0") - add_dependencies(${target} libgtest) - target_link_libraries(${target} PUBLIC libgtest ${PROJECT_NAME}) - target_include_directories(${target} PUBLIC ${GTEST_INCLUDE_DIRS}) - else() - target_link_libraries(${target} PUBLIC gtest_main ${PROJECT_NAME}) - endif() + target_link_libraries(${target} gtest_main ${PLUGIN_NAME}) add_test(NAME ${target} COMMAND ${target}) endfunction() -- GitLab