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)
|
|
|
|
check_cxx_compiler_flag("-std=c++14" COMPILER_HAS_CPP14_SUPPORT)
|
2016-02-11 12:04:49 +01:00
|
|
|
IF (COMPILER_HAS_CPP14_SUPPORT)
|
2016-02-11 12:57:50 +01:00
|
|
|
target_compile_options(${TARGET} PUBLIC -std=c++14)
|
2016-02-11 12:04:49 +01:00
|
|
|
ELSE()
|
2016-02-11 12:57:50 +01:00
|
|
|
check_cxx_compiler_flag("-std=c++1y" COMPILER_HAS_CPP14_PARTIAL_SUPPORT)
|
2016-02-11 12:04:49 +01:00
|
|
|
IF (COMPILER_HAS_CPP14_PARTIAL_SUPPORT)
|
2016-02-11 12:57:50 +01:00
|
|
|
target_compile_options(${TARGET} PUBLIC -std=c++1y)
|
2016-02-11 12:04:49 +01:00
|
|
|
ELSE()
|
2016-02-11 12:57:50 +01:00
|
|
|
message(FATAL_ERROR "Compiler doesn't support C++14")
|
2016-02-11 12:04:49 +01:00
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
IF(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
2016-02-11 12:57:50 +01:00
|
|
|
target_compile_options(${TARGET} PUBLIC -stdlib=libc++)
|
2016-02-11 12:04:49 +01:00
|
|
|
ENDIF()
|
2016-02-11 12:57:50 +01:00
|
|
|
endfunction(target_activate_cpp14)
|
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)
|
|
|
|
target_compile_options(${TARGET} PRIVATE -Wall -Wextra)
|
|
|
|
endfunction(target_enable_style_warnings)
|
2016-02-11 12:04:49 +01:00
|
|
|
|
|
|
|
##################################################
|
|
|
|
# Add boost to the project
|
|
|
|
#
|
|
|
|
# Uses:
|
2016-02-11 12:57:50 +01:00
|
|
|
# target_add_boost(buildtarget) # if you're only using header-only boost libs
|
|
|
|
# target_add_boost(buildtarget system filesystem) # list all libraries to link against in the dependencies
|
2016-02-11 12:04:49 +01:00
|
|
|
##################################################
|
2016-02-11 12:57:50 +01:00
|
|
|
function(target_add_boost TARGET)
|
2016-02-11 12:04:49 +01:00
|
|
|
# Load boost libraries
|
|
|
|
find_package(Boost 1.56.0
|
|
|
|
REQUIRED
|
|
|
|
COMPONENTS ${ARGN})
|
|
|
|
set(Boost_USE_STATIC_LIBS ON)
|
|
|
|
target_include_directories(${TARGET} SYSTEM PRIVATE ${Boost_INCLUDE_DIRS})
|
|
|
|
target_link_libraries(${TARGET} PRIVATE ${Boost_LIBRARIES})
|
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-11 12:57:50 +01:00
|
|
|
function(require_gcc_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)
|
|
|
|
if (GCC_VERSION VERSION_LESS ${ARGN})
|
|
|
|
message(FATAL_ERROR "Needs at least gcc version ${ARGN}, found gcc ${GCC_VERSION}")
|
|
|
|
endif (GCC_VERSION VERSION_LESS ${ARGN})
|
|
|
|
endif (CMAKE_COMPILER_IS_GNUCXX)
|
2016-02-11 12:57:50 +01:00
|
|
|
endfunction(require_gcc_version)
|