cmake update

This commit is contained in:
Markus F.X.J. Oberhumer 2024-07-31 18:56:32 +02:00
parent ba969fb9f2
commit b4db17ab3c
4 changed files with 38 additions and 11 deletions

View File

@ -133,8 +133,10 @@ endif()
# CMake init
upx_set_default_build_type(Release) # default is CMAKE_BUILD_TYPE=Release
upx_set_default_rpath()
project(upx VERSION "${UPX_VERSION_STRING}" LANGUAGES C CXX)
upx_apply_build_type()
upx_apply_rpath()
if(DEFINED UPX_CONFIG_CMAKE_EXECUTABLE_SUFFIX)
set(CMAKE_EXECUTABLE_SUFFIX "${UPX_CONFIG_CMAKE_EXECUTABLE_SUFFIX}")

View File

@ -35,7 +35,7 @@ macro(upx_disallow_in_source_build)
endif()
endmacro()
# set the default build type; must be called before project() cmake init
# set the default build type; must be called BEFORE project() cmake init
macro(upx_set_default_build_type type)
set(upx_global_default_build_type "${type}")
get_property(upx_global_is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
@ -54,7 +54,7 @@ macro(upx_set_default_build_type type)
endif()
endmacro()
# set the default multi-config build type; must be called after project() cmake init
# set the default multi-config build type; must be called AFTER project() cmake init
macro(upx_apply_build_type)
if(upx_global_is_multi_config)
set(c "${CMAKE_CONFIGURATION_TYPES}")
@ -73,13 +73,6 @@ macro(upx_apply_build_type)
set(CMAKE_TRY_COMPILE_CONFIGURATION "${upx_global_default_build_type}")
endif()
endif()
# handle CMAKE_BUILD_WITH_INSTALL_RPATH
if(NOT DEFINED CMAKE_BUILD_WITH_INSTALL_RPATH)
if(CMAKE_GENERATOR MATCHES "Ninja" AND NOT CMAKE_EXECUTABLE_FORMAT MATCHES "^ELF")
# info: needed by Ninja generator unless on an ELF-based or XCOFF-based platform
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
endif()
endif()
# and also set MSVC_FRONTEND, GNU_FRONTEND and MINGW
if(NOT DEFINED MSVC_FRONTEND AND (MSVC OR CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC"))
set(MSVC_FRONTEND 1)
@ -91,6 +84,24 @@ macro(upx_apply_build_type)
endif()
endmacro()
# handle the default RPATH settings; must be called BEFORE project() cmake init
macro(upx_set_default_rpath)
endmacro()
# handle the default RPATH settings; must be called AFTER project() cmake init
macro(upx_apply_rpath)
if(NOT DEFINED CMAKE_BUILD_WITH_INSTALL_RPATH)
if(APPLE) # macOS
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
set(CMAKE_BUILD_WITH_INSTALL_NAME_DIR ON)
set(CMAKE_INSTALL_NAME_DIR "@rpath")
elseif(CMAKE_GENERATOR MATCHES "Ninja" AND NOT CMAKE_EXECUTABLE_FORMAT MATCHES "^ELF")
# info: needed by Ninja generator unless on an ELF-based or XCOFF-based platform
set(CMAKE_BUILD_WITH_INSTALL_RPATH ON)
endif()
endif()
endmacro()
# ternary conditional operator
macro(upx_ternary result_var_name condition true_value false_value)
if(${condition})
@ -394,6 +405,15 @@ function(upx_sanitize_target) # ARGV
target_compile_options(${t} PRIVATE $<$<CONFIG:MinSizeRel>:${UPX_CONFIG_SANITIZE_FLAGS_RELEASE}>)
target_compile_options(${t} PRIVATE $<$<CONFIG:Release>:${UPX_CONFIG_SANITIZE_FLAGS_RELEASE}>)
target_compile_options(${t} PRIVATE $<$<CONFIG:RelWithDebInfo>:${UPX_CONFIG_SANITIZE_FLAGS_RELEASE}>)
get_target_property(target_type ${t} TYPE)
if(NOT ",${target_type}," STREQUAL ",STATIC_LIBRARY,")
if(${CMAKE_VERSION} VERSION_GREATER "3.12.99")
target_link_options(${t} PRIVATE $<$<CONFIG:Debug>:${UPX_CONFIG_SANITIZE_FLAGS_DEBUG}>)
target_link_options(${t} PRIVATE $<$<CONFIG:MinSizeRel>:${UPX_CONFIG_SANITIZE_FLAGS_RELEASE}>)
target_link_options(${t} PRIVATE $<$<CONFIG:Release>:${UPX_CONFIG_SANITIZE_FLAGS_RELEASE}>)
target_link_options(${t} PRIVATE $<$<CONFIG:RelWithDebInfo>:${UPX_CONFIG_SANITIZE_FLAGS_RELEASE}>)
endif() # CMAKE_VERSION
endif() # target_type
endif()
endforeach()
endfunction()

View File

@ -38,6 +38,7 @@ function(upx_print_info) # ARGV
foreach(lang IN ITEMS ASM C CXX)
upx_print_var(CMAKE_${lang}_COMPILER_LAUNCHER)
upx_print_var(CMAKE_${lang}_COMPILER)
upx_print_var(CMAKE_${lang}_COMPILER_ARG1)
upx_print_var(CMAKE_${lang}_COMPILER_ID)
upx_print_var(CMAKE_${lang}_SIMULATE_ID)
upx_print_var(CMAKE_${lang}_COMPILER_VERSION)

View File

@ -55,14 +55,18 @@
#endif
#endif
#if defined(__FAST_MATH__) && defined(__clang__) && (__clang_major__ + 0 >= 6)
#if defined(__FAST_MATH__) && defined(__clang__) && (__clang_major__ + 0 > 0)
#if __clang_major__ >= 6
// warning: comparison with NaN always evaluates to false in fast floating point modes
#pragma clang diagnostic ignored "-Wtautological-constant-compare"
#endif
#if defined(__FAST_MATH__) && defined(__clang__) && (__clang_major__ + 0 >= 18)
#if defined(__has_warning)
#if __has_warning("-Wnan-infinity-disabled")
// warning: use of NaN is undefined behavior due to the currently enabled floating-point options
#pragma clang diagnostic ignored "-Wnan-infinity-disabled"
#endif
#endif
#endif
#include <doctest/doctest/parts/doctest.cpp>