-if(enable_model-checking AND enable_compile_optimizations)
- # Forget it, do not optimize the code (because it confuses the MC):
- set(optCFLAGS "-O0 ")
- # But you can still optimize this:
- foreach(s
- src/xbt/mmalloc/mm.c
- src/xbt/log.c src/xbt/xbt_log_appender_file.c
- src/xbt/xbt_log_layout_format.c src/xbt/xbt_log_layout_simple.c
- src/xbt/dict.c src/xbt/dict_elm.c src/xbt/dict_multi.c src/xbt/dict_cursor.c
- src/xbt/set.c src/xbt/setset.c
- src/xbt/dynar.c src/xbt/fifo.c src/xbt/heap.c src/xbt/swag.c
- src/xbt/str.c src/xbt/strbuff.c src/xbt/snprintf.c
- src/xbt/queue.c
- src/xbt/xbt_os_time.c src/xbt/xbt_os_thread.c
- src/xbt/sha.c
- src/xbt/matrix.c
- src/xbt/backtrace_linux.c
- ${MC_SRC_BASE} ${MC_SRC})
- set (mcCFLAGS "-O3 -funroll-loops -fno-strict-aliasing")
- if(CMAKE_COMPILER_IS_GNUCC)
- set (mcCFLAGS "${mcCFLAGS} -finline-functions")
- endif()
- set_source_files_properties(${s} PROPERTIES COMPILE_FLAGS ${mcCFLAGS})
- endforeach()
+# 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)
+ 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()
+ message(STATUS "LTO does not seem usable -- try updating your build chain.")
+ endif()
+ endif()
+else()
+ message(STATUS "LTO disabled on the command line.")
+endif()
+if(enable_lto) # User wants LTO, and it seems usable. Go for it
+ set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+ if(LTO_EXTRA_FLAG AND CMAKE_COMPILER_IS_GNUCC)
+ list(APPEND CMAKE_C_COMPILE_OPTIONS_IPO "-flto=${LTO_EXTRA_FLAG}")
+ list(APPEND CMAKE_CXX_COMPILE_OPTIONS_IPO "-flto=${LTO_EXTRA_FLAG}")
+ endif()
+
+ # Activate fat-lto-objects in case LD and gfortran differ too much.
+ # Only test with GNU as it's the only case I know (clang+gfortran+lld)
+ execute_process(COMMAND ${CMAKE_LINKER} -v OUTPUT_VARIABLE LINKER_ID ERROR_VARIABLE LINKER_ID)
+ string(REGEX MATCH "GNU" LINKER_ID "${LINKER_ID}")
+ if(${CMAKE_Fortran_COMPILER_ID} MATCHES "GNU"
+ AND NOT "${LINKER_ID}" MATCHES "GNU")
+ list(APPEND CMAKE_Fortran_COMPILE_OPTIONS_IPO "-ffat-lto-objects")
+ endif()
+
+ # "Since version 4.9 gcc produces slim object files that only contain
+ # the intermediate representation. In order to handle archives of
+ # these objects you have to use the gcc wrappers:
+ # gcc-ar, gcc-nm and gcc-ranlib."
+ if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU"
+ AND CMAKE_C_COMPILER_VERSION VERSION_GREATER "4.8")
+ set (CMAKE_AR gcc-ar)
+ set (CMAKE_RANLIB gcc-ranlib)
+ endif()
+endif()
+
+if (CMAKE_C_COMPILER_ID MATCHES "Intel")
+ # honor parentheses when determining the order of expression evaluation.
+ # disallow optimizations for floating-point arithmetic with Nans or +-Infs (breaks Eigen3)
+ set(optCFLAGS "${optCFLAGS} -fprotect-parens -fno-finite-math-only")