boost/libs/callable_traits/CMakeLists.txt

136 lines
5.7 KiB
CMake
Raw Normal View History

2018-01-12 21:47:58 +01:00
# Copyright Louis Dionne 2015
# Modified Work Copyright Barrett Adair 2015-2017
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
cmake_minimum_required(VERSION 3.0)
2021-10-05 21:37:46 +02:00
project(boost_callable_traits CXX)
2018-01-12 21:47:58 +01:00
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
enable_testing()
2021-10-05 21:37:46 +02:00
set (CMAKE_CXX_STANDARD ${boost_callable_traits_CXX_STD})
2018-01-12 21:47:58 +01:00
# Setting up CMake options and compiler flags (more flags can be set on a per-target basis or in subdirectories)
include(CheckCXXCompilerFlag)
2021-10-05 21:37:46 +02:00
macro(boost_callable_traits_append_flag testname flag)
2018-01-12 21:47:58 +01:00
check_cxx_compiler_flag(${flag} ${testname})
if (${testname})
add_compile_options(${flag})
endif()
endmacro()
if(NOT MSVC OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
# enable all warnings and treat them all as errors
2021-10-05 21:37:46 +02:00
boost_callable_traits_append_flag(boost_callable_traits_HAS_WERROR -Werror)
boost_callable_traits_append_flag(boost_callable_traits_HAS_WX -WX)
boost_callable_traits_append_flag(boost_callable_traits_HAS_W -W)
boost_callable_traits_append_flag(boost_callable_traits_HAS_WALL -Wall)
boost_callable_traits_append_flag(boost_callable_traits_HAS_WEXTRA -Wextra)
2018-01-12 21:47:58 +01:00
endif()
if(MSVC)
# MSVC/Clang-cl builds need -Qunused-arguments
2021-10-05 21:37:46 +02:00
boost_callable_traits_append_flag(boost_callable_traits_HAS_QUNUSED_ARGUMENTS -Qunused-arguments)
2018-01-12 21:47:58 +01:00
else()
# for better template error debugging
2021-10-05 21:37:46 +02:00
boost_callable_traits_append_flag(boost_callable_traits_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0)
2018-01-12 21:47:58 +01:00
# enforce strict standards compliance
2021-10-05 21:37:46 +02:00
boost_callable_traits_append_flag(boost_callable_traits_HAS_PEDANTIC -pedantic)
2018-01-12 21:47:58 +01:00
# use the most recent C++ standard available
2021-10-05 21:37:46 +02:00
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX0x -std=c++0x)
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX1y -std=c++1y)
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX1z -std=c++1z)
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX17 -std=c++17)
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX2a -std=c++2a)
2018-01-12 21:47:58 +01:00
endif()
# transactional memory - currently only available in GCC 6 and later
if(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
2021-10-05 21:37:46 +02:00
boost_callable_traits_append_flag(boost_callable_traits_HAS_FGNU_TM -fgnu-tm)
2018-01-12 21:47:58 +01:00
endif()
2021-10-05 21:37:46 +02:00
add_library(boost_callable_traits INTERFACE)
set_property(TARGET boost_callable_traits PROPERTY EXPORT_NAME callable_traits)
add_library(Boost::callable_traits ALIAS boost_callable_traits)
target_include_directories(boost_callable_traits INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
$<INSTALL_INTERFACE:include>)
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
2018-01-12 21:47:58 +01:00
#
#find_package(Doxygen)
##find_package(Meta)
#find_package(PythonInterp 2.7)
#find_package(Ruby 2.1)
##############################################################################
2021-10-05 21:37:46 +02:00
# boost_callable_traits_target_name_for(<output variable> <source file> [ext])
2018-01-12 21:47:58 +01:00
# Returns the target name associated to a source file. If the path of the
2021-10-05 21:37:46 +02:00
# source file relative from the root of boost_callable_traits is `path/to/source/file.ext`,
2018-01-12 21:47:58 +01:00
# the target name associated to it will be `path.to.source.file`.
#
# The extension of the file should be specified as a last argument. If no
# extension is specified, the `.cpp` extension is assumed.
##############################################################################
2021-10-05 21:37:46 +02:00
function(boost_callable_traits_target_name_for out file)
2018-01-12 21:47:58 +01:00
if (NOT ARGV2)
set(_extension ".cpp")
else()
set(_extension "${ARGV2}")
endif()
2021-10-05 21:37:46 +02:00
file(RELATIVE_PATH _relative ${boost_callable_traits_SOURCE_DIR} ${file})
2018-01-12 21:47:58 +01:00
string(REPLACE "${_extension}" "" _name ${_relative})
string(REGEX REPLACE "/" "." _name ${_name})
set(${out} "${_name}" PARENT_SCOPE)
endfunction()
##############################################################################
2021-10-05 21:37:46 +02:00
# boost_callable_traits_add_test(<name> <command> [<arg>...])
2018-01-12 21:47:58 +01:00
# Creates a test called `name`, which runs the given `command` with the given args.
##############################################################################
2021-10-05 21:37:46 +02:00
function(boost_callable_traits_add_test name)
if (boost_callable_traits_ENABLE_MEMCHECK)
2018-01-12 21:47:58 +01:00
add_test(${name} ${Valgrind_EXECUTABLE} --leak-check=full --error-exitcode=1 ${ARGN})
else()
add_test(${name} ${ARGN})
endif()
endfunction()
##############################################################################
# Setup the `check` target to build and then run all the tests and examples.
##############################################################################
2021-10-05 21:37:46 +02:00
add_custom_target(callable_traits_check
2018-01-12 21:47:58 +01:00
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Build and then run all the tests and examples.")
2021-10-05 21:37:46 +02:00
if (NOT TARGET check)
add_custom_target(check DEPENDS callable_traits_check)
else()
add_dependencies(check callable_traits_check)
endif()
2018-01-12 21:47:58 +01:00
add_subdirectory(example)
add_subdirectory(test)
##############################################################################
# Setup the 'install' target and the package config file.
##############################################################################
2021-10-05 21:37:46 +02:00
install(TARGETS boost_callable_traits EXPORT CallableTraitsConfig)
2018-01-12 21:47:58 +01:00
install(EXPORT CallableTraitsConfig DESTINATION lib/cmake/CallableTraits)
install(DIRECTORY include/boost DESTINATION include FILES_MATCHING PATTERN "*.hpp")
2021-10-05 21:37:46 +02:00
endif()