2016-11-03 12:06:33 +00:00
|
|
|
#
|
|
|
|
# Core setup
|
|
|
|
#
|
2017-01-26 16:17:02 +00:00
|
|
|
|
2016-11-03 12:06:33 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 14)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2017-01-26 16:17:02 +00:00
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
|
2016-11-03 12:06:33 +00:00
|
|
|
# Export compile commands used for custom targets
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
|
|
# Set default build type if not specified
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
2018-12-23 21:38:05 +00:00
|
|
|
set(CMAKE_BUILD_TYPE "Release")
|
|
|
|
message_colored(STATUS "No build type specified; using ${CMAKE_BUILD_TYPE}" 33)
|
2016-11-03 12:06:33 +00:00
|
|
|
endif()
|
2017-01-27 12:30:23 +00:00
|
|
|
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPER)
|
2016-11-03 12:06:33 +00:00
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
# Compiler flags
|
2016-11-03 12:06:33 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
|
2017-08-30 04:33:21 +00:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|
|
|
# there's no way to modify the code to avoid this warning, so we must
|
|
|
|
# suppress it if we use -Werror
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-noexcept-type")
|
|
|
|
endif()
|
2016-11-20 22:04:31 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
|
2017-01-13 12:17:11 +00:00
|
|
|
|
2018-03-21 22:35:10 +00:00
|
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
|
|
|
# Need dprintf() for FreeBSD 11.1 and older
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_WITH_DPRINTF")
|
|
|
|
# libinotify uses c99 extension, so suppress this error
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c99-extensions")
|
2018-03-21 23:03:47 +00:00
|
|
|
# Ensures that libraries from dependencies in LOCALBASE are used
|
2018-05-12 14:29:14 +00:00
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/lib")
|
2018-03-21 22:35:10 +00:00
|
|
|
endif()
|
|
|
|
|
2017-07-04 15:50:15 +00:00
|
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=parentheses-equality")
|
2018-03-21 22:35:10 +00:00
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-zero-length-array")
|
2017-07-04 15:50:15 +00:00
|
|
|
endif()
|
|
|
|
|
2018-11-21 17:46:33 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wno-error")
|
2016-11-03 12:06:33 +00:00
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG")
|
|
|
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g2")
|
|
|
|
|
2017-01-13 12:17:11 +00:00
|
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
|
|
|
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -fdata-sections -ffunction-sections")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} -Wl,--gc-sections,--icf=safe")
|
|
|
|
endif()
|
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
# Check compiler
|
|
|
|
if(${CMAKE_CXX_COMPILER_ID} STREQUAL Clang)
|
2016-12-21 23:40:45 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "3.4.0")
|
|
|
|
message_colored(FATAL_ERROR "Compiler not supported (Requires clang-3.4+ or gcc-5.1+)" 31)
|
|
|
|
else()
|
|
|
|
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}" 32)
|
|
|
|
endif()
|
2016-11-20 22:04:31 +00:00
|
|
|
elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
|
2016-12-21 23:40:45 +00:00
|
|
|
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.1.0")
|
|
|
|
message_colored(FATAL_ERROR "Compiler not supported (Requires clang-3.4+ or gcc-5.1+)" 31)
|
|
|
|
else()
|
|
|
|
message_colored(STATUS "Using supported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}" 32)
|
|
|
|
endif()
|
2016-11-03 12:06:33 +00:00
|
|
|
else()
|
2016-12-21 23:40:45 +00:00
|
|
|
message_colored(WARNING "Using unsupported compiler ${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION} !" 31)
|
2016-11-03 12:06:33 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# Set compiler and linker flags for preferred C++ library
|
|
|
|
if(CXXLIB_CLANG)
|
|
|
|
message_colored(STATUS "Linking against libc++" 32)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lc++ -lc++abi")
|
|
|
|
elseif(CXXLIB_GCC)
|
|
|
|
message_colored(STATUS "Linking against libstdc++" 32)
|
|
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lstdc++")
|
|
|
|
endif()
|
|
|
|
|
2016-11-30 17:22:10 +00:00
|
|
|
# Install paths
|
|
|
|
if(NOT DEFINED CMAKE_INSTALL_BINDIR)
|
|
|
|
set(CMAKE_INSTALL_BINDIR bin)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_INSTALL_SBINDIR)
|
|
|
|
set(CMAKE_INSTALL_SBINDIR sbin)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
|
|
|
|
set(CMAKE_INSTALL_LIBDIR lib)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_INSTALL_INCLUDEDIR)
|
|
|
|
set(CMAKE_INSTALL_INCLUDEDIR include)
|
|
|
|
endif()
|
2016-12-21 22:22:02 +00:00
|
|
|
|
|
|
|
# Custom build type ; SANITIZE
|
2018-11-17 13:30:02 +00:00
|
|
|
SET(CMAKE_CXX_FLAGS_SANITIZE "-O0 -g -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls"
|
2016-12-21 22:22:02 +00:00
|
|
|
CACHE STRING "Flags used by the C++ compiler during sanitize builds." FORCE)
|
|
|
|
SET(CMAKE_C_FLAGS_SANITIZE ""
|
|
|
|
CACHE STRING "Flags used by the C compiler during sanitize builds." FORCE)
|
|
|
|
SET(CMAKE_EXE_LINKER_FLAGS_SANITIZE ""
|
|
|
|
CACHE STRING "Flags used for linking binaries during sanitize builds." FORCE)
|
|
|
|
SET(CMAKE_SHARED_LINKER_FLAGS_SANITIZE ""
|
|
|
|
CACHE STRING "Flags used by the shared libraries linker during sanitize builds." FORCE)
|
|
|
|
MARK_AS_ADVANCED(
|
|
|
|
CMAKE_CXX_FLAGS_SANITIZE
|
|
|
|
CMAKE_C_FLAGS_SANITIZE
|
|
|
|
CMAKE_EXE_LINKER_FLAGS_SANITIZE
|
|
|
|
CMAKE_SHARED_LINKER_FLAGS_SANITIZE)
|
2018-11-21 17:46:33 +00:00
|
|
|
|
|
|
|
# Custom build type ; Coverage
|
|
|
|
SET(CMAKE_CXX_FLAGS_COVERAGE
|
|
|
|
"${CMAKE_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_COVERAGE} --coverage")
|
|
|
|
SET(CMAKE_C_FLAGS_COVERAGE
|
|
|
|
"${CMAKE_C_FLAGS_DEBUG} ${CMAKE_C_FLAGS_COVERAGE} --coverage")
|
|
|
|
SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE
|
|
|
|
"${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CMAKE_EXE_LINKER_FLAGS_COVERAGE}")
|
|
|
|
SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
|
|
|
|
"${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${CMAKE_SHARED_LINKER_FLAGS_COVERAGE}")
|