From d2767ceb20bf8a6c0396195df6829f23d9ddfc06 Mon Sep 17 00:00:00 2001 From: Fred Hornsey Date: Wed, 11 Oct 2023 06:47:24 -0500 Subject: [PATCH] Try to Fix Paths in Tests and Putback MSVC_RUNTIME --- cmake/ace_group.cmake | 39 +++++++++++++++++++++++-------------- cmake/init.cmake | 8 +++++++- cmake/opendds_testing.cmake | 5 ++--- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/cmake/ace_group.cmake b/cmake/ace_group.cmake index ff66632cbe7..a9d2218368b 100644 --- a/cmake/ace_group.cmake +++ b/cmake/ace_group.cmake @@ -53,21 +53,30 @@ function(_opendds_vs_force_static) # systems, is the same kind everywhere. Normally we shouldn't make global # changes, but if we don't do this, MSVC won't link the programs if the # runtimes of compiled objects are different. - # This is based on an old CMake FAQ: - # https://web.archive.org/web/20210319004154/https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#dynamic-replace - # At some point at or before CMake 3.26 these became cache variables. - # There are alternative methods of making this work, like - # MSVC_RUNTIME_LIBRARY, but this method seems like it works best for our - # purposes. - foreach(flag_var - CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE - CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) - if(${flag_var} MATCHES "/MD") - string(REGEX REPLACE "/MD" "/MT" new_value "${${flag_var}}") - set(${flag_var} "${new_value}" CACHE INTERNAL - "CXX Flags (Overridden by OpenDDS to match /MT* with ACE)") - endif() - endforeach() + # See the following for more info: + # https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html#variable:CMAKE_MSVC_RUNTIME_LIBRARY + # https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#how-can-i-build-my-msvc-application-with-a-static-runtime + cmake_policy(GET CMP0091 policy91) + if(policy91 STREQUAL NEW) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" CACHE STRING "" FORCE) + else() + foreach(flag_var + CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE + CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) + string(REGEX REPLACE "/M[DT][d]? " "" value "${${flag_var}}") + string(REGEX REPLACE " /M[DT][d]?" "" value "${value}") + string(REGEX REPLACE "/M[DT][d]?" "" value "${value}") + if(value) + set(value "${value} ") + endif() + set(value "${value}/MT") + if(flag_var STREQUAL "CMAKE_CXX_FLAGS_DEBUG") + set(value "${value}d") + endif() + set(${flag_var} "${value}" CACHE STRING + "CXX Flags (Overridden by OpenDDS to match /MT* with ACE)" FORCE) + endforeach() + endif() endfunction() if(MSVC AND OPENDDS_STATIC) diff --git a/cmake/init.cmake b/cmake/init.cmake index ba841627784..66848cc8a2f 100644 --- a/cmake/init.cmake +++ b/cmake/init.cmake @@ -203,7 +203,13 @@ function(_opendds_pop_list list_var) endfunction() function(_opendds_path_list path_list_var) - set(path_list) + if("APPEND" IN_LIST ARGN) + set(path_list "${${path_list_var}}") + list(REMOVE_ITEM ARGN APPEND) + else() + set(path_list) + endif() + if(WIN32) set(delimiter ";") else() diff --git a/cmake/opendds_testing.cmake b/cmake/opendds_testing.cmake index ba2b3ea8836..c2b2fe61368 100644 --- a/cmake/opendds_testing.cmake +++ b/cmake/opendds_testing.cmake @@ -29,10 +29,9 @@ function(opendds_add_test) endif() _opendds_path_list(lib_dir_list "$ENV{${env_var_name}}" "${TAO_LIB_DIR}") foreach(lib_dir "${OPENDDS_LIB_DIR}" ${arg_EXTRA_LIB_DIRS}) - _opendds_path_list(lib_dir_list "$ENV{${env_var_name}}" "${lib_dir}") + _opendds_path_list(lib_dir_list APPEND "${lib_dir}") if(CMAKE_CONFIGURATION_TYPES) - _opendds_path_list(lib_dir_list - "$ENV{${env_var_name}}" "${lib_dir}$<$>:/$>") + _opendds_path_list(lib_dir_list APPEND "${lib_dir}$<$>:/$>") endif() endforeach() if(WIN32)