basic project
This commit is contained in:
52
cmake/CompilerFlags.cmake
Normal file
52
cmake/CompilerFlags.cmake
Normal file
@@ -0,0 +1,52 @@
|
||||
|
||||
# Core compile arguments used for the whole native project
|
||||
|
||||
if(NOT TV2HV_LINKER)
|
||||
message(FATAL_ERROR "Somehow we got here without a set TV2HV_LINKER, bailing.")
|
||||
endif()
|
||||
|
||||
# This isn't really the best place to put this, but it's probably the only one which makes sense.
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
# TODO: Use a list so that this isn't one giant line, and we can just append compile flags to it as needed
|
||||
set(TV2HV_CORE_COMPILE_ARGS "-Wall -Wno-builtin-declaration-mismatch -Wformat=2 -fstrict-flex-arrays=3 -fstack-clash-protection -fstack-protector-strong")
|
||||
set(TV2HV_CORE_LINKER_ARGS "-fuse-ld=${TV2HV_LINKER}")
|
||||
|
||||
if("${CMAKE_BUILD_TYPE}" STREQUAL "Release" OR "${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
|
||||
# Disable C assert() in release builds (needed since we wipe cmake core args) and enable FORTIFY_SOURCE
|
||||
set(TV2HV_CORE_COMPILE_ARGS "${TV2HV_CORE_COMPILE_ARGS} -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -DNDEBUG")
|
||||
|
||||
# If on Release and we are prompted to use link-time optimizations do so
|
||||
if("lto" IN_LIST TV2HV_BUILD_FEATURES)
|
||||
# On clang we use ThinLTO for even better build performance.
|
||||
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
message(STATUS "CompilerFlags: Using LLVM ThinLTO")
|
||||
set(TV2HV_CORE_COMPILE_ARGS "${TV2HV_CORE_COMPILE_ARGS} -flto=thin")
|
||||
set(TV2HV_CORE_LINKER_ARGS "${TV2HV_CORE_LINKER_ARGS} -flto=thin")
|
||||
else()
|
||||
message(STATUS "CompilerFlags: Using LTO")
|
||||
set(TV2HV_CORE_COMPILE_ARGS "${TV2HV_CORE_COMPILE_ARGS} -flto")
|
||||
set(TV2HV_CORE_LINKER_ARGS "${TV2HV_CORE_LINKER_ARGS} -flto")
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
include(SanitizerSetup)
|
||||
|
||||
# Set core CMake toolchain variables so that they get applied to all projects.
|
||||
# A bit nasty, but /shrug, this way our third party libraries can be mostly sanitized/etc as well.
|
||||
#
|
||||
# Note that -g3 in release flags is temporary, and will be removed once we don't need it
|
||||
|
||||
set(CMAKE_C_FLAGS "${TV2HV_CORE_COMPILE_ARGS}")
|
||||
set(CMAKE_CXX_FLAGS "${TV2HV_CORE_COMPILE_ARGS}")
|
||||
|
||||
set(CMAKE_C_FLAGS_DEBUG "-O0 -g3")
|
||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g3")
|
||||
set(CMAKE_C_FLAGS_RELEASE "-O3 -g3")
|
||||
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")
|
||||
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g3")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g3")
|
||||
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${TV2HV_CORE_LINKER_ARGS} -Wl,-z,noexecstack,-z,relro,-z,now")
|
||||
1
cmake/Options.cmake
Normal file
1
cmake/Options.cmake
Normal file
@@ -0,0 +1 @@
|
||||
# Common place for CMake options
|
||||
22
cmake/Policies.cmake
Normal file
22
cmake/Policies.cmake
Normal file
@@ -0,0 +1,22 @@
|
||||
# CMake policy configuration
|
||||
|
||||
# Macro to enable new CMake policy.
|
||||
# Makes this file a *LOT* shorter.
|
||||
macro (_new_cmake_policy policy)
|
||||
if(POLICY ${policy})
|
||||
#message(STATUS "Enabling new policy ${policy}")
|
||||
cmake_policy(SET ${policy} NEW)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
_new_cmake_policy(CMP0026) # CMake 3.0: Disallow use of the LOCATION property for build targets.
|
||||
_new_cmake_policy(CMP0042) # CMake 3.0+ (2.8.12): MacOS "@rpath" in target's install name
|
||||
_new_cmake_policy(CMP0046) # warn about non-existent dependencies
|
||||
_new_cmake_policy(CMP0048) # CMake 3.0+: project() command now maintains VERSION
|
||||
_new_cmake_policy(CMP0054) # CMake 3.1: Only interpret if() arguments as variables or keywords when unquoted.
|
||||
_new_cmake_policy(CMP0056) # try_compile() linker flags
|
||||
_new_cmake_policy(CMP0066) # CMake 3.7: try_compile(): use per-config flags, like CMAKE_CXX_FLAGS_RELEASE
|
||||
_new_cmake_policy(CMP0067) # CMake 3.8: try_compile(): honor language standard variables (like C++11)
|
||||
_new_cmake_policy(CMP0068) # CMake 3.9+: `RPATH` settings on macOS do not affect `install_name`.
|
||||
_new_cmake_policy(CMP0075) # CMake 3.12+: Include file check macros honor `CMAKE_REQUIRED_LIBRARIES`
|
||||
_new_cmake_policy(CMP0077) # CMake 3.13+: option() honors normal variables.
|
||||
27
cmake/ProjectFuncs.cmake
Normal file
27
cmake/ProjectFuncs.cmake
Normal file
@@ -0,0 +1,27 @@
|
||||
function(tv2hv_target target)
|
||||
target_compile_definitions(${target} PRIVATE "$<$<CONFIG:DEBUG>:TV2HV_DEBUG>")
|
||||
#target_include_directories(${target} PRIVATE ${PROJECT_SOURCE_DIR})
|
||||
target_compile_features(${target} PRIVATE cxx_std_23)
|
||||
target_include_directories(${target} PRIVATE ${PROJECT_SOURCE_DIR}/src/lib ${CMAKE_CURRENT_BINARY_DIR})
|
||||
endfunction()
|
||||
|
||||
function(_tv2hv_set_alternate_linker)
|
||||
find_program(LINKER_EXECUTABLE ld.${TV2HV_LINKER} ${TV2HV_LINKER})
|
||||
if(LINKER_EXECUTABLE)
|
||||
message(STATUS "Using ${TV2HV_LINKER} as linker")
|
||||
else()
|
||||
message(FATAL_ERROR "Linker ${TV2HV_LINKER} does not exist on your system. Please specify one which does or omit this option from your configure command.")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
# Set a default linker if the user never provided one.
|
||||
# This defaults based on the detected compiler to the "best" linker possible
|
||||
if(NOT TV2HV_LINKER AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
set(TV2HV_LINKER "lld")
|
||||
elseif(NOT TV2HV_LINKER)
|
||||
set(TV2HV_LINKER "bfd")
|
||||
endif()
|
||||
|
||||
# Do the magic
|
||||
_tv2hv_set_alternate_linker()
|
||||
34
cmake/SanitizerSetup.cmake
Normal file
34
cmake/SanitizerSetup.cmake
Normal file
@@ -0,0 +1,34 @@
|
||||
set(_TV2HV_CORE_WANTED_SANITIZERS "")
|
||||
|
||||
if("asan" IN_LIST TV2HV_BUILD_FEATURES)
|
||||
# Error if someone's trying to mix asan and tsan together,
|
||||
# they aren't compatible.
|
||||
if("tsan" IN_LIST TV2HV_BUILD_FEATURES)
|
||||
message(FATAL_ERROR "ASAN and TSAN cannot be used together.")
|
||||
endif()
|
||||
|
||||
message(STATUS "Enabling ASAN because it was in TV2HV_BUILD_FEATURES")
|
||||
list(APPEND _TV2HV_CORE_WANTED_SANITIZERS "address")
|
||||
endif()
|
||||
|
||||
if("tsan" IN_LIST TV2HV_BUILD_FEATURES)
|
||||
if("asan" IN_LIST TV2HV_BUILD_FEATURES)
|
||||
message(FATAL_ERROR "ASAN and TSAN cannot be used together.")
|
||||
endif()
|
||||
|
||||
message(STATUS "Enabling TSAN because it was in TV2HV_BUILD_FEATURES")
|
||||
list(APPEND _TV2HV_CORE_WANTED_SANITIZERS "thread")
|
||||
endif()
|
||||
|
||||
if("ubsan" IN_LIST TV2HV_BUILD_FEATURES)
|
||||
message(STATUS "Enabling UBSAN because it was in TV2HV_BUILD_FEATURES")
|
||||
list(APPEND _TV2HV_CORE_WANTED_SANITIZERS "undefined")
|
||||
endif()
|
||||
|
||||
list(LENGTH _TV2HV_CORE_WANTED_SANITIZERS _TV2HV_CORE_WANTED_SANITIZERS_LENGTH)
|
||||
if(NOT _TV2HV_CORE_WANTED_SANITIZERS_LENGTH EQUAL 0)
|
||||
list(JOIN _TV2HV_CORE_WANTED_SANITIZERS "," _TV2HV_CORE_WANTED_SANITIZERS_ARG)
|
||||
message(STATUS "Enabled sanitizers: ${_TV2HV_CORE_WANTED_SANITIZERS_ARG}")
|
||||
set(TV2HV_CORE_COMPILE_ARGS "${TV2HV_CORE_COMPILE_ARGS} -fsanitize=${_TV2HV_CORE_WANTED_SANITIZERS_ARG}")
|
||||
set(TV2HV_CORE_LINKER_ARGS "${TV2HV_CORE_LINKER_ARGS} -fsanitize=${_TV2HV_CORE_WANTED_SANITIZERS_ARG}")
|
||||
endif()
|
||||
Reference in New Issue
Block a user