From 6bb70df05b393ea3d4cb7bc0fc1545287526dada Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Fri, 3 Jan 2025 07:58:05 -0500 Subject: [PATCH 1/9] Use newer binary output directory variables and don't specify output directory on each target --- cmake/GtsamBuildTypes.cmake | 6 +++--- gtsam/3rdparty/cephes/CMakeLists.txt | 3 +-- gtsam/3rdparty/metis/libmetis/CMakeLists.txt | 1 - gtsam/CMakeLists.txt | 3 +-- gtsam_unstable/CMakeLists.txt | 3 +-- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cmake/GtsamBuildTypes.cmake b/cmake/GtsamBuildTypes.cmake index 2aad58abb..19314cd31 100644 --- a/cmake/GtsamBuildTypes.cmake +++ b/cmake/GtsamBuildTypes.cmake @@ -250,9 +250,9 @@ endif() # Make common binary output directory when on Windows if(WIN32) - set(RUNTIME_OUTPUT_PATH "${GTSAM_BINARY_DIR}/bin") - set(EXECUTABLE_OUTPUT_PATH "${GTSAM_BINARY_DIR}/bin") - set(LIBRARY_OUTPUT_PATH "${GTSAM_BINARY_DIR}/lib") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${GTSAM_BINARY_DIR}/bin") + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${GTSAM_BINARY_DIR}/lib") + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${GTSAM_BINARY_DIR}/lib") endif() # Set up build type list for cmake-gui diff --git a/gtsam/3rdparty/cephes/CMakeLists.txt b/gtsam/3rdparty/cephes/CMakeLists.txt index aeac7b403..d510ddf81 100644 --- a/gtsam/3rdparty/cephes/CMakeLists.txt +++ b/gtsam/3rdparty/cephes/CMakeLists.txt @@ -106,8 +106,7 @@ if(WIN32) set_target_properties( cephes-gtsam PROPERTIES PREFIX "" - COMPILE_FLAGS /w - RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/../../../bin") + COMPILE_FLAGS /w) endif() if(APPLE) diff --git a/gtsam/3rdparty/metis/libmetis/CMakeLists.txt b/gtsam/3rdparty/metis/libmetis/CMakeLists.txt index f3b8694f4..e0a178c5b 100644 --- a/gtsam/3rdparty/metis/libmetis/CMakeLists.txt +++ b/gtsam/3rdparty/metis/libmetis/CMakeLists.txt @@ -13,7 +13,6 @@ if(WIN32) set_target_properties(metis-gtsam PROPERTIES PREFIX "" COMPILE_FLAGS /w - RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/../../../bin" WINDOWS_EXPORT_ALL_SYMBOLS ON) endif() diff --git a/gtsam/CMakeLists.txt b/gtsam/CMakeLists.txt index 87440d19f..5d71bb7be 100644 --- a/gtsam/CMakeLists.txt +++ b/gtsam/CMakeLists.txt @@ -185,8 +185,7 @@ if(WIN32) # Add 'lib' prefix to static library to avoid filename collision with else() set_target_properties(gtsam PROPERTIES PREFIX "" - DEFINE_SYMBOL GTSAM_EXPORTS - RUNTIME_OUTPUT_DIRECTORY "${GTSAM_BINARY_DIR}/bin") + DEFINE_SYMBOL GTSAM_EXPORTS) endif() endif() diff --git a/gtsam_unstable/CMakeLists.txt b/gtsam_unstable/CMakeLists.txt index 1f7b4a7c7..730b6389a 100644 --- a/gtsam_unstable/CMakeLists.txt +++ b/gtsam_unstable/CMakeLists.txt @@ -108,8 +108,7 @@ if(WIN32) # Add 'lib' prefix to static library to avoid filename collision with else() set_target_properties(gtsam_unstable PROPERTIES PREFIX "" - DEFINE_SYMBOL GTSAM_UNSTABLE_EXPORTS - RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin") + DEFINE_SYMBOL GTSAM_UNSTABLE_EXPORTS) endif() endif() From e08064d9e7edc40ea53ce72241e384489403e6d2 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Jan 2025 07:49:32 -0500 Subject: [PATCH 2/9] Use CMAKE_POSITION_INDEPENDENT_CODE instead of -fPIC --- CMakeLists.txt | 1 + cmake/GtsamBuildTypes.cmake | 1 - gtsam/3rdparty/metis/libmetis/CMakeLists.txt | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 90162fe29..85c3d1b44 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ if(MSVC) set(CMAKE_STATIC_LINKER_FLAGS ${MSVC_LINKER_FLAGS}) endif() +set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(GtsamMakeConfigFile) include(GNUInstallDirs) diff --git a/cmake/GtsamBuildTypes.cmake b/cmake/GtsamBuildTypes.cmake index 19314cd31..76c04a2f9 100644 --- a/cmake/GtsamBuildTypes.cmake +++ b/cmake/GtsamBuildTypes.cmake @@ -130,7 +130,6 @@ else() set(GTSAM_COMPILE_OPTIONS_PRIVATE_COMMON -Wall # Enable common warnings - -fPIC # ensure proper code generation for shared libraries $<$:-Wreturn-local-addr -Werror=return-local-addr> # Error: return local address $<$:-Wreturn-stack-address -Werror=return-stack-address> # Error: return local address $<$:-Wno-weak-template-vtables> # TODO(dellaert): don't know how to resolve diff --git a/gtsam/3rdparty/metis/libmetis/CMakeLists.txt b/gtsam/3rdparty/metis/libmetis/CMakeLists.txt index e0a178c5b..96ec59f64 100644 --- a/gtsam/3rdparty/metis/libmetis/CMakeLists.txt +++ b/gtsam/3rdparty/metis/libmetis/CMakeLists.txt @@ -3,7 +3,6 @@ include_directories(.) # Find sources. file(GLOB metis_sources *.c) # Build libmetis. -add_definitions(-fPIC) add_library(metis-gtsam ${METIS_LIBRARY_TYPE} ${GKlib_sources} ${metis_sources}) if(UNIX) target_link_libraries(metis-gtsam m) From 885959a36b0d1799f8ff0ce33b9421e4fa340906 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Jan 2025 07:51:36 -0500 Subject: [PATCH 3/9] Use new CMake policies up to 3.29 This silences most warnings about overriding /W3 with /w --- CMakeLists.txt | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 85c3d1b44..453006d41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,23 +1,8 @@ -cmake_minimum_required(VERSION 3.9) -if (POLICY CMP0082) - cmake_policy(SET CMP0082 NEW) # install from sub-directories immediately -endif() -if (POLICY CMP0102) -cmake_policy(SET CMP0102 NEW) # set policy on advanced variables and cmake cache -endif() -if (POLICY CMP0156) -cmake_policy(SET CMP0156 NEW) # new linker strategies -endif() +cmake_minimum_required(VERSION 3.9...3.29) if (POLICY CMP0167) cmake_policy(SET CMP0167 OLD) # Don't complain about boost endif() -# allow parent project to override options -if (POLICY CMP0077) - cmake_policy(SET CMP0077 NEW) -endif(POLICY CMP0077) - - # Set the version number for the library set (GTSAM_VERSION_MAJOR 4) set (GTSAM_VERSION_MINOR 3) From 3d23152a75980b14e2ba5b84dbd84a286d07428d Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Jan 2025 07:52:59 -0500 Subject: [PATCH 4/9] Clean up version finding in HandleEigen --- cmake/HandleEigen.cmake | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/cmake/HandleEigen.cmake b/cmake/HandleEigen.cmake index 707593889..becebafb9 100644 --- a/cmake/HandleEigen.cmake +++ b/cmake/HandleEigen.cmake @@ -13,12 +13,6 @@ if(GTSAM_USE_SYSTEM_EIGEN) # Since Eigen 3.3.0 a Eigen3Config.cmake is available so use it. find_package(Eigen3 CONFIG REQUIRED) # need to find again as REQUIRED - # The actual include directory (for BUILD cmake target interface): - # Note: EIGEN3_INCLUDE_DIR points to some random location on some eigen - # versions. So here I use the target itself to get the proper include - # directory (it is generated by cmake, thus has the correct path) - get_target_property(GTSAM_EIGEN_INCLUDE_FOR_BUILD Eigen3::Eigen INTERFACE_INCLUDE_DIRECTORIES) - # check if MKL is also enabled - can have one or the other, but not both! # Note: Eigen >= v3.2.5 includes our patches if(EIGEN_USE_MKL_ALL AND (EIGEN3_VERSION VERSION_LESS 3.2.5)) @@ -30,6 +24,8 @@ if(GTSAM_USE_SYSTEM_EIGEN) if(EIGEN_USE_MKL_ALL AND (EIGEN3_VERSION VERSION_EQUAL 3.3.4)) message(FATAL_ERROR "MKL does not work with Eigen 3.3.4 because of a bug in Eigen. See http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1527. Disable GTSAM_USE_SYSTEM_EIGEN to use GTSAM's copy of Eigen, disable GTSAM_WITH_EIGEN_MKL, or upgrade/patch your installation of Eigen.") endif() + + set(GTSAM_EIGEN_VERSION "${EIGEN3_VERSION}") else() # Use bundled Eigen include path. # Clear any variables set by FindEigen3 @@ -46,7 +42,7 @@ else() add_library(gtsam_eigen3 INTERFACE) - target_include_directories(gtsam_eigen3 INTERFACE + target_include_directories(gtsam_eigen3 SYSTEM INTERFACE $ $ ) @@ -56,11 +52,8 @@ else() list(APPEND GTSAM_EXPORTED_TARGETS gtsam_eigen3) set(GTSAM_EXPORTED_TARGETS "${GTSAM_EXPORTED_TARGETS}") -endif() - -# Detect Eigen version: -set(EIGEN_VER_H "${GTSAM_EIGEN_INCLUDE_FOR_BUILD}/Eigen/src/Core/util/Macros.h") -if (EXISTS ${EIGEN_VER_H}) + # Detect Eigen version: + set(EIGEN_VER_H "${GTSAM_EIGEN_INCLUDE_FOR_BUILD}/Eigen/src/Core/util/Macros.h") file(READ "${EIGEN_VER_H}" STR_EIGEN_VERSION) # Extract the Eigen version from the Macros.h file, lines "#define EIGEN_WORLD_VERSION XX", etc... @@ -75,11 +68,9 @@ if (EXISTS ${EIGEN_VER_H}) string(REGEX MATCH "[0-9]+" GTSAM_EIGEN_VERSION_MINOR "${GTSAM_EIGEN_VERSION_MINOR}") set(GTSAM_EIGEN_VERSION "${GTSAM_EIGEN_VERSION_WORLD}.${GTSAM_EIGEN_VERSION_MAJOR}.${GTSAM_EIGEN_VERSION_MINOR}") +endif() - message(STATUS "Found Eigen version: ${GTSAM_EIGEN_VERSION}") -else() - message(WARNING "Cannot determine Eigen version, missing file: `${EIGEN_VER_H}`") -endif () +message(STATUS "Found Eigen version: ${GTSAM_EIGEN_VERSION}") if (MSVC) if (GTSAM_SHARED_LIB) From f638035e104b6363e09d5b5cd25ae2daa7555ba5 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Jan 2025 07:53:19 -0500 Subject: [PATCH 5/9] Remove redundant MSVC optimization flag in GKLib --- gtsam/3rdparty/metis/GKlib/GKlibSystem.cmake | 1 - 1 file changed, 1 deletion(-) diff --git a/gtsam/3rdparty/metis/GKlib/GKlibSystem.cmake b/gtsam/3rdparty/metis/GKlib/GKlibSystem.cmake index 7ea5bab94..229e39a90 100644 --- a/gtsam/3rdparty/metis/GKlib/GKlibSystem.cmake +++ b/gtsam/3rdparty/metis/GKlib/GKlibSystem.cmake @@ -15,7 +15,6 @@ option(GKRAND "enable GKRAND support" OFF) # Add compiler flags. if(MSVC) - set(GKlib_COPTS "/Ox") set(GKlib_COPTIONS "-DWIN32 -DMSC -D_CRT_SECURE_NO_DEPRECATE -DUSE_GKREGEX") elseif(MINGW) set(GKlib_COPTS "-DUSE_GKREGEX") From 0435efdebcaf50bd28927a19140b134affebcf2a Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Jan 2025 08:27:19 -0500 Subject: [PATCH 6/9] Remove PREFIX "" --- gtsam/3rdparty/cephes/CMakeLists.txt | 5 +---- gtsam/3rdparty/metis/libmetis/CMakeLists.txt | 1 - gtsam/CMakeLists.txt | 4 +--- gtsam_unstable/CMakeLists.txt | 1 - 4 files changed, 2 insertions(+), 9 deletions(-) diff --git a/gtsam/3rdparty/cephes/CMakeLists.txt b/gtsam/3rdparty/cephes/CMakeLists.txt index d510ddf81..d1c8cfe0d 100644 --- a/gtsam/3rdparty/cephes/CMakeLists.txt +++ b/gtsam/3rdparty/cephes/CMakeLists.txt @@ -103,10 +103,7 @@ set_target_properties( C_STANDARD 99) if(WIN32) - set_target_properties( - cephes-gtsam - PROPERTIES PREFIX "" - COMPILE_FLAGS /w) + set_target_properties(cephes-gtsam PROPERTIES COMPILE_FLAGS /w) endif() if(APPLE) diff --git a/gtsam/3rdparty/metis/libmetis/CMakeLists.txt b/gtsam/3rdparty/metis/libmetis/CMakeLists.txt index 96ec59f64..8a35c2f6b 100644 --- a/gtsam/3rdparty/metis/libmetis/CMakeLists.txt +++ b/gtsam/3rdparty/metis/libmetis/CMakeLists.txt @@ -10,7 +10,6 @@ endif() if(WIN32) set_target_properties(metis-gtsam PROPERTIES - PREFIX "" COMPILE_FLAGS /w WINDOWS_EXPORT_ALL_SYMBOLS ON) endif() diff --git a/gtsam/CMakeLists.txt b/gtsam/CMakeLists.txt index 5d71bb7be..3c2073547 100644 --- a/gtsam/CMakeLists.txt +++ b/gtsam/CMakeLists.txt @@ -183,9 +183,7 @@ if(WIN32) # Add 'lib' prefix to static library to avoid filename collision with PREFIX "lib") target_compile_definitions(gtsam PRIVATE GTSAM_IMPORT_STATIC) else() - set_target_properties(gtsam PROPERTIES - PREFIX "" - DEFINE_SYMBOL GTSAM_EXPORTS) + set_target_properties(gtsam PROPERTIES DEFINE_SYMBOL GTSAM_EXPORTS) endif() endif() diff --git a/gtsam_unstable/CMakeLists.txt b/gtsam_unstable/CMakeLists.txt index 730b6389a..aaffe54a8 100644 --- a/gtsam_unstable/CMakeLists.txt +++ b/gtsam_unstable/CMakeLists.txt @@ -107,7 +107,6 @@ if(WIN32) # Add 'lib' prefix to static library to avoid filename collision with COMPILE_DEFINITIONS GTSAM_UNSTABLE_IMPORT_STATIC) else() set_target_properties(gtsam_unstable PROPERTIES - PREFIX "" DEFINE_SYMBOL GTSAM_UNSTABLE_EXPORTS) endif() endif() From 7742f025fcda64a3b5ac68d64d149858897630cf Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Jan 2025 08:45:47 -0500 Subject: [PATCH 7/9] Clean up MSVC flags to allow use of MSVC variables instead Generator expressions were used to prevent the addition of /MD and /Zi if the CMake version is new enough to have specific MSVC variables for controlling those flags --- cmake/GtsamBuildTypes.cmake | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cmake/GtsamBuildTypes.cmake b/cmake/GtsamBuildTypes.cmake index 76c04a2f9..0d249ad44 100644 --- a/cmake/GtsamBuildTypes.cmake +++ b/cmake/GtsamBuildTypes.cmake @@ -108,13 +108,15 @@ endif() # Other (non-preprocessor macros) compiler flags: if(MSVC) + set(CMAKE_3_15 $) + set(CMAKE_3_25 $) # Common to all configurations, next for each configuration: set(GTSAM_COMPILE_OPTIONS_PRIVATE_COMMON /W3 /GR /EHsc /MP CACHE STRING "(User editable) Private compiler flags for all configurations.") - set(GTSAM_COMPILE_OPTIONS_PRIVATE_DEBUG /MDd /Zi /Ob0 /Od /RTC1 CACHE STRING "(User editable) Private compiler flags for Debug configuration.") - set(GTSAM_COMPILE_OPTIONS_PRIVATE_RELWITHDEBINFO /MD /O2 /D /Zi /d2Zi+ CACHE STRING "(User editable) Private compiler flags for RelWithDebInfo configuration.") - set(GTSAM_COMPILE_OPTIONS_PRIVATE_RELEASE /MD /O2 CACHE STRING "(User editable) Private compiler flags for Release configuration.") - set(GTSAM_COMPILE_OPTIONS_PRIVATE_PROFILING /MD /O2 /Zi CACHE STRING "(User editable) Private compiler flags for Profiling configuration.") - set(GTSAM_COMPILE_OPTIONS_PRIVATE_TIMING /MD /O2 CACHE STRING "(User editable) Private compiler flags for Timing configuration.") + set(GTSAM_COMPILE_OPTIONS_PRIVATE_DEBUG $<${CMAKE_3_15}:/MDd> $<${CMAKE_3_25}:/Zi> /Ob0 /Od /RTC1 CACHE STRING "(User editable) Private compiler flags for Debug configuration.") + set(GTSAM_COMPILE_OPTIONS_PRIVATE_RELWITHDEBINFO $<${CMAKE_3_15}:/MD> /O2 $<${CMAKE_3_25}:/Zi> CACHE STRING "(User editable) Private compiler flags for RelWithDebInfo configuration.") + set(GTSAM_COMPILE_OPTIONS_PRIVATE_RELEASE $<${CMAKE_3_15}:/MD> /O2 CACHE STRING "(User editable) Private compiler flags for Release configuration.") + set(GTSAM_COMPILE_OPTIONS_PRIVATE_PROFILING $<${CMAKE_3_15}:/MD> /O2 $<${CMAKE_3_25}:/Zi> CACHE STRING "(User editable) Private compiler flags for Profiling configuration.") + set(GTSAM_COMPILE_OPTIONS_PRIVATE_TIMING $<${CMAKE_3_15}:/MD> /O2 CACHE STRING "(User editable) Private compiler flags for Timing configuration.") else() # Common to all configurations, next for each configuration: From 1d5d8f89d8b1b37d65aef220ea40593c10a4aa89 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Jan 2025 08:48:21 -0500 Subject: [PATCH 8/9] Clean up the enabling of C++17 MSVC flag is not needed and the minimum CMake version is higher now --- cmake/GtsamBuildTypes.cmake | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/cmake/GtsamBuildTypes.cmake b/cmake/GtsamBuildTypes.cmake index 0d249ad44..8c86c6f3d 100644 --- a/cmake/GtsamBuildTypes.cmake +++ b/cmake/GtsamBuildTypes.cmake @@ -156,20 +156,9 @@ mark_as_advanced(GTSAM_COMPILE_OPTIONS_PRIVATE_PROFILING) mark_as_advanced(GTSAM_COMPILE_OPTIONS_PRIVATE_TIMING) # Enable C++17: -if (NOT CMAKE_VERSION VERSION_LESS 3.8) - set(GTSAM_COMPILE_FEATURES_PUBLIC "cxx_std_17" CACHE STRING "CMake compile features property for all gtsam targets.") - # See: https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html - set(CMAKE_CXX_EXTENSIONS OFF) - if (MSVC) - # NOTE(jlblanco): seems to be required in addition to the cxx_std_17 above? - list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC /std:c++17) - endif() -else() - # Old cmake versions: - if (NOT MSVC) - list_append_cache(GTSAM_COMPILE_OPTIONS_PUBLIC $<$:-std=c++17>) - endif() -endif() +set(GTSAM_COMPILE_FEATURES_PUBLIC "cxx_std_17" CACHE STRING "CMake compile features property for all gtsam targets.") +# See: https://cmake.org/cmake/help/latest/prop_tgt/CXX_EXTENSIONS.html +set(CMAKE_CXX_EXTENSIONS OFF) # Merge all user-defined flags into the variables that are to be actually used by CMake: foreach(build_type "common" ${GTSAM_CMAKE_CONFIGURATION_TYPES}) From bf4f6f5554c3b190539da5631e6246f146ef8fc6 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Jan 2025 08:54:41 -0500 Subject: [PATCH 9/9] Remove /FORCE:MULTIPLE from CMAKE_STATIC_LINKER_FLAGS It's not a valid flag for static linking --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 453006d41..262f38121 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,6 @@ if(MSVC) set(CMAKE_EXE_LINKER_FLAGS ${MSVC_LINKER_FLAGS}) set(CMAKE_MODULE_LINKER_FLAGS ${MSVC_LINKER_FLAGS}) set(CMAKE_SHARED_LINKER_FLAGS ${MSVC_LINKER_FLAGS}) - set(CMAKE_STATIC_LINKER_FLAGS ${MSVC_LINKER_FLAGS}) endif() set(CMAKE_POSITION_INDEPENDENT_CODE ON)