Merge pull request #19725 from chennes/cmakeUpdates2025
CMake: Clean up policies
This commit is contained in:
@@ -41,11 +41,11 @@ inputs:
|
||||
libpackdownloadurl:
|
||||
description: "URL where to download libpack"
|
||||
required: false
|
||||
default: https://github.com/FreeCAD/FreeCAD-LibPack/releases/download/3.0.0RC4/LibPack-1.0.0-v3.0.0RC4-Release.7z
|
||||
default: https://github.com/FreeCAD/FreeCAD-LibPack/releases/download/3.1.0/LibPack-1.1.0-v3.1.0-Release.7z
|
||||
libpackname:
|
||||
description: "Libpack name (once downloaded)"
|
||||
required: false
|
||||
default: LibPack-1.0.0-v3.0.0RC4-Release
|
||||
default: LibPack-1.1.0-v3.1.0-Release
|
||||
|
||||
runs:
|
||||
using: "composite"
|
||||
|
||||
@@ -1,26 +1,42 @@
|
||||
# As of January 2023 we require CMake 3.16.3
|
||||
# see https://forum.freecad.org/viewtopic.php?f=10&t=72173
|
||||
# for further info why
|
||||
cmake_minimum_required(VERSION 3.16.3 FATAL_ERROR)
|
||||
# As of February 2025 we require CMake 3.22.0
|
||||
cmake_minimum_required(VERSION 3.22.0 FATAL_ERROR)
|
||||
|
||||
|
||||
# As of cMake 3.27, find_package() will look for both case-sensitive and all-uppercase versions
|
||||
# of the package. This seems to affect FLANN as included by Pixi
|
||||
if(POLICY CMP0144)
|
||||
cmake_policy(SET CMP0144 NEW)
|
||||
endif()
|
||||
|
||||
# FindPythonInterp and FindPythonLibs modules are deprecated, but are still in use by
|
||||
# all versions of Shiboken2. This policy must be kept at OLD until Shiboken2 is no longer
|
||||
# supported
|
||||
if(POLICY CMP0148)
|
||||
cmake_policy(SET CMP0148 OLD)
|
||||
endif()
|
||||
|
||||
# The exec_program command was deprecated in cMake 3.0, and policy CMP0153 was added in cMake
|
||||
# 3.28 to control whether this gives a warning (the OLD behavior) or a fatal error (NEW)
|
||||
if(POLICY CMP0153)
|
||||
cmake_policy(SET CMP0153 NEW)
|
||||
endif()
|
||||
|
||||
# Suppress 'FindBoost module is removed' warning. Will use BoostConfig.cmake instead
|
||||
if(POLICY CMP0167)
|
||||
cmake_policy(SET CMP0167 NEW)
|
||||
endif()
|
||||
|
||||
# policy CMP0072 was introduced with CMake 3.11
|
||||
# relates to FindOpenGL module
|
||||
# and cache variables OPENGL_gl_LIBRARY, OPENGL_glu_LIBRARY
|
||||
if (POLICY CMP0072)
|
||||
set(OpenGL_GL_PREFERENCE LEGACY)
|
||||
endif(POLICY CMP0072)
|
||||
|
||||
# FindPythonInterp and FindPythonLibs modules are deprecated.
|
||||
# Currently, they are still used by shiboken's CMake files
|
||||
if (POLICY CMP0148)
|
||||
cmake_policy(SET CMP0148 OLD)
|
||||
# As of cMake 3.31 add_custom_command() rejects invalid arguments
|
||||
if(POLICY CMP0175)
|
||||
cmake_policy(SET CMP0175 NEW)
|
||||
endif()
|
||||
|
||||
# Added in cMake 3.31, enforce normalization of all DESTINATION paths given to install()
|
||||
if(POLICY CMP0177)
|
||||
cmake_policy(SET CMP0177 NEW)
|
||||
endif()
|
||||
|
||||
|
||||
option(FREECAD_USE_CCACHE "Auto detect and use ccache during compilation" ON)
|
||||
|
||||
if(FREECAD_USE_CCACHE)
|
||||
|
||||
@@ -5,18 +5,22 @@
|
||||
|
||||
find_package(PySide6 CONFIG QUIET)
|
||||
if(NOT PySide6_FOUND)
|
||||
if(NOT PySide6_INCLUDE_DIR AND TARGET PySide6::pyside6)
|
||||
get_property(PySide6_INCLUDE_DIR TARGET PySide6::pyside6 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
if(NOT PySide6_INCLUDE_DIRS AND TARGET PySide6::pyside6)
|
||||
get_property(PySide6_INCLUDE_DIRS TARGET PySide6::pyside6 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
endif()
|
||||
|
||||
if(NOT PySide6_INCLUDE_DIR)
|
||||
if(NOT PySide6_INCLUDE_DIRS)
|
||||
find_pip_package(PySide6)
|
||||
if (PySide6_FOUND)
|
||||
set(PYSIDE_INCLUDE_DIR ${PySide6_INCLUDE_DIRS} CACHE INTERNAL "")
|
||||
set(PYSIDE_LIBRARY ${PySide6_LIBRARIES} CACHE INTERNAL "")
|
||||
set(PYSIDE_FOUND TRUE CACHE BOOL OFF)
|
||||
set(PYSIDE_MAJOR_VERSION 6 CACHE INTERNAL 6)
|
||||
endif()
|
||||
else()
|
||||
set(PySide6_FOUND ON)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
|
||||
# Also provide the old-style variables so we don't have to update everything yet
|
||||
if (PySide6_FOUND)
|
||||
set(PYSIDE_INCLUDE_DIR ${PySide6_INCLUDE_DIRS})
|
||||
set(PYSIDE_LIBRARY ${PySide6_LIBRARIES})
|
||||
set(PYSIDE_FOUND TRUE)
|
||||
set(PYSIDE_MAJOR_VERSION 6)
|
||||
endif()
|
||||
|
||||
@@ -11,18 +11,18 @@ if(NOT Shiboken6_FOUND)
|
||||
if(NOT Shiboken6_INCLUDE_DIR)
|
||||
find_pip_package(Shiboken6)
|
||||
if (Shiboken6_FOUND)
|
||||
set(SHIBOKEN_LIBRARY ${Shiboken6_LIBRARIES} CACHE INTERNAL "")
|
||||
set(SHIBOKEN_MAJOR_VERSION 6 CACHE INTERNAL 6)
|
||||
set(SHIBOKEN_FOUND ON CACHE BOOL OFF)
|
||||
set(SHIBOKEN_LIBRARY ${Shiboken6_LIBRARIES})
|
||||
set(SHIBOKEN_MAJOR_VERSION 6)
|
||||
set(SHIBOKEN_FOUND ON)
|
||||
endif()
|
||||
# The include directory we actually want is part of shiboken6-generator
|
||||
find_pip_package(shiboken6_generator)
|
||||
if (shiboken6_generator_FOUND)
|
||||
set(SHIBOKEN_INCLUDE_DIR ${shiboken6_generator_INCLUDE_DIRS} CACHE PATH "")
|
||||
set(SHIBOKEN_INCLUDE_DIR ${shiboken6_generator_INCLUDE_DIRS})
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
set(SHIBOKEN_INCLUDE_DIR ${Shiboken6_INCLUDE_DIRS} CACHE PATH "")
|
||||
set(SHIBOKEN_LIBRARY ${Shiboken6_LIBRARIES} CACHE INTERNAL "")
|
||||
set(SHIBOKEN_FOUND ON CACHE BOOL OFF)
|
||||
set(SHIBOKEN_INCLUDE_DIR ${Shiboken6_INCLUDE_DIRS})
|
||||
set(SHIBOKEN_LIBRARY ${Shiboken6_LIBRARIES})
|
||||
set(SHIBOKEN_FOUND ON)
|
||||
endif()
|
||||
|
||||
@@ -9,14 +9,6 @@ macro(CompilerChecksAndSetups)
|
||||
|
||||
# ================================================================================
|
||||
|
||||
# Needed for boost1.69
|
||||
# Avoid that Python (pyerrors.h) defines snprintf and vsnprintf
|
||||
if (MSVC AND NOT MSVC_VERSION VERSION_LESS 1900)
|
||||
add_definitions(-DHAVE_SNPRINTF)
|
||||
elseif (MINGW)
|
||||
add_definitions(-DHAVE_SNPRINTF)
|
||||
endif()
|
||||
|
||||
# Allow developers to use Boost < 1.74
|
||||
if (NOT BOOST_MIN_VERSION)
|
||||
set(BOOST_MIN_VERSION 1.74)
|
||||
@@ -28,26 +20,24 @@ macro(CompilerChecksAndSetups)
|
||||
OUTPUT_VARIABLE CMAKE_CXX_COMPILER_VERSION)
|
||||
endif(CMAKE_COMPILER_IS_GNUCXX AND NOT CMAKE_CXX_COMPILER_VERSION)
|
||||
|
||||
# Enabled C++17 for Freecad 0.20 and later
|
||||
set(BUILD_ENABLE_CXX_STD "C++17" CACHE STRING "Enable C++ standard")
|
||||
set_property(CACHE BUILD_ENABLE_CXX_STD PROPERTY STRINGS
|
||||
"C++17"
|
||||
"C++20"
|
||||
)
|
||||
# Enabled C++20 for Freecad 1.1 and later
|
||||
set(BUILD_ENABLE_CXX_STD "C++20" CACHE STRING "Enable C++ standard")
|
||||
set_property(CACHE BUILD_ENABLE_CXX_STD PROPERTY STRINGS
|
||||
"C++20"
|
||||
"C++23"
|
||||
)
|
||||
|
||||
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.3)
|
||||
message(FATAL_ERROR "FreeCAD 0.20 and later requires C++17. G++ must be 7.3 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
elseif(CMAKE_COMPILER_IS_CLANGXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0)
|
||||
message(FATAL_ERROR "FreeCAD 0.20 and later requires C++17. Clang must be 6.0 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
endif()
|
||||
if (CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 11.2)
|
||||
message(FATAL_ERROR "FreeCAD 1.1 and later requires C++20. G++ must be 11.2 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
elseif(CMAKE_COMPILER_IS_CLANGXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14.0)
|
||||
message(FATAL_ERROR "FreeCAD 1.1 and later requires C++20. Clang must be 14.0 or later, the used version is ${CMAKE_CXX_COMPILER_VERSION}")
|
||||
endif()
|
||||
|
||||
# Escape the two plus chars as otherwise cmake complains about invalid regex
|
||||
if(${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+23")
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
elseif(${BUILD_ENABLE_CXX_STD} MATCHES "C\\+\\+20")
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
else()#Enabled C++17
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
endif()
|
||||
|
||||
# Log the compiler and version
|
||||
@@ -99,15 +89,15 @@ macro(CompilerChecksAndSetups)
|
||||
#
|
||||
# https://en.wikipedia.org/wiki/Xcode#Latest_versions
|
||||
if (APPLE)
|
||||
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template")
|
||||
endif()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template")
|
||||
add_definitions(-DGL_SILENCE_DEPRECATION)
|
||||
elseif (UNIX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-undefined-var-template")
|
||||
endif()
|
||||
|
||||
# older boost.preprocessor turn off variadics for clang
|
||||
# boost.preprocessor 1.74 and earlier turns off variadics for clang regardless of version, even though they
|
||||
# work in all versions of clang that we support. Manually force variadic macro support until our oldest
|
||||
# supported version of boost is 1.75 or higher.
|
||||
add_definitions(-DBOOST_PP_VARIADICS=1)
|
||||
message(STATUS "Force BOOST_PP_VARIADICS=1 for clang")
|
||||
endif()
|
||||
|
||||
@@ -14,7 +14,7 @@ macro(PrintFinalReport)
|
||||
|
||||
# just a value
|
||||
macro(value)
|
||||
unset(val)
|
||||
unset(val)
|
||||
set(name ${ARGV0})
|
||||
if(${name})
|
||||
set(val ${${name}}) # name has a value
|
||||
|
||||
@@ -59,15 +59,18 @@ macro(SetupShibokenAndPyside)
|
||||
|
||||
find_package(PySide${PYSIDE_MAJOR_VERSION} QUIET)
|
||||
|
||||
if(NOT PYSIDE_INCLUDE_DIR AND TARGET PySide${PYSIDE_MAJOR_VERSION}::pyside${PYSIDE_MAJOR_VERSION})
|
||||
get_property(PYSIDE_INCLUDE_DIR TARGET PySide${PYSIDE_MAJOR_VERSION}::pyside${PYSIDE_MAJOR_VERSION} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
endif(NOT PYSIDE_INCLUDE_DIR AND TARGET PySide${PYSIDE_MAJOR_VERSION}::pyside${PYSIDE_MAJOR_VERSION})
|
||||
if(${PYSIDE_MAJOR_VERSION} EQUAL 5)
|
||||
# Our internal FindPySide6.cmake file already provides these for PySide6
|
||||
if(NOT PYSIDE_INCLUDE_DIR AND TARGET PySide${PYSIDE_MAJOR_VERSION}::pyside${PYSIDE_MAJOR_VERSION})
|
||||
get_property(PYSIDE_INCLUDE_DIR TARGET PySide${PYSIDE_MAJOR_VERSION}::pyside${PYSIDE_MAJOR_VERSION} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
endif(NOT PYSIDE_INCLUDE_DIR AND TARGET PySide${PYSIDE_MAJOR_VERSION}::pyside${PYSIDE_MAJOR_VERSION})
|
||||
|
||||
if(NOT PYSIDE_INCLUDE_DIR)
|
||||
find_pip_package(PySide${PYSIDE_MAJOR_VERSION})
|
||||
if (PySide${PYSIDE_MAJOR_VERSION}_FOUND)
|
||||
set(PYSIDE_INCLUDE_DIR ${PySide${PYSIDE_MAJOR_VERSION}_INCLUDE_DIRS})
|
||||
set(PYSIDE_LIBRARY ${PySide${PYSIDE_MAJOR_VERSION}_LIBRARIES})
|
||||
if(NOT PYSIDE_INCLUDE_DIR)
|
||||
find_pip_package(PySide${PYSIDE_MAJOR_VERSION})
|
||||
if (PySide${PYSIDE_MAJOR_VERSION}_FOUND)
|
||||
set(PYSIDE_INCLUDE_DIR ${PySide${PYSIDE_MAJOR_VERSION}_INCLUDE_DIRS})
|
||||
set(PYSIDE_LIBRARY ${PySide${PYSIDE_MAJOR_VERSION}_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
@@ -266,6 +266,8 @@ ENDMACRO(SET_PYTHON_PREFIX_SUFFIX)
|
||||
# Locate the include directory for a pip-installed package -- uses pip show to find the base pip
|
||||
# install directory, and then appends the package name and "/include" to the end
|
||||
macro(find_pip_package PACKAGE)
|
||||
unset(${PACKAGE}_FOUND) # Remove from local scope
|
||||
unset(${PACKAGE}_FOUND CACHE) # Remove from CMake cache (if it exists)
|
||||
execute_process(
|
||||
COMMAND ${Python3_EXECUTABLE} -m pip show ${PACKAGE}
|
||||
RESULT_VARIABLE FAILURE
|
||||
@@ -300,15 +302,18 @@ macro(find_pip_package PACKAGE)
|
||||
file(GLOB OPT_LIBRARIES "${PIP_PACKAGE_LOCATION}/${PIP_PACKAGE_NAME}/*${PIP_LIB_NAME}*.so.*")
|
||||
endif()
|
||||
if (OPT_LIBRARIES AND DEBUG_LIBRARIES)
|
||||
set(${PACKAGE}_LIBRARIES optimized ${OPT_LIBRARIES} debug ${DEBUG_LIBRARIES} CACHE PATH "")
|
||||
set(${PACKAGE}_LIBRARIES optimized ${OPT_LIBRARIES} debug ${DEBUG_LIBRARIES} CACHE PATH "Location of the ${PACKAGE} libraries")
|
||||
elseif(OPT_LIBRARIES)
|
||||
set(${PACKAGE}_LIBRARIES ${OPT_LIBRARIES} CACHE PATH "")
|
||||
set(${PACKAGE}_LIBRARIES ${OPT_LIBRARIES} CACHE PATH "Location of the ${PACKAGE} optimized libraries")
|
||||
elseif(DEBUG_LIBRARIES)
|
||||
set(${PACKAGE}_LIBRARIES ${DEBUG_LIBRARIES} CACHE PATH "")
|
||||
set(${PACKAGE}_LIBRARIES ${DEBUG_LIBRARIES} CACHE PATH "Location of the ${PACKAGE} debug libraries")
|
||||
endif()
|
||||
set(${PACKAGE}_INCLUDE_DIRS ${INCLUDE_DIR} CACHE PATH "")
|
||||
set(${PACKAGE}_FOUND ON CACHE BOOL OFF)
|
||||
set(${PACKAGE}_INCLUDE_DIRS ${INCLUDE_DIR} CACHE PATH "Location of the ${PACKAGE} includes")
|
||||
set(${PACKAGE}_FOUND ON)
|
||||
message(STATUS "Found pip-installed ${PACKAGE} in ${PIP_PACKAGE_LOCATION}/${PIP_PACKAGE_NAME}")
|
||||
if(${PACKAGE}_INCLUDE_DIRS)
|
||||
message(STATUS " --> with includes in ${${PACKAGE}_INCLUDE_DIRS}")
|
||||
endif()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
@@ -83,15 +83,16 @@ bool MacroFile::commit()
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
|
||||
str.setCodec("UTF-8");
|
||||
#endif
|
||||
QStringList import;
|
||||
import << QStringLiteral("import FreeCAD");
|
||||
QStringList importCommand;
|
||||
importCommand << QStringLiteral("import FreeCAD");
|
||||
QStringList body;
|
||||
|
||||
for (const auto& it : std::as_const(this->macroInProgress)) {
|
||||
if (it.startsWith(QLatin1String("import ")) ||
|
||||
it.startsWith(QLatin1String("#import "))) {
|
||||
if (import.indexOf(it) == -1)
|
||||
import.push_back(it);
|
||||
if (importCommand.indexOf(it) == -1) {
|
||||
importCommand.push_back(it);
|
||||
}
|
||||
}
|
||||
else {
|
||||
body.push_back(it);
|
||||
@@ -110,7 +111,7 @@ bool MacroFile::commit()
|
||||
|
||||
// write the data to the text file
|
||||
str << header;
|
||||
for (const auto& it : std::as_const(import)) {
|
||||
for (const auto& it : std::as_const(importCommand)) {
|
||||
str << it << QLatin1Char('\n');
|
||||
}
|
||||
str << QLatin1Char('\n');
|
||||
|
||||
@@ -124,20 +124,6 @@ if (FREECAD_WARN_ERROR)
|
||||
target_compile_warn_error(Path)
|
||||
endif()
|
||||
|
||||
# Boost >= 1.75.0
|
||||
if(NOT ${Boost_VERSION} LESS 107500)
|
||||
set_target_properties(Path PROPERTIES CXX_STANDARD_REQUIRED ON)
|
||||
set_target_properties(Path PROPERTIES CXX_STANDARD 14)
|
||||
|
||||
# Suppress -Wc++17-extensions when using OCCT 7.5 or newer
|
||||
if (MINGW AND CMAKE_COMPILER_IS_CLANGXX)
|
||||
unset(_flag_found CACHE)
|
||||
check_cxx_compiler_flag("-Wno-c++17-extensions" _flag_found)
|
||||
if (_flag_found)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++17-extensions")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(FREECAD_USE_PCH)
|
||||
add_definitions(-D_PreComp_)
|
||||
|
||||
@@ -413,8 +413,6 @@ endif ()
|
||||
|
||||
add_library(Mesh SHARED ${Core_SRCS} ${WildMagic4_SRCS} ${Mesh_SRCS})
|
||||
target_link_libraries(Mesh ${Mesh_LIBS})
|
||||
set_target_properties(Mesh PROPERTIES CXX_STANDARD_REQUIRED ON)
|
||||
set_target_properties(Mesh PROPERTIES CXX_STANDARD 17)
|
||||
if (FREECAD_WARN_ERROR)
|
||||
target_compile_warn_error(Mesh)
|
||||
endif()
|
||||
|
||||
Reference in New Issue
Block a user