Skip to content

Commit

Permalink
iox-eclipse-iceoryx#1311 Remove CMake warning for googletest
Browse files Browse the repository at this point in the history
Signed-off-by: Dietrich Krönke <dietrich.kroenke@apex.ai>
  • Loading branch information
dkroenke committed Apr 12, 2022
1 parent 3d6428c commit 7b58855
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions cmake/googletest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
# Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
# Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,6 +19,12 @@ project(googletest-build CXX)

if(BUILD_TEST)

# set download config, source and build paths
set(DOWNLOAD_CONFIG_DIR ${CMAKE_BINARY_DIR}/dependencies/googletest/download)
set(SOURCE_DIR ${CMAKE_BINARY_DIR}/dependencies/googletest/src)
set(BUILD_DIR ${CMAKE_BINARY_DIR}/dependencies/googletest/build)
set(INSTALL_DIR ${CMAKE_BINARY_DIR}/dependencies/install)

include(ProcessorCount)
ProcessorCount(N)

Expand All @@ -30,31 +36,31 @@ if(BUILD_TEST)
endif()
endif()


set(EXTRA_CMAKE_ARGS)
if(DEFINED CMAKE_CXX_FLAGS)
list(APPEND EXTRA_CMAKE_ARGS -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS})
endif()

set(GTEST_BUILD_ARGS "-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}" "${EXTRA_CMAKE_ARGS}")
set(GTEST_DOWNLOAD_ARGS "${DOWNLOAD_CONFIG_DIR}")

if(WIN32)
set(ENABLE_STATIC_DEBUG "-Dgtest_force_shared_crt=ON")
endif(WIN32)
list(APPEND GTEST_BUILD_ARGS "-Dgtest_force_shared_crt=ON")
endif()

if(DEFINED CMAKE_TOOLCHAIN_FILE)
set(TOOLCHAIN_FILE "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
list(APPEND EXTRA_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
list(APPEND GTEST_DOWNLOAD_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}")
set(GTest_DIR ${CMAKE_BINARY_DIR}/dependencies/install/lib/cmake/GTest)
set(GTest_DIR ${GTest_DIR} CACHE PATH "" FORCE)
endif()

set(EXTRA_CMAKE_ARGS)
if(DEFINED CMAKE_CXX_FLAGS)
list(APPEND EXTRA_CMAKE_ARGS -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS})
endif()

# set download confi, source and build paths
set(DOWNLOAD_CONFIG_DIR ${CMAKE_BINARY_DIR}/dependencies/googletest/download)
set(SOURCE_DIR ${CMAKE_BINARY_DIR}/dependencies/googletest/src)
set(BUILD_DIR ${CMAKE_BINARY_DIR}/dependencies/googletest/build)
set(INSTALL_DIR ${CMAKE_BINARY_DIR}/dependencies/install)

# Download and unpack googletest at configure time
configure_file(googletest.cmake.in ${DOWNLOAD_CONFIG_DIR}/CMakeLists.txt)

execute_process(COMMAND ${CMAKE_COMMAND} ${ENABLE_STATIC_DEBUG} -G "${CMAKE_GENERATOR}" "${COMPILER_FLAGS}" "${TOOLCHAIN_FILE}" "${DOWNLOAD_CONFIG_DIR}"
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${GTEST_DOWNLOAD_ARGS}
RESULT_VARIABLE result
WORKING_DIRECTORY ${DOWNLOAD_CONFIG_DIR} )
if(result)
Expand All @@ -81,7 +87,7 @@ if(BUILD_TEST)
endif()
endif()

execute_process(COMMAND ${CMAKE_COMMAND} ${ENABLE_STATIC_DEBUG} -G "${CMAKE_GENERATOR}" "-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}" "${TOOLCHAIN_FILE}" "${EXTRA_CMAKE_ARGS}" "${SOURCE_DIR}"
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${GTEST_BUILD_ARGS} "${SOURCE_DIR}"
RESULT_VARIABLE result
WORKING_DIRECTORY ${BUILD_DIR} )
if(result)
Expand Down

0 comments on commit 7b58855

Please sign in to comment.