From 4a2d0f96e3f6ea878eafff801732ea0c4c69b419 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 14 Nov 2024 09:23:41 +0100 Subject: [PATCH] [cmake] unify compiler settings move settings to cmake/CompilerFlags.cmake and cmake/CXXCompilerFlags.cmake --- CMakeLists.txt | 143 +----------------------- cmake/CFlagsToVar.cmake | 3 +- cmake/CXXCompilerFlags.cmake | 41 ++----- cmake/CheckAndSetFlag.cmake | 28 +++++ cmake/CleaningConfigureFile.cmake | 1 + cmake/CommonCompilerFlags.cmake | 50 +++++++++ cmake/CompilerFlags.cmake | 50 +++------ cmake/CompilerSanitizerOptions.cmake | 42 +++++++ cmake/ConfigOptions.cmake | 11 +- cmake/ExportAllSymbols.cmake | 13 +++ rdtk/CMakeLists.txt | 8 +- scripts/blacklist-address-sanitizer.txt | 0 scripts/blacklist-memory-sanitizer.txt | 1 - scripts/blacklist-thread-sanitizer.txt | 0 uwac/CMakeLists.txt | 8 +- winpr/CMakeLists.txt | 14 +-- 16 files changed, 168 insertions(+), 245 deletions(-) create mode 100644 cmake/CheckAndSetFlag.cmake create mode 100644 cmake/CommonCompilerFlags.cmake create mode 100644 cmake/CompilerSanitizerOptions.cmake create mode 100644 cmake/ExportAllSymbols.cmake delete mode 100644 scripts/blacklist-address-sanitizer.txt delete mode 100644 scripts/blacklist-memory-sanitizer.txt delete mode 100644 scripts/blacklist-thread-sanitizer.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index ec7d5241b..93c3afcd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,48 +200,9 @@ if(BUILD_TESTING_INTERNAL) add_compile_definitions(BUILD_TESTING_INTERNAL) elseif(BUILD_TESTING) set(EXPORT_ALL_SYMBOLS OFF CACHE BOOL "testing default" FORCE) -else() - option(EXPORT_ALL_SYMBOLS "Export all symbols form library" OFF) endif() -if (EXPORT_ALL_SYMBOLS) - # set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) - add_compile_definitions(EXPORT_ALL_SYMBOLS) -endif(EXPORT_ALL_SYMBOLS) - -# Compiler-specific flags -if(CMAKE_COMPILER_IS_GNUCC) - if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_SYSTEM_PROCESSOR MATCHES "i686") - CHECK_SYMBOL_EXISTS(__x86_64__ "" IS_X86_64) - if(IS_X86_64) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - else() - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=i686") - endif() - endif() - - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") - - if(NOT EXPORT_ALL_SYMBOLS) - message(STATUS "GCC default symbol visibility: hidden") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") - endif() - CHECK_C_COMPILER_FLAG (-Wimplicit-function-declaration Wimplicit-function-declaration) - if(Wimplicit-function-declaration) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wimplicit-function-declaration") - endif() - - if (NOT OPENBSD) - CHECK_C_COMPILER_FLAG (-Wredundant-decls Wredundant-decls) - if(Wredundant-decls) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wredundant-decls") - endif() - endif() - add_compile_definitions("$<$:NDEBUG>") - add_compile_definitions("$<$:NDEBUG>") - add_compile_options("$<$:-g>") - add_compile_options("$<$:-g>") -endif() +include(ExportAllSymbols) set(THREAD_PREFER_PTHREAD_FLAG TRUE) @@ -249,92 +210,6 @@ if(NOT IOS) find_package(Threads REQUIRED) endif() -# Enable address sanitizer, where supported and when required -if(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCC) - set(CMAKE_REQUIRED_LINK_OPTIONS_SAVED ${CMAKE_REQUIRED_LINK_OPTIONS}) - file(WRITE ${PROJECT_BINARY_DIR}/foo.txt "") - if(WITH_SANITIZE_ADDRESS) - list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=address") - CHECK_C_COMPILER_FLAG ("-fsanitize=address" fsanitize-address) - CHECK_C_COMPILER_FLAG ("-fsanitize-blacklist=${PROJECT_BINARY_DIR}/foo.txt" fsanitize-blacklist) - CHECK_C_COMPILER_FLAG ("-fsanitize-address-use-after-scope" fsanitize-address-use-after-scope) - - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") - - if(fsanitize-blacklist) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/scripts/blacklist-address-sanitizer.txt") - endif(fsanitize-blacklist) - - if(fsanitize-address-use-after-scope) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-address-use-after-scope") - endif(fsanitize-address-use-after-scope) - elseif(WITH_SANITIZE_MEMORY) - list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=memory") - CHECK_C_COMPILER_FLAG ("-fsanitize=memory" fsanitize-memory) - CHECK_C_COMPILER_FLAG ("-fsanitize-blacklist=${PROJECT_BINARY_DIR}/foo.txt" fsanitize-blacklist) - CHECK_C_COMPILER_FLAG ("-fsanitize-memory-use-after-dtor" fsanitize-memory-use-after-dtor) - CHECK_C_COMPILER_FLAG ("-fsanitize-memory-track-origins" fsanitize-memory-track-origins) - - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=memory") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=memory") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=memory") - - if(fsanitize-blacklist) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/scripts/blacklist-memory-sanitizer.txt") - endif(fsanitize-blacklist) - - if (fsanitize-memory-use-after-dtor) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-memory-use-after-dtor") - endif(fsanitize-memory-use-after-dtor) - - if (fsanitize-memory-track-origins) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-memory-track-origins") - endif(fsanitize-memory-track-origins) - elseif(WITH_SANITIZE_THREAD) - list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "-fsanitize=thread") - CHECK_C_COMPILER_FLAG ("-fsanitize=thread" fsanitize-thread) - CHECK_C_COMPILER_FLAG ("-fsanitize-blacklist=${PROJECT_BINARY_DIR}/foo.txt" fsanitize-blacklist) - - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread") - if(fsanitize-blacklist) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize-blacklist=${PROJECT_SOURCE_DIR}/scripts/blacklist-thread-sanitizer.txt") - endif(fsanitize-blacklist) - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=thread") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=thread") - endif() - - file(REMOVE ${PROJECT_BINARY_DIR}/foo.txt) - set(CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS_SAVED}) - - if (WITH_NO_UNDEFINED) - CHECK_C_COMPILER_FLAG (-Wl,--no-undefined no-undefined) - - if(no-undefined) - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--no-undefined" ) - SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined" ) - endif() - endif() -endif() - -if(MSVC) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gd") - - set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}) - set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}) - - add_compile_options("$<$:/Zi>") - - add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE) -endif() - -if(ANDROID) - # workaround for https://github.com/android-ndk/ndk/issues/243 - string(REPLACE "-g " "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS}) - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g") -endif() - if(WIN32) add_compile_definitions(UNICODE _UNICODE) add_compile_definitions(_CRT_SECURE_NO_WARNINGS) @@ -443,12 +318,6 @@ if(ANDROID) endif(WITH_GPROF) endif() -if(WITH_VALGRIND_MEMCHECK) - check_include_files(valgrind/memcheck.h FREERDP_HAVE_VALGRIND_MEMCHECK_H) -else() - unset(FREERDP_HAVE_VALGRIND_MEMCHECK_H CACHE) -endif() - if(UNIX OR CYGWIN) set(WAYLAND_FEATURE_TYPE "RECOMMENDED") else() @@ -628,16 +497,6 @@ else() set(FREERDP_PROXY_PLUGINDIR "${PROXY_PLUGINDIR}") endif() -# Android profiling -if(ANDROID) - if(WITH_GPROF) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pg") - set(PROFILER_LIBRARIES - "${FREERDP_EXTERNAL_PROFILER_PATH}/obj/local/${ANDROID_ABI}/libandroid-ndk-profiler.a") - include_directories(SYSTEM "${FREERDP_EXTERNAL_PROFILER_PATH}") - endif() -endif() - # Unit Tests include(CTest) diff --git a/cmake/CFlagsToVar.cmake b/cmake/CFlagsToVar.cmake index 15c49d33b..95136d61d 100644 --- a/cmake/CFlagsToVar.cmake +++ b/cmake/CFlagsToVar.cmake @@ -4,10 +4,9 @@ function(CFlagsToVar NAME CFG) string(REPLACE "${CMAKE_SOURCE_DIR}" "" C_FLAGS "${C_FLAGS}") string(REPLACE "${CMAKE_BINARY_DIR}" "" C_FLAGS "${C_FLAGS}") - string(APPEND C_FLAGS " ${CMAKE_C_FLAGS_${UCFG}}") + string(APPEND C_FLAGS " ${CMAKE_C_FLAGS_${UCFG}}") string(REPLACE "\$" "\\\$" C_FLAGS "${C_FLAGS}") string(REPLACE "\"" "\\\"" C_FLAGS "${C_FLAGS}") set(${NAME} ${C_FLAGS} PARENT_SCOPE) endfunction() - diff --git a/cmake/CXXCompilerFlags.cmake b/cmake/CXXCompilerFlags.cmake index 732c93149..78eb421c2 100644 --- a/cmake/CXXCompilerFlags.cmake +++ b/cmake/CXXCompilerFlags.cmake @@ -1,4 +1,5 @@ include(CheckCXXCompilerFlag) +include(CommonCompilerFlags) macro (checkCXXFlag FLAG) check_cxx_compiler_flag("${FLAG}" CXXFLAG${FLAG}) @@ -9,9 +10,6 @@ macro (checkCXXFlag FLAG) endif() endmacro() -option(ENABLE_WARNING_VERBOSE "enable -Weveryting (and some exceptions) for compile" OFF) -option(ENABLE_WARNING_ERROR "enable -Werror for compile" OFF) - if (ENABLE_WARNING_VERBOSE) if (MSVC) # Remove previous warning definitions, @@ -25,24 +23,9 @@ if (ENABLE_WARNING_VERBOSE) string (REGEX REPLACE "(^| )[/-]W[ ]*[1-9]" " " "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") endforeach() - - set(C_WARNING_FLAGS - /W4 - /wo4324 - ) else() - set(C_WARNING_FLAGS - -Weverything - -Wall - -Wpedantic - -Wno-padded - -Wno-switch-enum - -Wno-cast-align + list(APPEND COMMON_COMPILER_FLAGS -Wno-declaration-after-statement - -Wno-unsafe-buffer-usage - -Wno-reserved-identifier - -Wno-covered-switch-default - -Wno-disabled-macro-expansion -Wno-ctad-maybe-unsupported -Wno-c++98-compat -Wno-c++98-compat-pedantic @@ -51,18 +34,11 @@ if (ENABLE_WARNING_VERBOSE) -Wno-gnu-zero-variadic-macro-arguments ) endif() - - foreach(FLAG ${C_WARNING_FLAGS}) - CheckCXXFlag(${FLAG}) - endforeach() endif() - -if (ENABLE_WARNING_ERROR) - CheckCXXFlag(-Werror) -endif() - -CheckCXXFlag(-fno-omit-frame-pointer) +foreach(FLAG ${COMMON_COMPILER_FLAGS}) + CheckCXXFlag(${FLAG}) +endforeach() if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.>) @@ -78,6 +54,13 @@ if (WIN32) add_compile_options($<$:-DNOMINMAX>) endif() +if(MSVC) + add_compile_options(/Gd) + + add_compile_options("$<$:/Zi>") + add_compile_definitions(_CRT_NONSTDC_NO_DEPRECATE) +endif() + set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "default CXXFLAGS") message("Using CXXFLAGS ${CMAKE_CXX_FLAGS}") message("Using CXXFLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE}") diff --git a/cmake/CheckAndSetFlag.cmake b/cmake/CheckAndSetFlag.cmake new file mode 100644 index 000000000..22635960c --- /dev/null +++ b/cmake/CheckAndSetFlag.cmake @@ -0,0 +1,28 @@ +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) + +macro (CheckAndSetFlag FLAG) + if (FLAG) + get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES) + + unset(C_FLAG) + unset(CXX_FLAG) + if ("C" IN_LIST languages) + CHECK_C_COMPILER_FLAG("${FLAG}" C_FLAG) + if (C_FLAG) + string(APPEND CMAKE_C_FLAGS " ${FLAG}") + endif() + endif() + + if ("CXX" IN_LIST languages) + CHECK_CXX_COMPILER_FLAG("${FLAG}" CXX_FLAG) + if (CXX_FLAG) + string(APPEND CMAKE_CXX_FLAGS " ${FLAG}") + endif() + endif() + + if(NOT C_FLAG AND NOT CXX_FLAG) + message(WARNING "compiler does not support ${FLAG}") + endif() + endif() +endmacro() diff --git a/cmake/CleaningConfigureFile.cmake b/cmake/CleaningConfigureFile.cmake index cc0246b06..7a2305a90 100644 --- a/cmake/CleaningConfigureFile.cmake +++ b/cmake/CleaningConfigureFile.cmake @@ -36,6 +36,7 @@ function(cleaning_configure_file RSRC RDST) configure_file(${SRC} ${DST} ${ARGN}) string(SHA256 DST_HASH "${DST}") + string(SUBSTRING "${DST_HASH}" 0 8 DST_HASH) if (NOT TARGET ct-${DST_HASH}) add_custom_target(ct-${DST_HASH} ALL COMMAND ${CMAKE_COMMAND} "-E" "make_directory" "${DST_DIR}" diff --git a/cmake/CommonCompilerFlags.cmake b/cmake/CommonCompilerFlags.cmake new file mode 100644 index 000000000..c8727b432 --- /dev/null +++ b/cmake/CommonCompilerFlags.cmake @@ -0,0 +1,50 @@ +include(CheckAndSetFlag) + +option(ENABLE_WARNING_VERBOSE "enable -Weveryting (and some exceptions) for compile" OFF) +option(ENABLE_WARNING_ERROR "enable -Werror for compile" OFF) + +set(COMMON_COMPILER_FLAGS "") +if (ENABLE_WARNING_VERBOSE) + if (MSVC) + list(APPEND COMMON_COMPILER_FLAGS + /W4 + /wo4324 + ) + else() + list(APPEND COMMON_COMPILER_FLAGS + -Weverything + -Wall + -Wpedantic + -Wno-padded + -Wno-switch-enum + -Wno-cast-align + -Wno-unsafe-buffer-usage + -Wno-reserved-identifier + -Wno-covered-switch-default + -Wno-disabled-macro-expansion + ) + endif() +endif() + +if (ENABLE_WARNING_ERROR) + list(APPEND COMMON_COMPILER_FLAGS -Werror) +endif() + +list(APPEND COMMON_COMPILER_FLAGS + -fno-omit-frame-pointer + -Wredundant-decls +) + +include(ExportAllSymbols) +include(CompilerSanitizerOptions) + +if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") + add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.>) + add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_BINARY_DIR}=./build>) + add_compile_options($<$>:-fmacro-prefix-map=${CMAKE_BINARY_DIR}=./build>) + add_compile_options($<$>:-ffile-prefix-map=${CMAKE_BINARY_DIR}=./build>) +endif() + + diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index 90d994f80..62c53f7aa 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -1,4 +1,5 @@ include(CheckCCompilerFlag) +include(CommonCompilerFlags) macro (checkCFlag FLAG) CHECK_C_COMPILER_FLAG("${FLAG}" CFLAG${FLAG}) @@ -9,9 +10,6 @@ macro (checkCFlag FLAG) endif() endmacro() -option(ENABLE_WARNING_VERBOSE "enable -Weveryting (and some exceptions) for compile" OFF) -option(ENABLE_WARNING_ERROR "enable -Werror for compile" OFF) - if (ENABLE_WARNING_VERBOSE) if (MSVC) # Remove previous warning definitions, @@ -25,47 +23,31 @@ if (ENABLE_WARNING_VERBOSE) string (REGEX REPLACE "(^| )[/-]W[ ]*[1-9]" " " "${flags_var_to_scrub}" "${${flags_var_to_scrub}}") endforeach() - - set(C_WARNING_FLAGS - /W4 - /wo4324 - ) else() - set(C_WARNING_FLAGS - -Weverything - -Wall - -Wpedantic - -Wno-padded - -Wno-switch-enum - -Wno-cast-align + list(APPEND COMMON_COMPILER_FLAGS -Wno-declaration-after-statement - -Wno-unsafe-buffer-usage - -Wno-reserved-identifier - -Wno-covered-switch-default - -Wno-disabled-macro-expansion -Wno-pre-c11-compat -Wno-gnu-zero-variadic-macro-arguments ) endif() - - foreach(FLAG ${C_WARNING_FLAGS}) - CheckCFlag(${FLAG}) - endforeach() endif() -if (ENABLE_WARNING_ERROR) - CheckCFlag(-Werror) -endif() +list(APPEND COMMON_COMPILER_FLAGS + -Wimplicit-function-declaration +) -CheckCFlag(-fno-omit-frame-pointer) +foreach(FLAG ${COMMON_COMPILER_FLAGS}) + CheckCFlag(${FLAG}) +endforeach() -if (CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "GNU") - add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_SOURCE_DIR}=.>) - add_compile_options($<$>:-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=.>) - add_compile_options($<$>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}=.>) - add_compile_options($<$>:-fdebug-prefix-map=${CMAKE_BINARY_DIR}=./build>) - add_compile_options($<$>:-fmacro-prefix-map=${CMAKE_BINARY_DIR}=./build>) - add_compile_options($<$>:-ffile-prefix-map=${CMAKE_BINARY_DIR}=./build>) +# Android profiling +if(ANDROID) + if(WITH_GPROF) + CheckAndSetFlag(-pg) + set(PROFILER_LIBRARIES + "${FREERDP_EXTERNAL_PROFILER_PATH}/obj/local/${ANDROID_ABI}/libandroid-ndk-profiler.a") + include_directories(SYSTEM "${FREERDP_EXTERNAL_PROFILER_PATH}") + endif() endif() set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "default CFLAGS") diff --git a/cmake/CompilerSanitizerOptions.cmake b/cmake/CompilerSanitizerOptions.cmake new file mode 100644 index 000000000..8d869545e --- /dev/null +++ b/cmake/CompilerSanitizerOptions.cmake @@ -0,0 +1,42 @@ +include(CMakeDependentOption) + +CMAKE_DEPENDENT_OPTION(WITH_VALGRIND_MEMCHECK "Compile with valgrind helpers." OFF + "NOT WITH_SANITIZE_ADDRESS; NOT WITH_SANITIZE_MEMORY; NOT WITH_SANITIZE_THREAD" OFF) +CMAKE_DEPENDENT_OPTION(WITH_SANITIZE_ADDRESS "Compile with gcc/clang address sanitizer." OFF + "NOT WITH_VALGRIND_MEMCHECK; NOT WITH_SANITIZE_MEMORY; NOT WITH_SANITIZE_THREAD" OFF) +CMAKE_DEPENDENT_OPTION(WITH_SANITIZE_MEMORY "Compile with gcc/clang memory sanitizer." OFF + "NOT WITH_VALGRIND_MEMCHECK; NOT WITH_SANITIZE_ADDRESS; NOT WITH_SANITIZE_THREAD" OFF) +CMAKE_DEPENDENT_OPTION(WITH_SANITIZE_THREAD "Compile with gcc/clang thread sanitizer." OFF + "NOT WITH_VALGRIND_MEMCHECK; NOT WITH_SANITIZE_ADDRESS; NOT WITH_SANITIZE_MEMORY" OFF) + +if(WITH_VALGRIND_MEMCHECK) + check_include_files(valgrind/memcheck.h FREERDP_HAVE_VALGRIND_MEMCHECK_H) +else() + unset(FREERDP_HAVE_VALGRIND_MEMCHECK_H CACHE) +endif() + +# Enable address sanitizer, where supported and when required +if(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCC) + set(CMAKE_REQUIRED_LINK_OPTIONS_SAVED ${CMAKE_REQUIRED_LINK_OPTIONS}) + file(WRITE ${PROJECT_BINARY_DIR}/foo.txt "") + if(WITH_SANITIZE_ADDRESS) + add_compile_options(-fsanitize=address) + add_compile_options(-fsanitize-address-use-after-scope) + add_link_options(-fsanitize=address) + elseif(WITH_SANITIZE_MEMORY) + add_compile_options(-fsanitize=memory) + add_compile_options(-fsanitize-memory-use-after-dtor) + add_compile_options(-fsanitize-memory-track-origins) + add_link_options(-fsanitize=memory) + elseif(WITH_SANITIZE_THREAD) + add_compile_options(-fsanitize=thread) + add_link_options(-fsanitize=thread) + endif() + + option(WITH_NO_UNDEFINED "Add -Wl,--no-undefined" OFF) + if (WITH_NO_UNDEFINED) + add_link_options(-Wl,--no-undefined) + endif() +endif() + + diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 358ff685a..c45693171 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -31,16 +31,7 @@ option(WITH_JPEG "Use JPEG decoding." OFF) include(CompilerDetect) -if(NOT WIN32) - CMAKE_DEPENDENT_OPTION(WITH_VALGRIND_MEMCHECK "Compile with valgrind helpers." OFF - "NOT WITH_SANITIZE_ADDRESS; NOT WITH_SANITIZE_MEMORY; NOT WITH_SANITIZE_THREAD" OFF) - CMAKE_DEPENDENT_OPTION(WITH_SANITIZE_ADDRESS "Compile with gcc/clang address sanitizer." OFF - "NOT WITH_VALGRIND_MEMCHECK; NOT WITH_SANITIZE_MEMORY; NOT WITH_SANITIZE_THREAD" OFF) - CMAKE_DEPENDENT_OPTION(WITH_SANITIZE_MEMORY "Compile with gcc/clang memory sanitizer." OFF - "NOT WITH_VALGRIND_MEMCHECK; NOT WITH_SANITIZE_ADDRESS; NOT WITH_SANITIZE_THREAD" OFF) - CMAKE_DEPENDENT_OPTION(WITH_SANITIZE_THREAD "Compile with gcc/clang thread sanitizer." OFF - "NOT WITH_VALGRIND_MEMCHECK; NOT WITH_SANITIZE_ADDRESS; NOT WITH_SANITIZE_MEMORY" OFF) -else() +if(WIN32) if(NOT UWP) option(WITH_MEDIA_FOUNDATION "Enable H264 media foundation decoder." OFF) endif() diff --git a/cmake/ExportAllSymbols.cmake b/cmake/ExportAllSymbols.cmake new file mode 100644 index 000000000..ba0f92098 --- /dev/null +++ b/cmake/ExportAllSymbols.cmake @@ -0,0 +1,13 @@ +include(CheckAndSetFlag) + +option(EXPORT_ALL_SYMBOLS "Export all symbols form library" OFF) + +if (EXPORT_ALL_SYMBOLS) + add_compile_definitions(EXPORT_ALL_SYMBOLS) +else() + message(STATUS "${} default symbol visibility: hidden") + + CheckAndSetFlag(-fvisibility=hidden) +endif() + + diff --git a/rdtk/CMakeLists.txt b/rdtk/CMakeLists.txt index acab9e707..30951e914 100644 --- a/rdtk/CMakeLists.txt +++ b/rdtk/CMakeLists.txt @@ -32,15 +32,9 @@ if (NOT FREERDP_UNIFIED_BUILD) set(CMAKE_C_EXTENSIONS ON) set(WINPR_VERSION_MAJOR 3) - option(EXPORT_ALL_SYMBOLS "Export all symbols form library" OFF) option(BUILD_TESTING_INTERNAL "Build library unit tests" ON) - if(CMAKE_COMPILER_IS_GNUCC) - if(NOT EXPORT_ALL_SYMBOLS) - message(STATUS "GCC default symbol visibility: hidden") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") - endif() - endif() + include(ExportAllSymbols) else() set(WINPR_VERSION_MAJOR ${FREERDP_VERSION_MAJOR}) endif() diff --git a/scripts/blacklist-address-sanitizer.txt b/scripts/blacklist-address-sanitizer.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/scripts/blacklist-memory-sanitizer.txt b/scripts/blacklist-memory-sanitizer.txt deleted file mode 100644 index 9a05abbdb..000000000 --- a/scripts/blacklist-memory-sanitizer.txt +++ /dev/null @@ -1 +0,0 @@ -fun:RAND* diff --git a/scripts/blacklist-thread-sanitizer.txt b/scripts/blacklist-thread-sanitizer.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/uwac/CMakeLists.txt b/uwac/CMakeLists.txt index cf39b9487..139dfa33a 100644 --- a/uwac/CMakeLists.txt +++ b/uwac/CMakeLists.txt @@ -31,15 +31,9 @@ if (NOT FREERDP_UNIFIED_BUILD) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS ON) - option(EXPORT_ALL_SYMBOLS "Export all symbols form library" OFF) option(BUILD_TESTING_INTERNAL "Build library unit tests" ON) - if(CMAKE_COMPILER_IS_GNUCC) - if(NOT EXPORT_ALL_SYMBOLS) - message(STATUS "GCC default symbol visibility: hidden") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") - endif() - endif() + include(ExportAllSymbols) endif() option(UWAC_FORCE_STATIC_BUILD "Force UWAC to be build as static libary (recommended)" OFF) diff --git a/winpr/CMakeLists.txt b/winpr/CMakeLists.txt index 8b387d29d..2fed1f88e 100644 --- a/winpr/CMakeLists.txt +++ b/winpr/CMakeLists.txt @@ -39,19 +39,7 @@ if (NOT FREERDP_UNIFIED_BUILD) endif() # Default to build shared libs - option(EXPORT_ALL_SYMBOLS "Export all symbols form library" OFF) - - if (EXPORT_ALL_SYMBOLS) - # set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) - add_compile_definitions(EXPORT_ALL_SYMBOLS) - endif() - - if(CMAKE_COMPILER_IS_GNUCC) - if(NOT EXPORT_ALL_SYMBOLS) - message(STATUS "GCC default symbol visibility: hidden") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") - endif() - endif() + include(ExportAllSymbols) if(WITH_DEBUG_ALL) message(WARNING "WITH_DEBUG_ALL=ON, the build will be slow and might leak sensitive information, do not use with release builds!") set(DEFAULT_DEBUG_OPTION "ON" CACHE INTERNAL "debug default")