cmake/nc_cxx.cmake

109 lines
3.6 KiB
CMake

###############################################################################
if (__nc_cxx)
return ()
endif ()
set (__nc_cxx TRUE)
###############################################################################
# clear the default flags because they include optimisation flags we
# explicitly do not want (ie, O3).
set (CMAKE_CXX_FLAGS_RELEASE "")
set (CMAKE_C_FLAGS_RELEASE "")
set (CMAKE_CXX_FLAGS_DEBUG "")
set (CMAKE_C_FLAGS_DEBUG "")
###############################################################################
include ("${CMAKE_CURRENT_LIST_DIR}/compile_flag.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/link_flag.cmake")
include ("${CMAKE_CURRENT_LIST_DIR}/test_restrict.cmake")
###############################################################################
append_compile_flag ("-fdiagnostics-color=auto")
###############################################################################
append_compile_flag ("-std=c++2b")
append_compile_flag ("-fpermissive")
append_compile_flag ("/std:c++latest")
###############################################################################
# STDLIB must be set after this block.
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(STDLIB "libc++")
append_compile_flag ("-stdlib=${STDLIB}")
append_link_flag ("-fuse-ld=lld")
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(STDLIB "libstdc++")
append_link_flag ("-fuse-ld=gold")
else()
message(FATAL_ERROR "Unknown CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
endif()
###############################################################################
# find the gcc or clang filesystem library and append to libs if needed
#
# note, we specifically _cannot_ use find_library because it just makes wild
# hardcoded guess and doesn't respect _all_ the system paths; specifically
# something like /usr/lib/gcc/x86_64-pc-linux-gnu/6.3.0/libstdc++.so won't get
# discovered.
#if (NOT DEFINED __nc_cxx_stdcxxfs)
# foreach(lib "" "c++fs" "c++experimental" "stdc++fs")
# message (STATUS "Trying c++fs library '${lib}'")
# try_compile(
# __nc_cxx_stdcxxfs ${CMAKE_CURRENT_BINARY_DIR}
# SOURCES
# ${CMAKE_CURRENT_LIST_DIR}/nc_cxx_stdcxxfs.cpp
# LINK_LIBRARIES
# ${lib}
# )
#
# if (__nc_cxx_stdcxxfs)
# set (__nc_cxx_stdcxxfs "${lib}" CACHE INTERNAL "library required for c++ filesystem")
# break ()
# endif ()
# endforeach()
#
# if (NOT DEFINED __nc_cxx_stdcxxfs)
# message (FATAL_ERROR "Could not locate the required c++fs library")
# endif ()
#
# message (STATUS "Using c++fs library ${__nc_cxx_stdcxxfs}")
#endif ()
set(NC_CXX_STDCXXFS ${__nc_cxx_stdcxxfs})
###############################################################################
test_restrict(RESTRICT_KEYWORD)
add_definitions("-Drestrict=${RESTRICT_KEYWORD}")
###############################################################################
append_compile_flag("-pipe")
append_compile_flag("-fno-deduce-init-list")
append_compile_flag("-fvisibility=hidden")
append_compile_flag("-fvisibility-inlines-hidden")
append_compile_flag("-fPIC")
# Clang doesn't enabled sized deallocation (__cpp_sized_deallocation) by
# default, at least by clang-15, so we have to enable it explicitly.
append_compile_flag("-fsized-deallocation")
# We want a build-id so that we can attribute minidumps
append_link_flag("-Wl,--build-id")
# breakpad:XXX Our supported versions of breakpad crash when dumping symbols
# from a DWARF5 binary. Just drop to DWARF4 for the moment.
append_compile_flag("-gdwarf-4")
append_compile_flag("-D__STDC_FORMAT_MACROS")
add_definitions("-D_FILE_OFFSET_BITS=64")