2023-06-15 17:42:54 +00:00
|
|
|
#
|
2023-06-24 23:55:06 +00:00
|
|
|
# UPX "CMake" build file; see https://cmake.org/
|
2023-06-15 17:42:54 +00:00
|
|
|
# Copyright (C) Markus Franz Xaver Johannes Oberhumer
|
|
|
|
#
|
|
|
|
|
2023-06-24 23:55:06 +00:00
|
|
|
# Build requirements:
|
|
|
|
# A C++ compiler that fully implements C++17: clang-5, gcc-8 or msvc-2019-16.11
|
|
|
|
# (older or other compilers may work but are unsupported, use at your own risk)
|
|
|
|
|
2023-11-21 19:29:54 +00:00
|
|
|
# Sections of this CMakeLists.txt:
|
|
|
|
# - options
|
|
|
|
# - init
|
|
|
|
# - common compilation flags
|
|
|
|
# - targets
|
|
|
|
# - target compilation flags
|
|
|
|
# - test
|
|
|
|
# - install
|
|
|
|
# - print summary
|
|
|
|
|
2023-06-23 12:13:08 +00:00
|
|
|
# CMake version check; using a somewhat current CMake version is highly recommended
|
2023-12-19 15:11:23 +00:00
|
|
|
file(REMOVE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/.upx_cmake_config_done.txt")
|
2023-06-24 23:55:06 +00:00
|
|
|
if(DEFINED UPX_CONFIG_CMAKE_MINIMUM_REQUIRED_VERSION)
|
2023-06-23 12:13:08 +00:00
|
|
|
cmake_minimum_required(VERSION "${UPX_CONFIG_CMAKE_MINIMUM_REQUIRED_VERSION}" FATAL_ERROR)
|
2023-06-24 23:55:06 +00:00
|
|
|
else()
|
2023-10-29 14:12:33 +00:00
|
|
|
cmake_minimum_required(VERSION "3.8" FATAL_ERROR) # CMake >= 3.8 is needed for CXX_STANDARD 17
|
2023-06-23 12:13:08 +00:00
|
|
|
endif()
|
2022-08-17 12:29:29 +00:00
|
|
|
|
2024-04-05 16:16:29 +00:00
|
|
|
# support functions and some utility
|
2023-12-20 11:16:25 +00:00
|
|
|
include("${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/functions.cmake")
|
2023-11-13 10:29:17 +00:00
|
|
|
|
2023-10-29 14:12:33 +00:00
|
|
|
#***********************************************************************
|
|
|
|
# options
|
|
|
|
#***********************************************************************
|
|
|
|
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_cmake_include_hook(1_options)
|
|
|
|
|
2022-10-31 17:53:38 +00:00
|
|
|
# compilation config options
|
2024-04-05 16:16:29 +00:00
|
|
|
if(NOT USE_STRICT_DEFAULTS)
|
2023-09-25 11:47:43 +00:00
|
|
|
# permissive config defaults when building from source code tarball
|
2024-04-05 16:16:29 +00:00
|
|
|
option(UPX_CONFIG_DISABLE_GITREV "Do not compile with Git version info." ON)
|
|
|
|
option(UPX_CONFIG_DISABLE_SANITIZE "Do not compile with sanitize options." ON)
|
|
|
|
option(UPX_CONFIG_DISABLE_WERROR "Do not compile with -Werror option." ON)
|
2023-02-05 16:20:32 +00:00
|
|
|
option(UPX_CONFIG_DISABLE_WSTRICT "Do not compile with strict compiler warnings." ON)
|
2022-11-22 19:54:12 +00:00
|
|
|
else()
|
2023-02-05 16:20:32 +00:00
|
|
|
# strict config defaults for Git developer builds
|
2023-01-17 22:43:24 +00:00
|
|
|
message(STATUS "===== UPX info: strict config defaults enabled")
|
2024-04-05 16:16:29 +00:00
|
|
|
option(UPX_CONFIG_DISABLE_GITREV "Do not compile with Git version info." OFF)
|
|
|
|
option(UPX_CONFIG_DISABLE_SANITIZE "Do not compile with sanitize options." OFF)
|
|
|
|
option(UPX_CONFIG_DISABLE_WERROR "Do not compile with -Werror option." OFF)
|
2023-02-05 16:20:32 +00:00
|
|
|
option(UPX_CONFIG_DISABLE_WSTRICT "Do not compile with strict compiler warnings." OFF)
|
2022-11-22 19:54:12 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# test config options (see below)
|
2023-06-28 16:18:36 +00:00
|
|
|
# IMPORTANT NOTE: self-pack test can only work if the host executable format is supported by UPX!
|
2024-04-25 01:19:59 +00:00
|
|
|
option(UPX_CONFIG_DISABLE_SELF_PACK_TEST "Do not test packing UPX with itself" OFF)
|
|
|
|
option(UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST "Do not run exhaustive test" OFF)
|
2022-08-17 12:29:29 +00:00
|
|
|
|
|
|
|
#***********************************************************************
|
|
|
|
# init
|
|
|
|
#***********************************************************************
|
|
|
|
|
2024-03-28 18:47:04 +00:00
|
|
|
set(UPX_VERSION_STRING "4.3.0") # this should match src/version.h
|
2023-12-19 15:11:23 +00:00
|
|
|
|
2023-11-21 19:29:54 +00:00
|
|
|
upx_cmake_include_hook(2_init)
|
2023-11-13 10:29:17 +00:00
|
|
|
|
2023-12-20 17:49:34 +00:00
|
|
|
# Disallow in-source build. Note that you will still have to manually
|
2022-08-17 12:29:29 +00:00
|
|
|
# clean up a few files if you accidentally try an in-source build.
|
2023-07-19 18:12:20 +00:00
|
|
|
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git")
|
2023-12-20 17:49:34 +00:00
|
|
|
upx_disallow_in_source_build()
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
2023-05-28 12:06:11 +00:00
|
|
|
|
|
|
|
# global settings
|
2023-11-26 17:30:47 +00:00
|
|
|
if(${CMAKE_VERSION} VERSION_GREATER "3.14.99" AND NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY)
|
2023-06-24 23:55:06 +00:00
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
|
|
|
|
cmake_policy(SET CMP0091 NEW)
|
|
|
|
endif()
|
2023-07-18 05:21:51 +00:00
|
|
|
# global CMake settings that default to ON
|
|
|
|
upx_cache_bool_vars(ON
|
|
|
|
CMAKE_C_STANDARD_REQUIRED CMAKE_CXX_STANDARD_REQUIRED
|
|
|
|
CMAKE_EXPORT_COMPILE_COMMANDS CMAKE_REQUIRED_QUIET
|
|
|
|
)
|
2024-03-28 19:21:11 +00:00
|
|
|
# internal UPX settings
|
2023-07-18 05:21:51 +00:00
|
|
|
upx_cache_bool_vars(OFF
|
|
|
|
UPX_CONFIG_CMAKE_DISABLE_TEST UPX_CONFIG_CMAKE_DISABLE_INSTALL
|
|
|
|
UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK
|
|
|
|
UPX_CONFIG_DISABLE_C_STANDARD UPX_CONFIG_DISABLE_CXX_STANDARD
|
2024-04-10 08:52:48 +00:00
|
|
|
UPX_CONFIG_DISABLE_RUN_UNPACKED_TEST UPX_CONFIG_DISABLE_RUN_PACKED_TEST
|
2024-03-28 19:21:11 +00:00
|
|
|
UPX_CONFIG_REQUIRE_THREADS
|
2023-07-18 05:21:51 +00:00
|
|
|
)
|
2024-03-28 19:21:11 +00:00
|
|
|
upx_cache_bool_vars(ON UPX_CONFIG_EXPECT_THREADS)
|
2024-03-25 10:07:40 +00:00
|
|
|
upx_print_env_var(CC CXX)
|
2022-08-17 12:29:29 +00:00
|
|
|
|
2023-02-05 16:20:32 +00:00
|
|
|
# determine Git revision
|
2022-08-17 12:29:29 +00:00
|
|
|
set(GITREV_SHORT "")
|
|
|
|
set(GITREV_PLUS "")
|
2022-11-02 09:35:40 +00:00
|
|
|
set(GIT_DESCRIBE "")
|
2023-02-05 16:20:32 +00:00
|
|
|
if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git" AND NOT UPX_CONFIG_DISABLE_GITREV)
|
|
|
|
find_package(Git)
|
|
|
|
if(Git_FOUND)
|
|
|
|
execute_process(
|
|
|
|
COMMAND "${GIT_EXECUTABLE}" rev-parse --short=12 HEAD
|
|
|
|
RESULT_VARIABLE result ERROR_QUIET
|
|
|
|
OUTPUT_VARIABLE GITREV_SHORT OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
string(LENGTH "${GITREV_SHORT}" l)
|
|
|
|
if(${result} EQUAL 0 AND ${l} EQUAL 12)
|
|
|
|
execute_process(RESULT_VARIABLE result COMMAND "${GIT_EXECUTABLE}" diff --quiet)
|
|
|
|
if(NOT ${result} EQUAL 0)
|
|
|
|
set(GITREV_PLUS "+")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(GITREV_SHORT "")
|
|
|
|
endif()
|
|
|
|
execute_process(
|
|
|
|
COMMAND "${GIT_EXECUTABLE}" describe --match "v*.*.*" --tags --dirty
|
|
|
|
RESULT_VARIABLE result ERROR_QUIET
|
|
|
|
OUTPUT_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE
|
|
|
|
)
|
|
|
|
if(GIT_DESCRIBE MATCHES "^v?([0-9]+\\.[0-9]+\\.[0-9]+)-([0-9]+)-g(.+)$")
|
|
|
|
set(GIT_DESCRIBE "${CMAKE_MATCH_1}-devel.${CMAKE_MATCH_2}+git-${CMAKE_MATCH_3}")
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
2022-11-02 09:35:40 +00:00
|
|
|
endif()
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
|
|
|
if(GITREV_SHORT)
|
|
|
|
message(STATUS "UPX_VERSION_GITREV = \"${GITREV_SHORT}${GITREV_PLUS}\"")
|
2022-11-02 09:35:40 +00:00
|
|
|
if(GIT_DESCRIBE)
|
|
|
|
message(STATUS "UPX_VERSION_GIT_DESCRIBE = \"${GIT_DESCRIBE}\"")
|
|
|
|
endif()
|
2022-11-06 07:35:00 +00:00
|
|
|
elseif(UPX_CONFIG_DISABLE_GITREV)
|
|
|
|
message(STATUS "UPX_VERSION_GITREV: disabled")
|
2022-08-17 12:29:29 +00:00
|
|
|
else()
|
|
|
|
message(STATUS "UPX_VERSION_GITREV: not set")
|
|
|
|
endif()
|
|
|
|
|
2023-01-17 22:43:24 +00:00
|
|
|
# CMake init
|
2024-03-08 10:52:44 +00:00
|
|
|
upx_set_default_build_type(Release) # default is CMAKE_BUILD_TYPE=Release
|
2023-12-19 15:11:23 +00:00
|
|
|
project(upx VERSION "${UPX_VERSION_STRING}" LANGUAGES C CXX)
|
2023-12-20 17:49:34 +00:00
|
|
|
upx_apply_build_type()
|
2023-11-13 10:29:17 +00:00
|
|
|
|
2024-04-05 16:16:29 +00:00
|
|
|
# set MSVC_FRONTEND, GNU_FRONTEND and MINGW
|
2023-10-12 22:01:00 +00:00
|
|
|
if(NOT DEFINED MSVC_FRONTEND AND (MSVC OR CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC"))
|
2023-04-20 18:10:12 +00:00
|
|
|
set(MSVC_FRONTEND 1)
|
2024-04-05 16:16:29 +00:00
|
|
|
elseif (NOT DEFINED GNU_FRONTEND AND (CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^GNU" OR CMAKE_C_COMPILER_ID MATCHES "(Clang|GNU)"))
|
|
|
|
set(GNU_FRONTEND 1)
|
2023-04-20 18:10:12 +00:00
|
|
|
endif()
|
2023-10-12 22:01:00 +00:00
|
|
|
if(NOT DEFINED MINGW AND CMAKE_C_PLATFORM_ID MATCHES "^MinGW")
|
|
|
|
set(MINGW 1)
|
|
|
|
endif()
|
2023-04-20 18:10:12 +00:00
|
|
|
|
2022-08-17 12:29:29 +00:00
|
|
|
#***********************************************************************
|
2023-07-06 16:03:37 +00:00
|
|
|
# common compilation flags
|
2023-02-05 16:20:32 +00:00
|
|
|
#***********************************************************************
|
|
|
|
|
2023-07-16 05:37:31 +00:00
|
|
|
include(CheckCCompilerFlag)
|
2023-10-22 11:29:26 +00:00
|
|
|
include(CheckFunctionExists)
|
2023-10-23 12:26:37 +00:00
|
|
|
include(CheckIncludeFile)
|
2023-10-22 11:29:26 +00:00
|
|
|
include(CheckStructHasMember)
|
|
|
|
include(CheckSymbolExists)
|
|
|
|
|
2023-11-21 19:29:54 +00:00
|
|
|
upx_cmake_include_hook(3_common_compilation_flags)
|
2023-11-08 09:08:19 +00:00
|
|
|
|
2023-10-22 11:29:26 +00:00
|
|
|
if(NOT DEFINED HAVE_UNISTD_H)
|
|
|
|
check_include_file("unistd.h" HAVE_UNISTD_H)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED HAVE_UTIMENSAT)
|
2023-10-30 11:17:51 +00:00
|
|
|
# proper checking for utimensat() is somewhat messy
|
2023-10-22 11:29:26 +00:00
|
|
|
check_function_exists(utimensat HAVE_UTIMENSAT_FUNCTION__)
|
|
|
|
if(HAVE_UTIMENSAT_FUNCTION__)
|
|
|
|
check_symbol_exists(utimensat "sys/types.h;fcntl.h;sys/stat.h" HAVE_UTIMENSAT_SYMBOL__)
|
|
|
|
if(HAVE_UTIMENSAT_SYMBOL__)
|
2023-10-30 11:17:51 +00:00
|
|
|
CHECK_STRUCT_HAS_MEMBER("struct stat" "st_mtim.tv_nsec" "sys/types.h;fcntl.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC) # POSIX.1-2008
|
2023-10-23 12:26:37 +00:00
|
|
|
if(NOT HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC)
|
2023-10-30 11:17:51 +00:00
|
|
|
CHECK_STRUCT_HAS_MEMBER("struct stat" "st_mtimespec.tv_nsec" "sys/types.h;fcntl.h;sys/stat.h" HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC) # macOS
|
2023-10-22 11:29:26 +00:00
|
|
|
endif()
|
2023-10-23 12:26:37 +00:00
|
|
|
if(HAVE_STRUCT_STAT_ST_MTIM_TV_NSEC OR HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
|
2023-10-22 11:29:26 +00:00
|
|
|
set(HAVE_UTIMENSAT 1)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
2023-07-16 05:37:31 +00:00
|
|
|
|
2023-02-05 16:20:32 +00:00
|
|
|
if(UPX_CONFIG_DISABLE_WSTRICT)
|
|
|
|
# enable all basic warnings
|
|
|
|
set(warn_Wall -Wall)
|
|
|
|
set(warn_WN -W3)
|
|
|
|
else()
|
2023-07-06 16:03:37 +00:00
|
|
|
# enable all basic warnings, and enable lots of strict warnings
|
2023-02-05 16:20:32 +00:00
|
|
|
set(warn_Wall -Wall -Wextra -Wcast-align -Wcast-qual -Wmissing-declarations -Wpointer-arith -Wshadow -Wvla -Wwrite-strings)
|
|
|
|
set(warn_WN -W4)
|
2023-01-29 10:39:57 +00:00
|
|
|
endif()
|
2022-08-17 12:29:29 +00:00
|
|
|
if(UPX_CONFIG_DISABLE_WERROR)
|
2023-07-06 16:03:37 +00:00
|
|
|
# warnings are just warnings
|
2022-08-17 12:29:29 +00:00
|
|
|
set(warn_Werror "")
|
|
|
|
set(warn_WX "")
|
|
|
|
else()
|
2023-07-06 16:03:37 +00:00
|
|
|
# warnings are fatal errors; annoy developers to keep the source code warning-free
|
2022-08-17 12:29:29 +00:00
|
|
|
set(warn_Werror -Werror)
|
|
|
|
set(warn_WX -WX)
|
|
|
|
endif()
|
2023-09-30 08:46:39 +00:00
|
|
|
if(MSVC_FRONTEND)
|
2023-10-21 09:22:18 +00:00
|
|
|
# disable warning C5105 which may get triggered by some older versions of <windows.h>
|
2023-09-30 08:46:39 +00:00
|
|
|
set(warn_WX -wd5105 ${warn_WX})
|
|
|
|
endif()
|
2022-08-17 12:29:29 +00:00
|
|
|
|
2023-07-16 19:28:26 +00:00
|
|
|
if(NOT CMAKE_C_COMPILER_ID MATCHES "^MSVC")
|
2022-08-17 12:29:29 +00:00
|
|
|
# use -O2 instead of -O3 to reduce code size
|
|
|
|
string(REGEX REPLACE "(^| )-O3( |$$)" "\\1-O2\\2" a "${CMAKE_C_FLAGS_RELEASE}")
|
|
|
|
string(REGEX REPLACE "(^| )-O3( |$$)" "\\1-O2\\2" b "${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
set(CMAKE_C_FLAGS_RELEASE "${a}" CACHE STRING "Flags used by the C compiler during RELEASE builds." FORCE)
|
|
|
|
set(CMAKE_CXX_FLAGS_RELEASE "${b}" CACHE STRING "Flags used by the CXX compiler during RELEASE builds." FORCE)
|
|
|
|
endif()
|
2023-10-12 22:01:00 +00:00
|
|
|
if(MSVC_FRONTEND OR WIN32 OR MINGW OR CYGWIN)
|
2022-08-17 12:29:29 +00:00
|
|
|
# disable silly warnings about using "deprecated" POSIX functions like fopen()
|
|
|
|
add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
|
|
|
|
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
2023-10-12 22:01:00 +00:00
|
|
|
add_definitions(-DWIN32_LEAN_AND_MEAN)
|
2023-11-21 19:29:54 +00:00
|
|
|
add_definitions(-D__USE_MINGW_ANSI_STDIO)
|
2023-09-25 11:47:43 +00:00
|
|
|
endif()
|
|
|
|
if(MSVC_FRONTEND)
|
2023-07-16 13:14:19 +00:00
|
|
|
# use -funsigned-char; set __cplusplus according to selected C++ standard
|
|
|
|
add_definitions(-J -Zc:__cplusplus)
|
2023-07-16 19:28:26 +00:00
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "^MSVC")
|
2023-07-16 13:14:19 +00:00
|
|
|
upx_add_definitions(-Zc:preprocessor) # use new preprocessor
|
|
|
|
endif()
|
2023-07-16 19:28:26 +00:00
|
|
|
endif()
|
|
|
|
if(NOT CMAKE_C_COMPILER_ID MATCHES "^MSVC")
|
2022-08-17 12:29:29 +00:00
|
|
|
# protect against security threats caused by misguided compiler "optimizations"
|
2023-07-16 13:14:19 +00:00
|
|
|
upx_add_definitions(-fno-delete-null-pointer-checks -fno-lifetime-dse)
|
|
|
|
upx_add_definitions(-fno-strict-aliasing -fno-strict-overflow -funsigned-char)
|
2022-08-17 12:29:29 +00:00
|
|
|
# disable overambitious auto-vectorization until this actually gains something
|
2023-07-16 13:14:19 +00:00
|
|
|
upx_add_definitions(-fno-tree-vectorize)
|
2023-07-09 15:36:24 +00:00
|
|
|
# disable annoying clang warnings which get added by the macOS Xcode cmake generator
|
2023-07-16 19:28:26 +00:00
|
|
|
if(CMAKE_GENERATOR MATCHES "Xcode")
|
2023-07-16 13:14:19 +00:00
|
|
|
upx_add_definitions(-Wno-shorten-64-to-32)
|
2023-06-13 14:42:14 +00:00
|
|
|
endif()
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
|
|
|
|
2024-04-20 19:08:09 +00:00
|
|
|
# examine compiler configuration
|
|
|
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO)
|
|
|
|
upx_print_common_symbols()
|
2023-12-20 11:16:25 +00:00
|
|
|
upx_print_mingw_symbols()
|
2024-04-20 19:08:09 +00:00
|
|
|
endif() # UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO
|
2023-11-17 10:50:52 +00:00
|
|
|
|
2023-07-06 16:03:37 +00:00
|
|
|
#***********************************************************************
|
|
|
|
# targets
|
|
|
|
#***********************************************************************
|
|
|
|
|
2023-10-05 01:51:27 +00:00
|
|
|
# internal settings; these may change in a future versions
|
2023-07-06 16:03:37 +00:00
|
|
|
set(UPX_CONFIG_DISABLE_THREADS ON) # multithreading is currently not used; maybe in UPX version 5
|
|
|
|
set(UPX_CONFIG_DISABLE_BZIP2 ON) # bzip2 is currently not used; we might need it to decompress linux kernels
|
|
|
|
set(UPX_CONFIG_DISABLE_ZSTD ON) # zstd is currently not used; maybe in UPX version 5
|
|
|
|
|
2023-11-21 19:29:54 +00:00
|
|
|
upx_cmake_include_hook(4_targets)
|
2023-11-13 10:29:17 +00:00
|
|
|
|
2023-07-06 16:03:37 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_THREADS)
|
|
|
|
find_package(Threads)
|
|
|
|
endif()
|
2023-11-17 10:50:52 +00:00
|
|
|
# make sure that threads are indeed fully supported in C++
|
2023-11-14 18:15:34 +00:00
|
|
|
if(Threads_FOUND)
|
|
|
|
foreach(f std_lock_guard.cpp)
|
|
|
|
set(CMAKE_TRY_COMPILE_TARGET_TYPE "EXECUTABLE")
|
2024-02-17 15:34:11 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_CXX_STANDARD)
|
|
|
|
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/try_compile/${f}"
|
|
|
|
OUTPUT_VARIABLE output CXX_STANDARD 17)
|
|
|
|
else()
|
|
|
|
try_compile(result "${CMAKE_CURRENT_BINARY_DIR}"
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/misc/cmake/try_compile/${f}"
|
|
|
|
OUTPUT_VARIABLE output)
|
|
|
|
endif()
|
2023-11-14 18:15:34 +00:00
|
|
|
if(NOT result)
|
2023-12-09 07:52:25 +00:00
|
|
|
# failed; under MinGW be sure to use the posix-threads and NOT the win32-threads version
|
2023-12-20 10:44:01 +00:00
|
|
|
#message(STATUS "Threads FAILED: ${output}") # debug output from try_compile
|
2023-11-14 18:15:34 +00:00
|
|
|
set(Threads_FOUND OFF)
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2023-07-06 16:03:37 +00:00
|
|
|
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_BZIP2)
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_add_glob_files(bzip2_SOURCES "vendor/bzip2/*.c")
|
2023-07-06 16:03:37 +00:00
|
|
|
add_library(upx_vendor_bzip2 STATIC ${bzip2_SOURCES})
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_C_STANDARD)
|
|
|
|
set_property(TARGET upx_vendor_bzip2 PROPERTY C_STANDARD 11)
|
|
|
|
endif()
|
|
|
|
endif() # UPX_CONFIG_DISABLE_BZIP2
|
|
|
|
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_add_glob_files(ucl_SOURCES "vendor/ucl/src/*.c")
|
2023-07-06 16:03:37 +00:00
|
|
|
add_library(upx_vendor_ucl STATIC ${ucl_SOURCES})
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_C_STANDARD)
|
|
|
|
set_property(TARGET upx_vendor_ucl PROPERTY C_STANDARD 11)
|
|
|
|
endif()
|
|
|
|
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_add_glob_files(zlib_SOURCES "vendor/zlib/*.c")
|
2023-07-06 16:03:37 +00:00
|
|
|
add_library(upx_vendor_zlib STATIC ${zlib_SOURCES})
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_C_STANDARD)
|
|
|
|
set_property(TARGET upx_vendor_zlib PROPERTY C_STANDARD 11)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_add_glob_files(zstd_SOURCES "vendor/zstd/lib/*/*.c")
|
2023-07-06 16:03:37 +00:00
|
|
|
add_library(upx_vendor_zstd STATIC ${zstd_SOURCES})
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_C_STANDARD)
|
|
|
|
set_property(TARGET upx_vendor_zstd PROPERTY C_STANDARD 11)
|
|
|
|
endif()
|
|
|
|
endif() # UPX_CONFIG_DISABLE_ZSTD
|
|
|
|
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_add_glob_files(upx_SOURCES "src/*.cpp" "src/[cfu]*/*.cpp")
|
2023-07-06 16:03:37 +00:00
|
|
|
add_executable(upx ${upx_SOURCES})
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_CXX_STANDARD)
|
|
|
|
set_property(TARGET upx PROPERTY CXX_STANDARD 17)
|
|
|
|
endif()
|
|
|
|
target_link_libraries(upx upx_vendor_ucl upx_vendor_zlib)
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_BZIP2)
|
|
|
|
target_link_libraries(upx upx_vendor_bzip2)
|
|
|
|
endif()
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
|
|
|
target_link_libraries(upx upx_vendor_zstd)
|
|
|
|
endif()
|
|
|
|
if(Threads_FOUND)
|
|
|
|
target_link_libraries(upx Threads::Threads)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
#***********************************************************************
|
|
|
|
# target compilation flags
|
|
|
|
#***********************************************************************
|
|
|
|
|
2023-11-21 19:29:54 +00:00
|
|
|
upx_cmake_include_hook(5_target_compilation_flags)
|
2023-11-13 10:29:17 +00:00
|
|
|
|
2023-06-15 17:42:54 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_BZIP2)
|
|
|
|
set(t upx_vendor_bzip2)
|
|
|
|
upx_compile_target_debug_with_O2(${t})
|
|
|
|
upx_sanitize_target(${t})
|
2023-11-06 18:29:40 +00:00
|
|
|
target_compile_definitions(${t} PRIVATE BZ_NO_STDIO=1)
|
2023-06-15 17:42:54 +00:00
|
|
|
if(MSVC_FRONTEND)
|
|
|
|
target_compile_options(${t} PRIVATE ${warn_WN} -wd4127 -wd4244 -wd4267 ${warn_WX})
|
2024-04-05 16:16:29 +00:00
|
|
|
elseif(GNU_FRONTEND)
|
2023-11-03 16:52:46 +00:00
|
|
|
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
2023-06-15 17:42:54 +00:00
|
|
|
endif()
|
2024-02-14 14:14:47 +00:00
|
|
|
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_BZIP2)
|
2023-06-15 17:42:54 +00:00
|
|
|
endif() # UPX_CONFIG_DISABLE_BZIP2
|
|
|
|
|
2022-08-17 12:29:29 +00:00
|
|
|
set(t upx_vendor_ucl)
|
|
|
|
target_include_directories(${t} PRIVATE vendor/ucl/include vendor/ucl)
|
2023-01-16 08:47:39 +00:00
|
|
|
upx_compile_target_debug_with_O2(${t})
|
2022-11-06 07:35:00 +00:00
|
|
|
upx_sanitize_target(${t})
|
2023-04-20 18:10:12 +00:00
|
|
|
if(MSVC_FRONTEND)
|
|
|
|
target_compile_options(${t} PRIVATE ${warn_WN} ${warn_WX})
|
2024-04-05 16:16:29 +00:00
|
|
|
elseif(GNU_FRONTEND)
|
2023-02-05 16:20:32 +00:00
|
|
|
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
2024-02-14 14:14:47 +00:00
|
|
|
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UCL)
|
2022-08-17 12:29:29 +00:00
|
|
|
|
|
|
|
set(t upx_vendor_zlib)
|
2023-01-16 08:47:39 +00:00
|
|
|
upx_compile_target_debug_with_O2(${t})
|
2022-11-06 07:35:00 +00:00
|
|
|
upx_sanitize_target(${t})
|
2023-07-22 14:12:13 +00:00
|
|
|
target_compile_definitions(${t} PRIVATE HAVE_VSNPRINTF=1)
|
2023-09-22 15:33:22 +00:00
|
|
|
if(HAVE_UNISTD_H)
|
|
|
|
target_compile_definitions(${t} PRIVATE HAVE_UNISTD_H=1)
|
|
|
|
endif()
|
2023-04-20 18:10:12 +00:00
|
|
|
if(MSVC_FRONTEND)
|
|
|
|
target_compile_options(${t} PRIVATE -W3 ${warn_WX})
|
2024-04-05 16:16:29 +00:00
|
|
|
elseif(GNU_FRONTEND)
|
2023-11-03 16:52:46 +00:00
|
|
|
target_compile_options(${t} PRIVATE ${warn_Wall} -Wno-cast-align -Wno-cast-qual ${warn_Werror})
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
2024-02-14 14:14:47 +00:00
|
|
|
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZLIB)
|
2022-08-17 12:29:29 +00:00
|
|
|
|
2023-01-13 21:07:24 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
|
|
|
set(t upx_vendor_zstd)
|
2023-01-16 08:47:39 +00:00
|
|
|
upx_compile_target_debug_with_O2(${t})
|
2023-01-13 21:07:24 +00:00
|
|
|
upx_sanitize_target(${t})
|
2023-03-14 23:19:55 +00:00
|
|
|
target_compile_definitions(${t} PRIVATE DYNAMIC_BMI2=0 ZSTD_DISABLE_ASM=1)
|
2023-04-20 18:10:12 +00:00
|
|
|
if(MSVC_FRONTEND)
|
|
|
|
target_compile_options(${t} PRIVATE ${warn_WN} ${warn_WX})
|
2024-04-05 16:16:29 +00:00
|
|
|
elseif(GNU_FRONTEND)
|
2023-02-05 16:20:32 +00:00
|
|
|
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
2023-01-13 21:07:24 +00:00
|
|
|
endif()
|
2024-02-14 14:14:47 +00:00
|
|
|
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_ZSTD)
|
2023-04-18 15:02:13 +00:00
|
|
|
endif() # UPX_CONFIG_DISABLE_ZSTD
|
2023-01-13 21:07:24 +00:00
|
|
|
|
2022-08-17 12:29:29 +00:00
|
|
|
set(t upx)
|
2023-01-30 12:39:49 +00:00
|
|
|
target_include_directories(${t} PRIVATE vendor)
|
2022-08-17 12:29:29 +00:00
|
|
|
target_compile_definitions(${t} PRIVATE $<$<CONFIG:Debug>:DEBUG=1>)
|
|
|
|
if(GITREV_SHORT)
|
|
|
|
target_compile_definitions(${t} PRIVATE UPX_VERSION_GITREV="${GITREV_SHORT}${GITREV_PLUS}")
|
2022-11-02 09:35:40 +00:00
|
|
|
if(GIT_DESCRIBE)
|
|
|
|
target_compile_definitions(${t} PRIVATE UPX_VERSION_GIT_DESCRIBE="${GIT_DESCRIBE}")
|
|
|
|
endif()
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
2023-03-14 23:19:55 +00:00
|
|
|
if(Threads_FOUND)
|
|
|
|
target_compile_definitions(${t} PRIVATE WITH_THREADS=1)
|
|
|
|
endif()
|
2023-04-20 12:13:36 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_WSTRICT)
|
|
|
|
target_compile_definitions(${t} PRIVATE UPX_CONFIG_DISABLE_WSTRICT=0)
|
2023-02-05 16:20:32 +00:00
|
|
|
endif()
|
2023-04-20 12:13:36 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_WERROR)
|
|
|
|
target_compile_definitions(${t} PRIVATE UPX_CONFIG_DISABLE_WERROR=0)
|
2023-02-05 16:20:32 +00:00
|
|
|
endif()
|
2023-06-15 17:42:54 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_BZIP2)
|
2023-11-06 18:29:40 +00:00
|
|
|
target_compile_definitions(${t} PRIVATE WITH_BZIP2=1)
|
2023-06-15 17:42:54 +00:00
|
|
|
endif()
|
2023-02-21 14:19:24 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_ZSTD)
|
|
|
|
target_compile_definitions(${t} PRIVATE WITH_ZSTD=1)
|
|
|
|
endif()
|
2023-10-22 11:29:26 +00:00
|
|
|
if(HAVE_UTIMENSAT)
|
|
|
|
target_compile_definitions(${t} PRIVATE USE_UTIMENSAT=1)
|
2023-10-23 12:26:37 +00:00
|
|
|
if(HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC)
|
2023-10-22 11:29:26 +00:00
|
|
|
target_compile_definitions(${t} PRIVATE HAVE_STRUCT_STAT_ST_MTIMESPEC_TV_NSEC=1)
|
|
|
|
endif()
|
|
|
|
endif()
|
2023-10-29 14:12:33 +00:00
|
|
|
# improve speed of the Debug versions
|
2023-10-24 20:54:54 +00:00
|
|
|
upx_compile_source_debug_with_O2(src/compress/compress_lzma.cpp)
|
|
|
|
upx_compile_source_debug_with_O2(src/filter/filter_impl.cpp)
|
2023-01-16 08:47:39 +00:00
|
|
|
#upx_compile_target_debug_with_O2(${t})
|
2022-11-06 07:35:00 +00:00
|
|
|
upx_sanitize_target(${t})
|
2023-04-20 18:10:12 +00:00
|
|
|
if(MSVC_FRONTEND)
|
|
|
|
target_compile_options(${t} PRIVATE -EHsc ${warn_WN} ${warn_WX})
|
2024-04-05 16:16:29 +00:00
|
|
|
elseif(GNU_FRONTEND)
|
2023-02-05 16:20:32 +00:00
|
|
|
target_compile_options(${t} PRIVATE ${warn_Wall} ${warn_Werror})
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
2024-02-14 14:14:47 +00:00
|
|
|
upx_add_target_extra_compile_options(${t} UPX_CONFIG_EXTRA_COMPILE_OPTIONS_UPX)
|
2022-08-17 12:29:29 +00:00
|
|
|
|
|
|
|
#***********************************************************************
|
2023-10-29 14:12:33 +00:00
|
|
|
# test
|
|
|
|
# ctest
|
|
|
|
# make test
|
|
|
|
# ninja test
|
2022-08-17 12:29:29 +00:00
|
|
|
#***********************************************************************
|
|
|
|
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_cmake_include_hook(6_test)
|
|
|
|
|
2023-01-18 08:28:12 +00:00
|
|
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_TEST)
|
|
|
|
|
2022-10-31 17:53:38 +00:00
|
|
|
include(CTest)
|
2023-11-14 18:15:34 +00:00
|
|
|
if(NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)
|
2024-04-10 08:52:48 +00:00
|
|
|
add_test(NAME upx-version COMMAND upx --version)
|
|
|
|
add_test(NAME upx-version-short COMMAND upx --version-short)
|
|
|
|
add_test(NAME upx-license COMMAND upx --license)
|
2024-04-21 12:20:18 +00:00
|
|
|
add_test(NAME upx-help-1 COMMAND upx --help)
|
|
|
|
add_test(NAME upx-help-2 COMMAND upx --help-short)
|
|
|
|
add_test(NAME upx-help-3 COMMAND upx --help-verbose)
|
|
|
|
add_test(NAME upx-sysinfo-1 COMMAND upx --sysinfo)
|
|
|
|
add_test(NAME upx-sysinfo-2 COMMAND upx --sysinfo -v)
|
|
|
|
add_test(NAME upx-sysinfo-3 COMMAND upx --sysinfo -vv)
|
2023-11-14 18:15:34 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_SELF_PACK_TEST)
|
2023-06-28 16:18:36 +00:00
|
|
|
# IMPORTANT NOTE: these tests can only work if the host executable format is supported by UPX!
|
2023-12-20 17:49:34 +00:00
|
|
|
set(emu "")
|
|
|
|
if(DEFINED CMAKE_CROSSCOMPILING_EMULATOR)
|
|
|
|
set(emu "${CMAKE_CROSSCOMPILING_EMULATOR}")
|
|
|
|
endif()
|
2023-11-14 18:15:34 +00:00
|
|
|
set(exe "${CMAKE_EXECUTABLE_SUFFIX}")
|
2022-10-06 12:10:35 +00:00
|
|
|
set(upx_self_exe "$<TARGET_FILE:upx>")
|
2022-11-16 11:52:53 +00:00
|
|
|
set(fo "--force-overwrite")
|
2024-04-06 13:47:46 +00:00
|
|
|
|
2024-04-10 08:52:48 +00:00
|
|
|
# use fast compression levels because
|
|
|
|
# - we want to test UPX and not the compression libraries
|
|
|
|
# - higher compression levels are somewhat slow in our automated QEMU/Valgrind CI tests
|
2024-04-16 13:20:56 +00:00
|
|
|
upx_add_serial_test(upx-self-pack upx -3 "${upx_self_exe}" ${fo} -o upx-packed${exe})
|
|
|
|
upx_add_serial_test(upx-self-pack-fa upx -3 --all-filters "${upx_self_exe}" ${fo} -o upx-packed-fa${exe})
|
|
|
|
upx_add_serial_test(upx-self-pack-fn upx -3 --no-filter "${upx_self_exe}" ${fo} -o upx-packed-fn${exe})
|
2024-04-21 10:17:38 +00:00
|
|
|
upx_add_serial_test(upx-self-pack-fr upx -3 --debug-use-random-filter "${upx_self_exe}" ${fo} -o upx-packed-fr${exe})
|
2024-04-16 13:20:56 +00:00
|
|
|
upx_add_serial_test(upx-self-pack-nrv2b upx -3 --nrv2b "${upx_self_exe}" ${fo} -o upx-packed-nrv2b${exe})
|
|
|
|
upx_add_serial_test(upx-self-pack-nrv2d upx -3 --nrv2d "${upx_self_exe}" ${fo} -o upx-packed-nrv2d${exe})
|
|
|
|
upx_add_serial_test(upx-self-pack-nrv2e upx -3 --nrv2e "${upx_self_exe}" ${fo} -o upx-packed-nrv2e${exe})
|
|
|
|
upx_add_serial_test(upx-self-pack-lzma upx -1 --lzma "${upx_self_exe}" ${fo} -o upx-packed-lzma${exe})
|
|
|
|
|
2024-04-21 10:17:38 +00:00
|
|
|
upx_add_serial_test(upx-list upx -l upx-packed${exe} upx-packed-fa${exe} upx-packed-fn${exe} upx-packed-fr${exe} upx-packed-nrv2b${exe} upx-packed-nrv2d${exe} upx-packed-nrv2e${exe} upx-packed-lzma${exe})
|
|
|
|
upx_add_serial_test(upx-fileinfo upx --fileinfo upx-packed${exe} upx-packed-fa${exe} upx-packed-fn${exe} upx-packed-fr${exe} upx-packed-nrv2b${exe} upx-packed-nrv2d${exe} upx-packed-nrv2e${exe} upx-packed-lzma${exe})
|
|
|
|
upx_add_serial_test(upx-test upx -t upx-packed${exe} upx-packed-fa${exe} upx-packed-fn${exe} upx-packed-fr${exe} upx-packed-nrv2b${exe} upx-packed-nrv2d${exe} upx-packed-nrv2e${exe} upx-packed-lzma${exe})
|
2024-04-16 13:20:56 +00:00
|
|
|
|
|
|
|
upx_add_serial_test(upx-unpack upx -d upx-packed${exe} ${fo} -o upx-unpacked${exe})
|
|
|
|
upx_add_serial_test(upx-unpack-fa upx -d upx-packed-fa${exe} ${fo} -o upx-unpacked-fa${exe})
|
|
|
|
upx_add_serial_test(upx-unpack-fn upx -d upx-packed-fn${exe} ${fo} -o upx-unpacked-fn${exe})
|
2024-04-21 10:17:38 +00:00
|
|
|
upx_add_serial_test(upx-unpack-fr upx -d upx-packed-fr${exe} ${fo} -o upx-unpacked-fr${exe})
|
2024-04-16 13:20:56 +00:00
|
|
|
upx_add_serial_test(upx-unpack-nrv2b upx -d upx-packed-nrv2b${exe} ${fo} -o upx-unpacked-nrv2b${exe})
|
|
|
|
upx_add_serial_test(upx-unpack-nrv2d upx -d upx-packed-nrv2d${exe} ${fo} -o upx-unpacked-nrv2d${exe})
|
|
|
|
upx_add_serial_test(upx-unpack-nrv2e upx -d upx-packed-nrv2e${exe} ${fo} -o upx-unpacked-nrv2e${exe})
|
|
|
|
upx_add_serial_test(upx-unpack-lzma upx -d upx-packed-lzma${exe} ${fo} -o upx-unpacked-lzma${exe})
|
2024-04-10 08:52:48 +00:00
|
|
|
|
2024-04-21 10:17:38 +00:00
|
|
|
# all unpacked files must be identical
|
|
|
|
upx_add_serial_test(upx-compare-fa "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-fa${exe})
|
|
|
|
upx_add_serial_test(upx-compare-fn "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-fn${exe})
|
|
|
|
upx_add_serial_test(upx-compare-fr "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-fr${exe})
|
|
|
|
upx_add_serial_test(upx-compare-nrv2b "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-nrv2b${exe})
|
|
|
|
upx_add_serial_test(upx-compare-nrv2d "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-nrv2d${exe})
|
|
|
|
upx_add_serial_test(upx-compare-nrv2e "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-nrv2e${exe})
|
|
|
|
upx_add_serial_test(upx-compare-lzma "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-lzma${exe})
|
|
|
|
|
2024-04-10 08:52:48 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_RUN_UNPACKED_TEST)
|
2024-04-16 13:20:56 +00:00
|
|
|
upx_add_serial_test(upx-run-unpacked ${emu} ./upx-unpacked${exe} --version-short)
|
2024-04-10 08:52:48 +00:00
|
|
|
endif()
|
2024-04-06 13:47:46 +00:00
|
|
|
|
2024-04-10 08:52:48 +00:00
|
|
|
if(NOT UPX_CONFIG_DISABLE_RUN_PACKED_TEST)
|
2024-04-21 10:17:38 +00:00
|
|
|
upx_add_serial_test(upx-run-packed ${emu} ./upx-packed${exe} --version-short)
|
|
|
|
upx_add_serial_test(upx-run-packed-fa ${emu} ./upx-packed-fa${exe} --version-short)
|
|
|
|
upx_add_serial_test(upx-run-packed-fn ${emu} ./upx-packed-fn${exe} --version-short)
|
|
|
|
upx_add_serial_test(upx-run-packed-fr ${emu} ./upx-packed-fr${exe} --version-short)
|
2024-04-16 13:20:56 +00:00
|
|
|
upx_add_serial_test(upx-run-packed-nrv2b ${emu} ./upx-packed-nrv2b${exe} --version-short)
|
|
|
|
upx_add_serial_test(upx-run-packed-nrv2d ${emu} ./upx-packed-nrv2d${exe} --version-short)
|
|
|
|
upx_add_serial_test(upx-run-packed-nrv2e ${emu} ./upx-packed-nrv2e${exe} --version-short)
|
2024-04-21 10:17:38 +00:00
|
|
|
upx_add_serial_test(upx-run-packed-lzma ${emu} ./upx-packed-lzma${exe} --version-short)
|
2024-04-10 08:52:48 +00:00
|
|
|
endif()
|
2024-04-25 01:19:59 +00:00
|
|
|
|
|
|
|
# TODO later: check if we can somehow run these tests in parallel groups
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST)
|
|
|
|
foreach(method IN ITEMS nrv2b nrv2d nrv2e lzma)
|
2024-04-25 08:56:24 +00:00
|
|
|
foreach(level IN ITEMS 1 2 3 4 5 6 7)
|
2024-04-25 01:19:59 +00:00
|
|
|
set(s "${method}-${level}")
|
|
|
|
upx_add_serial_test(upx-self-pack-${s} upx --${method} -${level} --debug-use-random-filter "${upx_self_exe}" ${fo} -o upx-packed-${s}${exe})
|
|
|
|
upx_add_serial_test(upx-list-${s} upx -l upx-packed-${s}${exe})
|
|
|
|
upx_add_serial_test(upx-fileinfo-${s} upx --fileinfo upx-packed-${s}${exe})
|
|
|
|
upx_add_serial_test(upx-test-${s} upx -t upx-packed-${s}${exe})
|
|
|
|
upx_add_serial_test(upx-unpack-pack-${s} upx -d upx-packed-${s}${exe} ${fo} -o upx-unpacked-${s}${exe})
|
|
|
|
upx_add_serial_test(upx-compare-${s} "${CMAKE_COMMAND}" -E compare_files upx-unpacked${exe} upx-unpacked-${s}${exe})
|
|
|
|
if(NOT UPX_CONFIG_DISABLE_RUN_PACKED_TEST)
|
|
|
|
upx_add_serial_test(upx-run-packed-${s} ${emu} ./upx-packed-${s}${exe} --version-short)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
endif () # UPX_CONFIG_DISABLE_EXHAUSTIVE_TEST
|
2023-11-14 18:15:34 +00:00
|
|
|
endif() # UPX_CONFIG_DISABLE_SELF_PACK_TEST
|
2024-04-10 08:52:48 +00:00
|
|
|
endif() # CMAKE_CROSSCOMPILING
|
2022-10-06 12:10:35 +00:00
|
|
|
|
2023-01-18 08:28:12 +00:00
|
|
|
endif() # UPX_CONFIG_CMAKE_DISABLE_TEST
|
|
|
|
|
2022-08-17 12:29:29 +00:00
|
|
|
#***********************************************************************
|
2023-10-29 14:12:33 +00:00
|
|
|
# install
|
|
|
|
# cmake --install .
|
|
|
|
# make install
|
|
|
|
# ninja install
|
2022-08-17 12:29:29 +00:00
|
|
|
#***********************************************************************
|
|
|
|
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_cmake_include_hook(7_install)
|
|
|
|
|
2023-01-18 08:28:12 +00:00
|
|
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_INSTALL)
|
|
|
|
|
2022-09-16 10:37:56 +00:00
|
|
|
# installation prefix and directories
|
|
|
|
if(NOT CMAKE_INSTALL_PREFIX)
|
2023-06-09 12:12:05 +00:00
|
|
|
#message(FATAL_ERROR "ERROR: CMAKE_INSTALL_PREFIX is not defined")
|
|
|
|
message(WARNING "WARNING: CMAKE_INSTALL_PREFIX is not defined")
|
2022-09-16 10:37:56 +00:00
|
|
|
endif()
|
2023-01-04 23:57:01 +00:00
|
|
|
if(CMAKE_INSTALL_PREFIX)
|
|
|
|
include(GNUInstallDirs)
|
|
|
|
endif()
|
2023-12-09 07:52:25 +00:00
|
|
|
# install files
|
2023-01-04 23:57:01 +00:00
|
|
|
if(CMAKE_INSTALL_PREFIX AND DEFINED CMAKE_INSTALL_FULL_BINDIR)
|
2022-09-16 10:37:56 +00:00
|
|
|
install(TARGETS upx DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
|
|
|
|
install(FILES
|
2023-03-18 20:27:34 +00:00
|
|
|
COPYING LICENSE NEWS README doc/THANKS.txt doc/upx-doc.html doc/upx-doc.txt
|
2022-09-16 10:37:56 +00:00
|
|
|
DESTINATION "${CMAKE_INSTALL_FULL_DOCDIR}"
|
|
|
|
)
|
|
|
|
install(FILES doc/upx.1 DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man1")
|
2022-08-17 12:29:29 +00:00
|
|
|
endif()
|
|
|
|
|
2023-01-18 08:28:12 +00:00
|
|
|
endif() # UPX_CONFIG_CMAKE_DISABLE_INSTALL
|
|
|
|
|
2022-08-17 12:29:29 +00:00
|
|
|
#***********************************************************************
|
2023-11-21 19:29:54 +00:00
|
|
|
# summary
|
2023-10-29 14:12:33 +00:00
|
|
|
# print some info about the build configuration
|
2022-08-17 12:29:29 +00:00
|
|
|
#***********************************************************************
|
|
|
|
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_cmake_include_hook(8_summary)
|
2023-06-29 23:20:48 +00:00
|
|
|
|
2023-12-19 15:11:23 +00:00
|
|
|
upx_print_var(CMAKE_VERSION UPX_CONFIG_CMAKE_MINIMUM_REQUIRED_VERSION CMAKE_GENERATOR)
|
2023-01-18 08:28:12 +00:00
|
|
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO)
|
2024-03-08 10:52:44 +00:00
|
|
|
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()
|
2024-01-24 19:53:14 +00:00
|
|
|
upx_print_var(CMAKE_HOST_SYSTEM_NAME CMAKE_HOST_SYSTEM_VERSION CMAKE_HOST_SYSTEM_PROCESSOR CMAKE_APPLE_SILICON_PROCESSOR)
|
|
|
|
upx_print_var(CMAKE_SYSTEM_NAME CMAKE_SYSTEM_VERSION CMAKE_SYSTEM_PROCESSOR CMAKE_CROSSCOMPILING CMAKE_CROSSCOMPILING_EMULATOR)
|
2024-02-13 17:29:07 +00:00
|
|
|
upx_print_var(CMAKE_OSX_DEPLOYMENT_TARGET CMAKE_OSX_SYSROOT)
|
2024-03-25 10:07:40 +00:00
|
|
|
upx_print_var(CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_AR CMAKE_RANLIB)
|
2023-12-19 15:11:23 +00:00
|
|
|
upx_print_var(CMAKE_C_COMPILER_ID CMAKE_C_COMPILER_VERSION CMAKE_C_COMPILER_FRONTEND_VARIANT CMAKE_C_COMPILER_ARCHITECTURE_ID CMAKE_C_PLATFORM_ID CMAKE_C_COMPILER_ABI)
|
|
|
|
upx_print_var(CMAKE_CXX_COMPILER_ID CMAKE_CXX_COMPILER_VERSION CMAKE_CXX_COMPILER_FRONTEND_VARIANT CMAKE_CXX_COMPILER_ARCHITECTURE_ID CMAKE_CXX_PLATFORM_ID CMAKE_CXX_COMPILER_ABI)
|
|
|
|
upx_print_var(CMAKE_INTERPROCEDURAL_OPTIMIZATION CMAKE_POSITION_INDEPENDENT_CODE CMAKE_TRY_COMPILE_CONFIGURATION)
|
2024-04-05 16:16:29 +00:00
|
|
|
upx_print_var(APPLE CLANG CYGWIN GNU_FRONTEND GNUC MINGW MSVC MSVC_FRONTEND MSVC_IDE MSVC_TOOLSET_VERSION MSVC_VERSION MSYS UNIX WIN32 WIN64)
|
2023-01-18 08:28:12 +00:00
|
|
|
endif() # UPX_CONFIG_CMAKE_DISABLE_PRINT_INFO
|
2023-12-19 15:11:23 +00:00
|
|
|
upx_print_var(CMAKE_INSTALL_PREFIX CMAKE_CONFIGURATION_TYPES CMAKE_BUILD_TYPE)
|
2023-11-14 18:15:34 +00:00
|
|
|
if(Threads_FOUND)
|
|
|
|
message(STATUS "WITH_THREADS = 1")
|
2023-11-15 12:06:29 +00:00
|
|
|
elseif(UPX_CONFIG_REQUIRE_THREADS)
|
|
|
|
message(FATAL_ERROR "ERROR: WITH_THREADS required")
|
|
|
|
elseif(UPX_CONFIG_EXPECT_THREADS AND NOT UPX_CONFIG_DISABLE_THREADS)
|
2024-04-01 18:31:05 +00:00
|
|
|
message(FATAL_ERROR "ERROR: WITH_THREADS expected; set UPX_CONFIG_EXPECT_THREADS=OFF to disable")
|
2023-11-14 18:15:34 +00:00
|
|
|
endif()
|
2023-03-14 23:19:55 +00:00
|
|
|
if(CMAKE_BUILD_TYPE AND NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|None|Release)$")
|
2022-08-17 12:29:29 +00:00
|
|
|
message(WARNING "WARNING: unsupported CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}; please use \"Debug\" or \"Release\"")
|
|
|
|
endif()
|
|
|
|
|
2023-01-04 23:57:01 +00:00
|
|
|
# extra sanity checks to detect incompatible C vs CXX settings
|
2023-03-14 23:19:55 +00:00
|
|
|
if(NOT UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK)
|
2024-03-26 14:38:20 +00:00
|
|
|
upx_platform_check_mismatch(CMAKE_C_PLATFORM_ID CMAKE_CXX_PLATFORM_ID)
|
|
|
|
upx_platform_check_mismatch(CMAKE_C_COMPILER_ABI CMAKE_CXX_COMPILER_ABI)
|
|
|
|
upx_platform_check_mismatch(CMAKE_C_COMPILER_FRONTEND_VARIANT CMAKE_CXX_COMPILER_FRONTEND_VARIANT)
|
2023-01-29 10:39:57 +00:00
|
|
|
endif() # UPX_CONFIG_CMAKE_DISABLE_PLATFORM_CHECK
|
2023-01-01 12:54:39 +00:00
|
|
|
|
2023-11-13 10:29:17 +00:00
|
|
|
upx_cmake_include_hook(9_finish)
|
2023-12-02 00:48:26 +00:00
|
|
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/.upx_cmake_config_done.txt" "")
|
2023-11-13 10:29:17 +00:00
|
|
|
|
2022-08-17 12:29:29 +00:00
|
|
|
# vim:set ft=cmake ts=4 sw=4 tw=0 et:
|