Newer
Older
Bryan O'Sullivan
committed
# -*- cmake -*-
#
# Compilation options shared by all Second Life components.
#*****************************************************************************
# It's important to realize that CMake implicitly concatenates
# CMAKE_CXX_FLAGS with (e.g.) CMAKE_CXX_FLAGS_RELEASE for Release builds. So
# set switches in CMAKE_CXX_FLAGS that should affect all builds, but in
# CMAKE_CXX_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELWITHDEBINFO for switches
# that should affect only that build variant.
#
# Also realize that CMAKE_CXX_FLAGS may already be partially populated on
# entry to this file.
#*****************************************************************************
include_guard()
Bryan O'Sullivan
committed
include(Variables)
Bryan O'Sullivan
committed
# Portable compilation flags.
add_compile_definitions(
ADDRESS_SIZE=${ADDRESS_SIZE}
$<$<CONFIG:Debug>:_DEBUG>
$<$<CONFIG:Debug>:LL_DEBUG=1>
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:LL_RELEASE=1>
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:NDEBUG>
$<$<CONFIG:RelWithDebInfo>:LL_RELEASE_WITH_DEBUG_INFO=1>
$<$<CONFIG:Release>:LL_RELEASE_FOR_DOWNLOAD=1>
# Configure crash reporting
set(RELEASE_CRASH_REPORTING OFF CACHE BOOL "Enable use of crash reporting in release builds")
set(NON_RELEASE_CRASH_REPORTING OFF CACHE BOOL "Enable use of crash reporting in developer builds")
Bryan O'Sullivan
committed
if(RELEASE_CRASH_REPORTING)
add_compile_definitions( LL_SEND_CRASH_REPORTS=1)
endif()
if(NON_RELEASE_CRASH_REPORTING)
add_compile_definitions( LL_SEND_CRASH_REPORTS=1)
endif()
Bryan O'Sullivan
committed
# Don't bother with a MinSizeRel build.
Bryan O'Sullivan
committed
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo;Release;Debug" CACHE STRING
"Supported build types." FORCE)
# SIMD config
option(USE_AVX2 "Enable usage of the AVX2 instruction set" OFF)
option(USE_AVX "Enable usage of the AVX instruction set" OFF)
option(USE_SSE42 "Enable usage of the SSE4.2 instruction set" ON)
Bryan O'Sullivan
committed
# Warnings
option(DISABLE_FATAL_WARNINGS "Disable warnings as errors" ON)
if(USE_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${USE_LTO})
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_C_VISIBILITY_PRESET "hidden")
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
Bryan O'Sullivan
committed
# Platform-specific compilation flags.
if (WINDOWS)
# Don't build DLLs.
set(BUILD_SHARED_LIBS OFF)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
Bryan O'Sullivan
committed
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options(/MP)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options(-m${ADDRESS_SIZE})
add_compile_definitions(
$<$<CONFIG:Debug>:_SCL_SECURE_NO_WARNINGS=1>
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:_ITERATOR_DEBUG_LEVEL=0>
LL_WINDOWS=1
NOMINMAX
UNICODE
_UNICODE
_CRT_SECURE_NO_WARNINGS
_CRT_NONSTDC_NO_DEPRECATE
_WINSOCK_DEPRECATED_NO_WARNINGS
_SILENCE_CXX20_CISO646_REMOVED_WARNING
)
add_compile_options(
$<$<CONFIG:Release>:/Zc:inline>
$<$<CONFIG:Release>:/fp:fast>
/Zi
/EHsc
/permissive-
add_link_options(
/DEBUG:FULL
/IGNORE:4099
)
if (ADDRESS_SIZE EQUAL 32)
add_compile_options(/arch:SSE2)
elseif (USE_AVX2)
add_compile_options(/arch:AVX2)
elseif (USE_AVX)
add_compile_options(/arch:AVX)
elseif (USE_SSE42)
add_compile_definitions(__SSE3__=1 __SSSE3__=1 __SSE4__=1 __SSE4_1__=1 __SSE4_2__=1)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options(/Zc:externConstexpr /ZH:SHA_256)
elseif("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options(/Qvec /Zc:dllexportInlines- /clang:-mprefer-vector-width=128 -fno-strict-aliasing -Wno-ignored-pragma-intrinsic -Wno-unused-local-typedef)
endif()
Mark Palange (Mani)
committed
if(FAVOR_AMD AND FAVOR_INTEL)
message(FATAL_ERROR "Cannot enable FAVOR_AMD and FAVOR_INTEL at the same time")
elseif(FAVOR_AMD)
add_compile_options(/favor:AMD64)
elseif(FAVOR_INTEL)
add_compile_options(/favor:INTEL64)
endif()
add_link_options(
$<$<CONFIG:Release>:/OPT:REF>
$<$<CONFIG:Release>:/OPT:ICF>
)
add_link_options($<$<CONFIG:Release>:/INCREMENTAL>)
add_link_options(
$<$<CONFIG:Release>:/OPT:REF>
$<$<CONFIG:Release>:/OPT:ICF>
$<$<CONFIG:Release>:/INCREMENTAL:NO>
)
endif ()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# This is a massive hack and makes me sad. clang-cl fails to find its own builtins library :/ x64 only for now.
set(CLANG_RT_NAMES clang_rt.builtins-x86_64)
find_library(CLANG_RT NAMES ${CLANG_RT_NAMES}
PATHS [HKEY_LOCAL_MACHINE\\SOFTWARE\\LLVM\\LLVM]/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/windows
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\LLVM\\LLVM]/lib/clang/${CMAKE_CXX_COMPILER_VERSION}/lib/windows)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /defaultlib:\"${CLANG_RT}\"")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /defaultlib:\"${CLANG_RT}\"")
endif()
Bryan O'Sullivan
committed
string(REPLACE "/Ob2" "/Ob3" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
string(REPLACE "/Ob2" "/Ob3" CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE})
# configure win32 API for 10 and above compatibility
set(WINVER "0x0A00" CACHE STRING "Win32 API Target version (see http://msdn.microsoft.com/en-us/library/aa383745%28v=VS.85%29.aspx)")
add_compile_definitions(WINVER=${WINVER} _WIN32_WINNT=${WINVER})
Bryan O'Sullivan
committed
endif (WINDOWS)
if (LINUX)
set(CMAKE_SKIP_BUILD_RPATH TRUE)
Bryan O'Sullivan
committed
add_compile_definitions(
LL_LINUX=1
APPID=secondlife
LL_IGNORE_SIGCHLD
_REENTRANT
$<$<CONFIG:Release>:_FORTIFY_SOURCE=2>
)
add_compile_options(
$<$<OR:$<CONFIG:Release>,$<CONFIG:RelWithDebInfo>>:-fstack-protector>
-fexceptions
-fno-math-errno
-fno-strict-aliasing
add_compile_options(-mfpmath=sse -msse -msse2 -msse3 -mssse3 -msse4 -msse4.1 -msse4.2)
add_compile_options(-mfpmath=sse -msse -msse2 -msse3 -mssse3 -msse4 -msse4.1)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if (USE_ASAN)
add_compile_options(-fsanitize=address -fsanitize-recover=address)
elseif (USE_LEAKSAN)
add_compile_options(-fsanitize=leak)
elseif (USE_UBSAN)
add_compile_options(-fsanitize=undefined -fno-sanitize=vptr)
elseif (USE_THDSAN)
add_compile_options(-fsanitize=thread)
add_compile_options(-O3)
# Enable these flags so we have a read only GOT and some linking opts
add_link_options("LINKER:-z,relro" "LINKER:-z,now" "LINKER:--as-needed" "LINKER:--build-id=uuid")
Bryan O'Sullivan
committed
if (DARWIN)
add_compile_definitions(LL_DARWIN=1 GL_SILENCE_DEPRECATION=1)
add_link_options("LINKER:-headerpad_max_install_names" "LINKER:-search_paths_first" "LINKER:-dead_strip")
add_compile_options(
-O3
-gdwarf-2
-fno-strict-aliasing
-msse4.2
$<$<COMPILE_LANGUAGE:OBJCXX>:-fobjc-arc>
Bryan O'Sullivan
committed
if (LINUX OR DARWIN)
add_compile_options(-Wall -Wno-sign-compare -Wno-reorder)
add_compile_options(-Wno-unused-parameter -Wno-unused-but-set-parameter -Wno-ignored-qualifiers -Wno-unused-function)
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
add_compile_options(-Wno-trigraphs -Wno-unused-local-typedef -Wno-unknown-warning-option -Wno-shorten-64-to-32)
endif()
Bryan O'Sullivan
committed
CHECK_CXX_COMPILER_FLAG(-Wdeprecated-copy HAS_DEPRECATED_COPY)
if (HAS_DEPRECATED_COPY)
Bryan O'Sullivan
committed
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
add_compile_options(-Wno-unused-but-set-variable -Wno-unused-variable )
add_compile_options(-m${ADDRESS_SIZE})
option(RELEASE_SHOW_ASSERTS "Enable asserts in release builds" OFF)
if(RELEASE_SHOW_ASSERTS)
add_compile_definitions(RELEASE_SHOW_ASSERT=1)
option(ENABLE_TIMING "Enable all fast timers" ON)
if(ENABLE_TIMING)
add_compile_definitions(AL_ENABLE_ALL_TIMERS=1)