- if(CMAKE_COMPILER_IS_GNUCC AND (NOT enable_model-checking))
- set(optCFLAGS "${optCFLAGS} -finline-functions ")
- if(WIN32)
- if (COMPILER_C_VERSION_MAJOR_MINOR STRGREATER "4.8")
- # On windows, we need 4.8 or higher to enable lto because of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50293
- #
- # We are experiencing assertion failures even with 4.8 on MinGW.
- # Push the support forward: will see if 4.9 works when we test it.
- set(optCFLAGS "${optCFLAGS} -flto ")
- endif()
- else()
- # On non-windows, 4.6 is enough for that
- if(LINKER_VERSION STRGREATER "2.22")
- set(optCFLAGS "${optCFLAGS} -flto ")
+else()
+ set(optCFLAGS "-O0 ")
+endif()
+
+#ARM platforms have signed char by default, switch to unsigned for consistancy
+if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
+ set(optCFLAGS "${optCFLAGS} -fsigned-char")
+endif()
+
+if(enable_compile_optimizations AND CMAKE_COMPILER_IS_GNUCC
+ AND (NOT enable_model-checking))
+ # This is redundant (already in -03):
+ set(optCFLAGS "${optCFLAGS} -finline-functions ")
+endif()
+
+# Do not leak the current directory into the binaries
+if(CMAKE_COMPILER_IS_GNUCC AND NOT enable_coverage)
+ if (CMAKE_VERSION VERSION_LESS "3.20")
+ file(RELATIVE_PATH RELATIVE_SOURCE_DIR ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR})
+ else() # cmake >= 3.20
+ cmake_path(RELATIVE_PATH CMAKE_SOURCE_DIR BASE_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_VARIABLE RELATIVE_SOURCE_DIR)
+ endif()
+ message(STATUS "Relative source directory is \"${RELATIVE_SOURCE_DIR}\".")
+ if (CMAKE_C_COMPILER_VERSION VERSION_LESS "8.0")
+ set(optCFLAGS "${optCFLAGS} -fdebug-prefix-map=\"${CMAKE_SOURCE_DIR}=${RELATIVE_SOURCE_DIR}\"")
+ else()
+ set(optCFLAGS "${optCFLAGS} -ffile-prefix-map=\"${CMAKE_SOURCE_DIR}=${RELATIVE_SOURCE_DIR}\"")
+ endif()
+endif()
+
+# Configure LTO
+if(enable_lto) # User wants LTO. Try if we can do that
+ set(enable_lto OFF)
+ if(enable_compile_optimizations
+ AND (NOT enable_model-checking))
+ include(CheckIPOSupported)
+ check_ipo_supported(RESULT ipo LANGUAGES C CXX)
+ if(ipo)
+ set(enable_lto ON)
+ endif()
+ endif()
+
+ if(enable_lto)
+ message(STATUS "LTO seems usable.")
+ else()
+ if(NOT enable_compile_optimizations)
+ message(STATUS "LTO disabled: Compile-time optimizations turned off.")
+ else()
+ if(enable_model-checking)
+ message(STATUS "LTO disabled when compiling with model-checking.")
+ else()
+ message(STATUS "LTO does not seem usable -- try updating your build chain.")