all: misc cleanups
This commit is contained in:
@@ -42,6 +42,10 @@ macro(upx_set_default_build_type type)
|
||||
if(NOT upx_global_is_multi_config AND NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "${upx_global_default_build_type}" CACHE STRING "Choose the type of build." FORCE)
|
||||
endif()
|
||||
# also enable CMAKE_EXPORT_COMPILE_COMMANDS by default
|
||||
if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# set the default multi-config build type; must be called after project() cmake init
|
||||
@@ -63,6 +67,22 @@ 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)
|
||||
elseif(NOT DEFINED GNU_FRONTEND AND (CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^GNU" OR CMAKE_C_COMPILER_ID MATCHES "(Clang|GNU|LLVM)"))
|
||||
set(GNU_FRONTEND 1)
|
||||
endif()
|
||||
if(NOT DEFINED MINGW AND CMAKE_C_PLATFORM_ID MATCHES "^MinGW")
|
||||
set(MINGW 1)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
# ternary conditional operator
|
||||
@@ -97,7 +117,7 @@ function(upx_make_bool_var result_var_name var_name default_value)
|
||||
set(${result_var_name} "${result}" PARENT_SCOPE) # return value
|
||||
endfunction()
|
||||
|
||||
function(upx_unused_var) # ARGV
|
||||
function(upx_maybe_unused_var) # ARGV
|
||||
foreach(var_name ${ARGV})
|
||||
if(DEFINED ${var_name})
|
||||
set(dummy "${${var_name}}")
|
||||
@@ -339,6 +359,15 @@ endfunction()
|
||||
|
||||
# sanitize a target; note that this may require special run-time support libs from your toolchain
|
||||
function(upx_sanitize_target) # ARGV
|
||||
# default sanitizer for Debug builds
|
||||
if(NOT DEFINED upx_sanitize_flags_debug)
|
||||
set(upx_sanitize_flags_debug -fsanitize=undefined -fsanitize-undefined-trap-on-error -fstack-protector-all)
|
||||
endif()
|
||||
# default sanitizer for Release builds
|
||||
if(NOT DEFINED upx_sanitize_flags_release)
|
||||
set(upx_sanitize_flags_release -fstack-protector)
|
||||
endif()
|
||||
|
||||
foreach(t ${ARGV})
|
||||
if(UPX_CONFIG_DISABLE_SANITIZE)
|
||||
# no-op
|
||||
@@ -356,12 +385,10 @@ function(upx_sanitize_target) # ARGV
|
||||
# unsupported compiler; unreliable/broken sanitize implementation before gcc-8 (May 2018)
|
||||
message(WARNING "WARNING: ignoring SANITIZE for target '${t}'")
|
||||
else()
|
||||
# default sanitizer for Debug builds
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:-fsanitize=undefined -fsanitize-undefined-trap-on-error -fstack-protector-all>)
|
||||
# default sanitizer for Release builds
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:MinSizeRel>:-fstack-protector>)
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:Release>:-fstack-protector>)
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:RelWithDebInfo>:-fstack-protector>)
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:Debug>:${upx_sanitize_flags_debug}>)
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:MinSizeRel>:${upx_sanitize_flags_release}>)
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:Release>:${upx_sanitize_flags_release}>)
|
||||
target_compile_options(${t} PRIVATE $<$<CONFIG:RelWithDebInfo>:${upx_sanitize_flags_release}>)
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
+39
-36
@@ -8,48 +8,51 @@
|
||||
# print some info about the build configuration
|
||||
#***********************************************************************
|
||||
|
||||
get_property(PROPERTY_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
get_property(PROPERTY_TARGET_SUPPORTS_SHARED_LIBS GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
|
||||
function(upx_print_info) # ARGV
|
||||
get_property(PROPERTY_GENERATOR_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
|
||||
get_property(PROPERTY_TARGET_SUPPORTS_SHARED_LIBS GLOBAL PROPERTY TARGET_SUPPORTS_SHARED_LIBS)
|
||||
|
||||
# generator
|
||||
upx_print_var(CMAKE_GENERATOR_TOOLSET CMAKE_GENERATOR_PLATFORM)
|
||||
upx_print_var(PROPERTY_GENERATOR_IS_MULTI_CONFIG)
|
||||
# generator
|
||||
upx_print_var(CMAKE_GENERATOR_TOOLSET CMAKE_GENERATOR_PLATFORM)
|
||||
upx_print_var(PROPERTY_GENERATOR_IS_MULTI_CONFIG)
|
||||
|
||||
# directories
|
||||
if(NOT ",${CMAKE_BINARY_DIR}," STREQUAL ",${CMAKE_CURRENT_BINARY_DIR}," OR NOT ",${CMAKE_SOURCE_DIR}," STREQUAL ",${CMAKE_CURRENT_SOURCE_DIR},")
|
||||
upx_print_var(CMAKE_BINARY_DIR CMAKE_SOURCE_DIR CMAKE_CURRENT_BINARY_DIR CMAKE_CURRENT_SOURCE_DIR)
|
||||
endif()
|
||||
# directories
|
||||
if(NOT ",${CMAKE_BINARY_DIR}," STREQUAL ",${CMAKE_CURRENT_BINARY_DIR}," OR NOT ",${CMAKE_SOURCE_DIR}," STREQUAL ",${CMAKE_CURRENT_SOURCE_DIR},")
|
||||
upx_print_var(CMAKE_BINARY_DIR CMAKE_SOURCE_DIR CMAKE_CURRENT_BINARY_DIR CMAKE_CURRENT_SOURCE_DIR)
|
||||
endif()
|
||||
|
||||
# system
|
||||
upx_print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_SYSTEM_PROCESSOR)
|
||||
upx_print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_SYSTEM_PROCESSOR)
|
||||
upx_print_var(CMAKE_ANDROID_NDK CMAKE_ANDROID_NDK_VERSION CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
|
||||
upx_print_var(CMAKE_APPLE_SILICON_PROCESSOR CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
|
||||
upx_print_var(CMAKE_VS_PLATFORM_TOOLSET CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE CMAKE_VS_PLATFORM_TOOLSET_VERSION)
|
||||
upx_print_var(CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR)
|
||||
# system
|
||||
upx_print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_SYSTEM_PROCESSOR)
|
||||
upx_print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_SYSTEM_PROCESSOR)
|
||||
upx_print_var(CMAKE_ANDROID_NDK CMAKE_ANDROID_NDK_VERSION CMAKE_ANDROID_STANDALONE_TOOLCHAIN)
|
||||
upx_print_var(CMAKE_APPLE_SILICON_PROCESSOR CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
|
||||
upx_print_var(CMAKE_VS_PLATFORM_TOOLSET CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE CMAKE_VS_PLATFORM_TOOLSET_VERSION)
|
||||
upx_print_var(CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR)
|
||||
upx_print_var(CMAKE_SIZEOF_VOID_P)
|
||||
|
||||
# binutils
|
||||
upx_print_var(CMAKE_EXECUTABLE_FORMAT CMAKE_AR CMAKE_RANLIB)
|
||||
# binutils
|
||||
upx_print_var(CMAKE_EXECUTABLE_FORMAT CMAKE_AR CMAKE_RANLIB)
|
||||
|
||||
# compilers
|
||||
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_ID)
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_VERSION)
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT )
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID)
|
||||
upx_print_var(CMAKE_${lang}_PLATFORM_ID)
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_ABI)
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_TARGET)
|
||||
endforeach()
|
||||
# compilers
|
||||
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_ID)
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_VERSION)
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_FRONTEND_VARIANT )
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_ARCHITECTURE_ID)
|
||||
upx_print_var(CMAKE_${lang}_PLATFORM_ID)
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_ABI)
|
||||
upx_print_var(CMAKE_${lang}_COMPILER_TARGET)
|
||||
endforeach()
|
||||
|
||||
# misc
|
||||
upx_print_var(CMAKE_BUILD_WITH_INSTALL_RPATH)
|
||||
upx_print_var(CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_POSITION_INDEPENDENT_CODE)
|
||||
upx_print_var(PROPERTY_TARGET_SUPPORTS_SHARED_LIBS)
|
||||
# misc
|
||||
upx_print_var(CMAKE_BUILD_WITH_INSTALL_RPATH)
|
||||
upx_print_var(CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_POSITION_INDEPENDENT_CODE)
|
||||
upx_print_var(PROPERTY_TARGET_SUPPORTS_SHARED_LIBS)
|
||||
|
||||
# shortcuts
|
||||
upx_print_var(APPLE CLANG CYGWIN GNU_FRONTEND GNUC MINGW MSVC MSVC_FRONTEND MSVC_IDE MSVC_TOOLSET_VERSION MSVC_VERSION MSYS UNIX WIN32 WIN64)
|
||||
# shortcuts
|
||||
upx_print_var(APPLE CLANG CYGWIN GNU_FRONTEND GNUC MINGW MSVC MSVC_FRONTEND MSVC_IDE MSVC_TOOLSET_VERSION MSVC_VERSION MSYS UNIX WIN32 WIN64)
|
||||
endfunction()
|
||||
|
||||
# vim:set ft=cmake ts=4 sw=4 tw=0 et:
|
||||
|
||||
@@ -137,7 +137,7 @@ if(NOT UPX_CONFIG_DISABLE_EXHAUSTIVE_TESTS)
|
||||
endif()
|
||||
endforeach()
|
||||
endforeach()
|
||||
endif () # UPX_CONFIG_DISABLE_EXHAUSTIVE_TESTS
|
||||
endif() # UPX_CONFIG_DISABLE_EXHAUSTIVE_TESTS
|
||||
|
||||
# clean up
|
||||
set(emu "")
|
||||
|
||||
+16
-10
@@ -70,34 +70,37 @@ build/extra/clang-static/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/clang-static/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/clang-static/%: export CC = clang -static
|
||||
build/extra/clang-static/%: export CXX = clang++ -static
|
||||
build/extra/clang-static/%: export UPX_CONFIG_DISABLE_SHARED_LIBS = ON
|
||||
|
||||
# force building with clang/clang++ -static-pie
|
||||
build/extra/clang-static-pie/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/clang-static-pie/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/clang-static-pie/%: export CC = clang -static-pie -fPIE -Wno-unused-command-line-argument
|
||||
build/extra/clang-static-pie/%: export CXX = clang++ -static-pie -fPIE -Wno-unused-command-line-argument
|
||||
build/extra/clang-static-pie/%: export UPX_CONFIG_DISABLE_SHARED_LIBS = ON
|
||||
|
||||
# force building with clang/clang++ -static -flto
|
||||
build/extra/clang-static-lto/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/clang-static-lto/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/clang-static-lto/%: export CC = clang -static -flto
|
||||
build/extra/clang-static-lto/%: export CXX = clang++ -static -flto
|
||||
build/extra/clang-static-lto/%: export UPX_CONFIG_DISABLE_SHARED_LIBS = ON
|
||||
|
||||
# force building with clang/clang++ C++20 (and C17)
|
||||
build/extra/clang-std-cxx20/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/clang-std-cxx20/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/clang-std-cxx20/%: export CC = clang -std=gnu17
|
||||
build/extra/clang-std-cxx20/%: export CXX = clang++ -std=gnu++20
|
||||
build/extra/clang-std-cxx20/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||
build/extra/clang-std-cxx20/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||
build/extra/clang-std-cxx20/%: export UPX_CONFIG_DISABLE_C_STANDARD = ON
|
||||
build/extra/clang-std-cxx20/%: export UPX_CONFIG_DISABLE_CXX_STANDARD = ON
|
||||
|
||||
# force building with clang/clang++ C++23 (and C23)
|
||||
build/extra/clang-std-cxx23/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/clang-std-cxx23/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/clang-std-cxx23/%: export CC = clang -std=gnu2x -Wno-constant-logical-operand
|
||||
build/extra/clang-std-cxx23/%: export CXX = clang++ -std=gnu++2b
|
||||
build/extra/clang-std-cxx23/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||
build/extra/clang-std-cxx23/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||
build/extra/clang-std-cxx23/%: export UPX_CONFIG_DISABLE_C_STANDARD = ON
|
||||
build/extra/clang-std-cxx23/%: export UPX_CONFIG_DISABLE_CXX_STANDARD = ON
|
||||
|
||||
# force building with gcc/g++
|
||||
build/extra/gcc/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
@@ -134,42 +137,45 @@ build/extra/gcc-static/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/gcc-static/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/gcc-static/%: export CC = gcc -static
|
||||
build/extra/gcc-static/%: export CXX = g++ -static
|
||||
build/extra/gcc-static/%: export UPX_CONFIG_DISABLE_SHARED_LIBS = ON
|
||||
|
||||
# force building with gcc/g++ -static-pie
|
||||
build/extra/gcc-static-pie/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/gcc-static-pie/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/gcc-static-pie/%: export CC = gcc -static-pie -fPIE
|
||||
build/extra/gcc-static-pie/%: export CXX = g++ -static-pie -fPIE
|
||||
build/extra/gcc-static-pie/%: export UPX_CONFIG_DISABLE_SHARED_LIBS = ON
|
||||
|
||||
# force building with gcc/g++ -static -flto
|
||||
build/extra/gcc-static-lto/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/gcc-static-lto/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/gcc-static-lto/%: export CC = gcc -static -flto
|
||||
build/extra/gcc-static-lto/%: export CXX = g++ -static -flto
|
||||
build/extra/gcc-static-lto/%: export UPX_CONFIG_DISABLE_SHARED_LIBS = ON
|
||||
|
||||
# force building with gcc/g++ C++20 (and C17)
|
||||
build/extra/gcc-std-cxx20/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/gcc-std-cxx20/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/gcc-std-cxx20/%: export CC = gcc -std=gnu17
|
||||
build/extra/gcc-std-cxx20/%: export CXX = g++ -std=gnu++20
|
||||
build/extra/gcc-std-cxx20/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||
build/extra/gcc-std-cxx20/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||
build/extra/gcc-std-cxx20/%: export UPX_CONFIG_DISABLE_C_STANDARD = ON
|
||||
build/extra/gcc-std-cxx20/%: export UPX_CONFIG_DISABLE_CXX_STANDARD = ON
|
||||
|
||||
# force building with gcc/g++ C++23 (and C23)
|
||||
build/extra/gcc-std-cxx23/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/gcc-std-cxx23/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/gcc-std-cxx23/%: export CC = gcc -std=gnu2x
|
||||
build/extra/gcc-std-cxx23/%: export CXX = g++ -std=gnu++2b
|
||||
build/extra/gcc-std-cxx23/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||
build/extra/gcc-std-cxx23/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||
build/extra/gcc-std-cxx23/%: export UPX_CONFIG_DISABLE_C_STANDARD = ON
|
||||
build/extra/gcc-std-cxx23/%: export UPX_CONFIG_DISABLE_CXX_STANDARD = ON
|
||||
|
||||
# force building with gcc/g++ C++26 (EXPERIMENTAL; need gcc-14)
|
||||
build/extra/gcc-std-cxx26/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
build/extra/gcc-std-cxx26/release: PHONY; $(call run_config_and_build,$@,Release)
|
||||
build/extra/gcc-std-cxx26/%: export CC = gcc -std=gnu23
|
||||
build/extra/gcc-std-cxx26/%: export CXX = g++ -std=gnu++26
|
||||
build/extra/gcc-std-cxx26/%: export UPX_CONFIG_DISABLE_C_STANDARD=ON
|
||||
build/extra/gcc-std-cxx26/%: export UPX_CONFIG_DISABLE_CXX_STANDARD=ON
|
||||
build/extra/gcc-std-cxx26/%: export UPX_CONFIG_DISABLE_C_STANDARD = ON
|
||||
build/extra/gcc-std-cxx26/%: export UPX_CONFIG_DISABLE_CXX_STANDARD = ON
|
||||
|
||||
# cross compiler: Linux glibc aarch64-linux-gnu (arm64)
|
||||
build/extra/cross-linux-gnu-aarch64/debug: PHONY; $(call run_config_and_build,$@,Debug)
|
||||
|
||||
@@ -6,8 +6,9 @@ argv0=$0; argv0abs=$(readlink -fn "$argv0"); argv0dir=$(dirname "$argv0abs")
|
||||
#
|
||||
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
||||
#
|
||||
# mimic running "ctest", i.e. the "test" section of CMakeLists.txt; does not redirect stdout
|
||||
# (allows freely setting $upx_exe_runner, while CMake is restricted to configure-time settings)
|
||||
# mimic running "ctest", i.e. the "test" section of CMakeLists.txt
|
||||
# - does not redirect stdout
|
||||
# - allows freely setting $upx_exe_runner, while CMake is restricted to configure-time settings
|
||||
#
|
||||
# requires:
|
||||
# $upx_exe (required, but with convenience fallback "./upx")
|
||||
@@ -48,7 +49,7 @@ if ! "${run_upx[@]}" --help >/dev/null; then echo "UPX-ERROR: FATAL: upx --help
|
||||
#***********************************************************************
|
||||
# see CMakeLists.txt
|
||||
#
|
||||
# IDEA: create a Makefile and use "make -j" so that these tests can
|
||||
# IDEA: create a Makefile and use "make -j8" so that these tests can
|
||||
# run in parallel much like "ctest --parallel 8"
|
||||
#***********************************************************************
|
||||
|
||||
|
||||
Reference in New Issue
Block a user