2016-02-11 12:53:42 +01:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
|
2016-02-11 12:04:49 +01:00
|
|
|
###################################################
|
|
|
|
# Activate C++14
|
|
|
|
#
|
2016-02-11 12:57:50 +01:00
|
|
|
# Uses: target_activate_cpp14(buildtarget)
|
2016-02-11 12:04:49 +01:00
|
|
|
###################################################
|
2016-02-11 12:57:50 +01:00
|
|
|
function(target_activate_cpp14 TARGET)
|
2019-11-01 07:50:55 +01:00
|
|
|
if(MSVC)
|
|
|
|
# Required by range-v3, see its README.md
|
|
|
|
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 17)
|
|
|
|
else()
|
2016-03-04 00:33:10 +01:00
|
|
|
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD 14)
|
2019-11-01 07:50:55 +01:00
|
|
|
endif()
|
|
|
|
set_property(TARGET ${TARGET} PROPERTY CXX_STANDARD_REQUIRED ON)
|
2016-10-26 00:50:53 +02:00
|
|
|
# Ideally, we'd like to use libc++ on linux as well, but:
|
|
|
|
# - http://stackoverflow.com/questions/37096062/get-a-basic-c-program-to-compile-using-clang-on-ubuntu-16
|
|
|
|
# - https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=808086
|
|
|
|
# so only use it on Apple systems...
|
|
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND APPLE)
|
2016-03-04 01:26:47 +01:00
|
|
|
target_compile_options(${TARGET} PUBLIC -stdlib=libc++)
|
2016-10-26 00:50:53 +02:00
|
|
|
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND APPLE)
|
2022-10-12 06:17:59 +02:00
|
|
|
|
|
|
|
# We need ENABLE_EXPORTS so that boost::stacktrace works correctly
|
|
|
|
set_property(TARGET ${TARGET} PROPERTY ENABLE_EXPORTS 1)
|
2016-02-11 12:57:50 +01:00
|
|
|
endfunction(target_activate_cpp14)
|
2016-02-11 12:04:49 +01:00
|
|
|
|
2017-10-27 05:02:51 +02:00
|
|
|
# Find clang-tidy executable (for use in target_enable_style_warnings)
|
2018-09-30 03:01:38 +02:00
|
|
|
if (USE_CLANG_TIDY)
|
|
|
|
find_program(
|
|
|
|
CLANG_TIDY_EXE
|
|
|
|
NAMES "clang-tidy"
|
|
|
|
DOC "Path to clang-tidy executable"
|
|
|
|
)
|
|
|
|
if(NOT CLANG_TIDY_EXE)
|
|
|
|
message(FATAL_ERROR "clang-tidy not found. Please install clang-tidy or run without -DUSE_CLANG_TIDY=on.")
|
|
|
|
else()
|
|
|
|
set(CLANG_TIDY_OPTIONS "-system-headers=0")
|
|
|
|
if (CLANG_TIDY_WARNINGS_AS_ERRORS)
|
|
|
|
set(CLANG_TIDY_OPTIONS "${CLANG_TIDY_OPTIONS}" "-warnings-as-errors=*")
|
|
|
|
endif()
|
|
|
|
message(STATUS "Clang-tidy is enabled. Executable: ${CLANG_TIDY_EXE} Arguments: ${CLANG_TIDY_OPTIONS}")
|
|
|
|
set(CLANG_TIDY_CLI "${CLANG_TIDY_EXE}" "${CLANG_TIDY_OPTIONS}")
|
|
|
|
endif()
|
2017-10-27 05:02:51 +02:00
|
|
|
endif()
|
|
|
|
|
2018-10-21 11:46:27 +02:00
|
|
|
# Find iwyu (for use in target_enable_style_warnings)
|
|
|
|
if (USE_IWYU)
|
|
|
|
find_program(
|
|
|
|
IWYU_EXE NAMES
|
|
|
|
include-what-you-use
|
|
|
|
iwyu
|
|
|
|
)
|
|
|
|
if(NOT IWYU_EXE)
|
|
|
|
message(FATAL_ERROR "include-what-you-use not found. Please install iwyu or run without -DUSE_IWYU=on.")
|
|
|
|
else()
|
|
|
|
message(STATUS "iwyu found: ${IWYU_EXE}")
|
|
|
|
set(DO_IWYU "${IWYU_EXE}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2016-02-11 12:04:49 +01:00
|
|
|
#################################################
|
|
|
|
# Enable style compiler warnings
|
|
|
|
#
|
2016-02-11 12:57:50 +01:00
|
|
|
# Uses: target_enable_style_warnings(buildtarget)
|
2016-02-11 12:04:49 +01:00
|
|
|
#################################################
|
2016-02-11 12:57:50 +01:00
|
|
|
function(target_enable_style_warnings TARGET)
|
2018-10-03 05:51:33 +02:00
|
|
|
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
|
|
|
# TODO
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
|
|
|
|
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wold-style-cast -Wcast-align -Wno-unused-command-line-argument) # TODO consider -Wpedantic -Wchkp -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option -Wconversion and others?
|
|
|
|
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
2018-10-14 23:30:36 +02:00
|
|
|
target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Wold-style-cast -Wcast-align -Wno-maybe-uninitialized) # TODO consider -Wpedantic -Wchkp -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wnoexcept -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=5 -Wundef -Wno-unused -Wno-variadic-macros -Wno-parentheses -fdiagnostics-show-option -Wconversion and others?
|
2018-08-08 05:13:01 +02:00
|
|
|
endif()
|
2017-10-27 05:02:51 +02:00
|
|
|
|
2018-10-03 05:51:33 +02:00
|
|
|
if (USE_WERROR)
|
2021-04-19 00:10:01 +02:00
|
|
|
message(STATUS Building ${TARGET} with -Werror)
|
2018-10-03 05:51:33 +02:00
|
|
|
target_compile_options(${TARGET} PRIVATE -Werror)
|
|
|
|
endif()
|
|
|
|
|
2017-10-27 05:02:51 +02:00
|
|
|
# Enable clang-tidy
|
2018-09-30 03:01:38 +02:00
|
|
|
if(USE_CLANG_TIDY)
|
|
|
|
set_target_properties(
|
|
|
|
${TARGET} PROPERTIES
|
|
|
|
CXX_CLANG_TIDY "${CLANG_TIDY_CLI}"
|
|
|
|
)
|
|
|
|
endif()
|
2018-10-21 11:46:27 +02:00
|
|
|
if(USE_IWYU)
|
|
|
|
set_target_properties(
|
|
|
|
${TARGET} PROPERTIES
|
|
|
|
CXX_INCLUDE_WHAT_YOU_USE "${DO_IWYU}"
|
|
|
|
)
|
|
|
|
endif()
|
2016-02-11 12:57:50 +01:00
|
|
|
endfunction(target_enable_style_warnings)
|
2016-02-11 12:04:49 +01:00
|
|
|
|
|
|
|
##################################################
|
|
|
|
# Add boost to the project
|
|
|
|
#
|
|
|
|
# Uses:
|
2021-04-18 09:49:26 +02:00
|
|
|
# target_add_boost(buildtarget)
|
2016-02-11 12:04:49 +01:00
|
|
|
##################################################
|
2016-02-11 12:57:50 +01:00
|
|
|
function(target_add_boost TARGET)
|
2020-07-01 06:49:09 +02:00
|
|
|
target_link_libraries(${TARGET} PUBLIC CryfsDependencies_boost)
|
2017-02-14 09:16:38 +01:00
|
|
|
target_compile_definitions(${TARGET} PUBLIC BOOST_THREAD_VERSION=4)
|
2016-02-11 12:57:50 +01:00
|
|
|
endfunction(target_add_boost)
|
2016-02-11 12:53:42 +01:00
|
|
|
|
|
|
|
##################################################
|
|
|
|
# Specify that a specific minimal version of gcc is required
|
|
|
|
#
|
|
|
|
# Uses:
|
2016-02-11 12:57:50 +01:00
|
|
|
# require_gcc_version(4.9)
|
2016-02-11 12:53:42 +01:00
|
|
|
##################################################
|
2016-02-13 02:08:55 +01:00
|
|
|
function(require_gcc_version VERSION)
|
2016-02-11 12:53:42 +01:00
|
|
|
if (CMAKE_COMPILER_IS_GNUCXX)
|
|
|
|
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
|
2016-02-13 02:08:55 +01:00
|
|
|
if (GCC_VERSION VERSION_LESS ${VERSION})
|
|
|
|
message(FATAL_ERROR "Needs at least gcc version ${VERSION}, found gcc ${GCC_VERSION}")
|
|
|
|
endif (GCC_VERSION VERSION_LESS ${VERSION})
|
2016-02-11 12:53:42 +01:00
|
|
|
endif (CMAKE_COMPILER_IS_GNUCXX)
|
2016-02-11 12:57:50 +01:00
|
|
|
endfunction(require_gcc_version)
|
2016-02-13 02:08:55 +01:00
|
|
|
|
2016-02-13 02:10:20 +01:00
|
|
|
##################################################
|
|
|
|
# Specify that a specific minimal version of clang is required
|
|
|
|
#
|
|
|
|
# Uses:
|
|
|
|
# require_clang_version(3.5)
|
|
|
|
##################################################
|
2016-02-13 02:08:55 +01:00
|
|
|
function(require_clang_version VERSION)
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${VERSION})
|
|
|
|
message(FATAL_ERROR "Needs at least clang version ${VERSION}, found clang ${CMAKE_CXX_COMPILER_VERSION}")
|
|
|
|
endif (CMAKE_CXX_COMPILER_VERSION VERSION_LESS ${VERSION})
|
|
|
|
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2016-02-14 15:55:54 +01:00
|
|
|
endfunction(require_clang_version)
|
|
|
|
|
2018-09-22 18:37:47 +02:00
|
|
|
include(cmake-utils/TargetArch.cmake)
|
2018-09-18 13:35:50 +02:00
|
|
|
function(get_target_architecture output_var)
|
|
|
|
target_architecture(local_output_var)
|
|
|
|
set(${output_var} ${local_output_var} PARENT_SCOPE)
|
|
|
|
endfunction()
|