2019-04-26 18:27:27 +03:00
|
|
|
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
# Licensed under the Apache 2.0 License.
|
|
|
|
|
2020-01-28 21:09:42 +03:00
|
|
|
# Note: this needs to be done before project(), otherwise CMAKE_*_COMPILER is
|
2020-04-16 13:31:04 +03:00
|
|
|
# already set by CMake. If the user has not expressed any choice, we attempt to
|
2023-04-19 17:42:34 +03:00
|
|
|
# default to Clang >= 11. If they have expressed even a partial choice, the
|
|
|
|
# usual CMake selection logic applies. If we cannot find both a suitable clang
|
|
|
|
# and a suitable clang++, the usual CMake selection logic applies
|
2020-01-28 21:09:42 +03:00
|
|
|
if((NOT CMAKE_C_COMPILER)
|
|
|
|
AND (NOT CMAKE_CXX_COMPILER)
|
|
|
|
AND "$ENV{CC}" STREQUAL ""
|
|
|
|
AND "$ENV{CXX}" STREQUAL ""
|
|
|
|
)
|
2024-08-16 13:43:28 +03:00
|
|
|
find_program(FOUND_CMAKE_C_COMPILER NAMES clang-15)
|
|
|
|
find_program(FOUND_CMAKE_CXX_COMPILER NAMES clang++-15)
|
2020-01-28 21:09:42 +03:00
|
|
|
if(NOT (FOUND_CMAKE_C_COMPILER AND FOUND_CMAKE_CXX_COMPILER))
|
|
|
|
message(
|
|
|
|
WARNING
|
2023-04-19 17:42:34 +03:00
|
|
|
"Clang 11 or Clang 15 not found, will use default compiler. "
|
2020-01-28 21:09:42 +03:00
|
|
|
"Override the compiler by setting CC and CXX environment variables."
|
|
|
|
)
|
2019-04-26 18:27:27 +03:00
|
|
|
else()
|
2020-01-28 21:09:42 +03:00
|
|
|
# CMAKE_*_COMPILER can only be set once, and cannot be unset, we either want
|
|
|
|
# both, or none at all.
|
2019-04-26 18:27:27 +03:00
|
|
|
set(CMAKE_C_COMPILER "${FOUND_CMAKE_C_COMPILER}")
|
|
|
|
set(CMAKE_CXX_COMPILER "${FOUND_CMAKE_CXX_COMPILER}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2020-01-28 21:09:42 +03:00
|
|
|
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
|
2023-04-19 17:42:34 +03:00
|
|
|
if(CMAKE_C_COMPILER_VERSION VERSION_LESS 11)
|
|
|
|
message(WARNING "CCF officially supports Clang >= 11 only, "
|
2020-01-28 21:09:42 +03:00
|
|
|
"but your Clang version (${CMAKE_C_COMPILER_VERSION}) "
|
|
|
|
"is older than that. Build problems may occur."
|
|
|
|
)
|
|
|
|
endif()
|
2019-04-26 18:27:27 +03:00
|
|
|
endif()
|
|
|
|
|
2020-04-09 14:01:39 +03:00
|
|
|
# Build Release by default, with debug info
|
|
|
|
set(default_build_type "RelWithDebInfo")
|
|
|
|
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
|
|
message(
|
|
|
|
STATUS
|
|
|
|
"Setting build type to '${default_build_type}' as none was specified."
|
|
|
|
)
|
|
|
|
set(CMAKE_BUILD_TYPE
|
|
|
|
"${default_build_type}"
|
|
|
|
CACHE STRING "Choose the type of build." FORCE
|
|
|
|
)
|
|
|
|
set_property(
|
|
|
|
CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel"
|
|
|
|
"RelWithDebInfo"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2024-01-08 12:41:08 +03:00
|
|
|
option(TSAN "Enable Thread Sanitizers" OFF)
|
|
|
|
|
2023-05-22 15:53:13 +03:00
|
|
|
option(COLORED_OUTPUT "Always produce ANSI-colored output." ON)
|
2020-04-16 13:31:04 +03:00
|
|
|
|
|
|
|
if(${COLORED_OUTPUT})
|
2023-05-22 15:53:13 +03:00
|
|
|
add_compile_options(-fcolor-diagnostics)
|
2020-04-16 13:31:04 +03:00
|
|
|
endif()
|
|
|
|
|
2020-07-21 18:08:25 +03:00
|
|
|
function(add_warning_checks name)
|
|
|
|
target_compile_options(
|
2021-04-01 19:27:55 +03:00
|
|
|
${name}
|
|
|
|
PRIVATE -Wall
|
|
|
|
-Wextra
|
|
|
|
-Werror
|
|
|
|
-Wundef
|
|
|
|
-Wpedantic
|
|
|
|
-Wno-unused
|
|
|
|
-Wno-unused-parameter
|
2023-07-13 22:40:46 +03:00
|
|
|
-Wshadow
|
2020-07-21 18:08:25 +03:00
|
|
|
)
|
|
|
|
endfunction()
|
|
|
|
|
2023-03-14 16:09:34 +03:00
|
|
|
set(SPECTRE_MITIGATION_FLAGS -mllvm -x86-speculative-load-hardening)
|
|
|
|
if("${COMPILE_TARGET}" STREQUAL "snp")
|
|
|
|
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
|
|
|
|
add_compile_options(${SPECTRE_MITIGATION_FLAGS})
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2023-12-08 16:29:37 +03:00
|
|
|
if("${COMPILE_TARGET}" STREQUAL "snp" OR "${COMPILE_TARGET}" STREQUAL "virtual")
|
2024-01-08 12:41:08 +03:00
|
|
|
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND NOT TSAN)
|
2023-12-08 16:29:37 +03:00
|
|
|
add_compile_options(-flto)
|
|
|
|
endif()
|
2024-07-10 20:08:53 +03:00
|
|
|
# Unconditionally make linker aware of possible LTO happening. Otherwise
|
|
|
|
# targets built in Debug and linked against this will fail linkage.
|
|
|
|
add_link_options(-flto)
|
2023-12-08 16:29:37 +03:00
|
|
|
endif()
|
|
|
|
|
2021-08-04 16:59:09 +03:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|