Skip to content

Commit 454b8ad

Browse files
author
Barrett Adair
authored
Merge pull request #183 from HDembinski/fix_cmake
Fix for using callable_traits as a CMake dependency in other boost projects
2 parents 7403f47 + 51bf01b commit 454b8ad

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

CMakeLists.txt

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
66

77
cmake_minimum_required(VERSION 3.0)
8-
project(callable_traits CXX)
8+
project(boost_callable_traits CXX)
99
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
1010
enable_testing()
1111

12-
set (CMAKE_CXX_STANDARD ${callable_traits_CXX_STD})
12+
set (CMAKE_CXX_STANDARD ${boost_callable_traits_CXX_STD})
1313

1414
# Setting up CMake options and compiler flags (more flags can be set on a per-target basis or in subdirectories)
1515

1616
include(CheckCXXCompilerFlag)
17-
macro(callable_traits_append_flag testname flag)
17+
macro(boost_callable_traits_append_flag testname flag)
1818
check_cxx_compiler_flag(${flag} ${testname})
1919
if (${testname})
2020
add_compile_options(${flag})
@@ -24,74 +24,84 @@ endmacro()
2424
if(NOT MSVC OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
2525

2626
# enable all warnings and treat them all as errors
27-
callable_traits_append_flag(callable_traits_HAS_WERROR -Werror)
28-
callable_traits_append_flag(callable_traits_HAS_WX -WX)
29-
callable_traits_append_flag(callable_traits_HAS_W -W)
30-
callable_traits_append_flag(callable_traits_HAS_WALL -Wall)
31-
callable_traits_append_flag(callable_traits_HAS_WEXTRA -Wextra)
27+
boost_callable_traits_append_flag(boost_callable_traits_HAS_WERROR -Werror)
28+
boost_callable_traits_append_flag(boost_callable_traits_HAS_WX -WX)
29+
boost_callable_traits_append_flag(boost_callable_traits_HAS_W -W)
30+
boost_callable_traits_append_flag(boost_callable_traits_HAS_WALL -Wall)
31+
boost_callable_traits_append_flag(boost_callable_traits_HAS_WEXTRA -Wextra)
3232
endif()
3333

3434
if(MSVC)
3535

3636
# MSVC/Clang-cl builds need -Qunused-arguments
37-
callable_traits_append_flag(callable_traits_HAS_QUNUSED_ARGUMENTS -Qunused-arguments)
37+
boost_callable_traits_append_flag(boost_callable_traits_HAS_QUNUSED_ARGUMENTS -Qunused-arguments)
3838
else()
3939

4040
# for better template error debugging
41-
callable_traits_append_flag(callable_traits_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0)
41+
boost_callable_traits_append_flag(boost_callable_traits_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0)
4242

4343
# enforce strict standards compliance
44-
callable_traits_append_flag(callable_traits_HAS_PEDANTIC -pedantic)
44+
boost_callable_traits_append_flag(boost_callable_traits_HAS_PEDANTIC -pedantic)
4545

4646
# use the most recent C++ standard available
47-
callable_traits_append_flag(callable_traits_HAS_STDCXX0x -std=c++0x)
48-
callable_traits_append_flag(callable_traits_HAS_STDCXX1y -std=c++1y)
49-
callable_traits_append_flag(callable_traits_HAS_STDCXX1z -std=c++1z)
50-
callable_traits_append_flag(callable_traits_HAS_STDCXX17 -std=c++17)
51-
callable_traits_append_flag(callable_traits_HAS_STDCXX2a -std=c++2a)
47+
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX0x -std=c++0x)
48+
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX1y -std=c++1y)
49+
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX1z -std=c++1z)
50+
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX17 -std=c++17)
51+
boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX2a -std=c++2a)
5252
endif()
5353

5454
# transactional memory - currently only available in GCC 6 and later
5555
if(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
56-
callable_traits_append_flag(callable_traits_HAS_FGNU_TM -fgnu-tm)
56+
boost_callable_traits_append_flag(boost_callable_traits_HAS_FGNU_TM -fgnu-tm)
5757
endif()
5858

59+
add_library(boost_callable_traits INTERFACE)
60+
set_property(TARGET boost_callable_traits PROPERTY EXPORT_NAME callable_traits)
61+
add_library(Boost::callable_traits ALIAS boost_callable_traits)
62+
63+
target_include_directories(boost_callable_traits INTERFACE
64+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
65+
$<INSTALL_INTERFACE:include>)
66+
67+
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
68+
5969
#
6070
#find_package(Doxygen)
6171
##find_package(Meta)
6272
#find_package(PythonInterp 2.7)
6373
#find_package(Ruby 2.1)
6474

6575
##############################################################################
66-
# callable_traits_target_name_for(<output variable> <source file> [ext])
76+
# boost_callable_traits_target_name_for(<output variable> <source file> [ext])
6777
# Returns the target name associated to a source file. If the path of the
68-
# source file relative from the root of callable_traits is `path/to/source/file.ext`,
78+
# source file relative from the root of boost_callable_traits is `path/to/source/file.ext`,
6979
# the target name associated to it will be `path.to.source.file`.
7080
#
7181
# The extension of the file should be specified as a last argument. If no
7282
# extension is specified, the `.cpp` extension is assumed.
7383
##############################################################################
7484

75-
function(callable_traits_target_name_for out file)
85+
function(boost_callable_traits_target_name_for out file)
7686
if (NOT ARGV2)
7787
set(_extension ".cpp")
7888
else()
7989
set(_extension "${ARGV2}")
8090
endif()
8191

82-
file(RELATIVE_PATH _relative ${callable_traits_SOURCE_DIR} ${file})
92+
file(RELATIVE_PATH _relative ${boost_callable_traits_SOURCE_DIR} ${file})
8393
string(REPLACE "${_extension}" "" _name ${_relative})
8494
string(REGEX REPLACE "/" "." _name ${_name})
8595
set(${out} "${_name}" PARENT_SCOPE)
8696
endfunction()
8797

8898
##############################################################################
89-
# callable_traits_add_test(<name> <command> [<arg>...])
99+
# boost_callable_traits_add_test(<name> <command> [<arg>...])
90100
# Creates a test called `name`, which runs the given `command` with the given args.
91101
##############################################################################
92102

93-
function(callable_traits_add_test name)
94-
if (callable_traits_ENABLE_MEMCHECK)
103+
function(boost_callable_traits_add_test name)
104+
if (boost_callable_traits_ENABLE_MEMCHECK)
95105
add_test(${name} ${Valgrind_EXECUTABLE} --leak-check=full --error-exitcode=1 ${ARGN})
96106
else()
97107
add_test(${name} ${ARGN})
@@ -102,7 +112,6 @@ endfunction()
102112
# Setup the `check` target to build and then run all the tests and examples.
103113
##############################################################################
104114

105-
106115
add_custom_target(callable_traits_check
107116
COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
108117
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
@@ -119,10 +128,8 @@ add_subdirectory(test)
119128
##############################################################################
120129
# Setup the 'install' target and the package config file.
121130
##############################################################################
122-
add_library(callable_traits INTERFACE)
123-
target_include_directories(callable_traits INTERFACE
124-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
125-
$<INSTALL_INTERFACE:include>)
126-
install(TARGETS callable_traits EXPORT CallableTraitsConfig)
131+
install(TARGETS boost_callable_traits EXPORT CallableTraitsConfig)
127132
install(EXPORT CallableTraitsConfig DESTINATION lib/cmake/CallableTraits)
128133
install(DIRECTORY include/boost DESTINATION include FILES_MATCHING PATTERN "*.hpp")
134+
135+
endif()

example/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
add_custom_target(examples COMMENT "Build all the examples.")
77
add_dependencies(callable_traits_check examples)
88

9-
include_directories(${callable_traits_SOURCE_DIR}/include)
9+
include_directories(${boost_callable_traits_SOURCE_DIR}/include)
1010

1111
file(GLOB_RECURSE EXAMPLES "*.cpp")
1212
file(GLOB_RECURSE EXPERIMENTAL_EXAMPLES "experimental*.cpp")
@@ -18,8 +18,8 @@ if (NOT BOOST_CLBL_TRTS_BUILD_EXPERIMENTAL)
1818
endif()
1919

2020
foreach(_file IN LISTS EXAMPLES)
21-
callable_traits_target_name_for(_target "${_file}")
21+
boost_callable_traits_target_name_for(_target "${_file}")
2222
add_executable(${_target} EXCLUDE_FROM_ALL "${_file}")
23-
callable_traits_add_test(${_target} ${CMAKE_CURRENT_BINARY_DIR}/${_target})
23+
boost_callable_traits_add_test(${_target} ${CMAKE_CURRENT_BINARY_DIR}/${_target})
2424
add_dependencies(examples ${_target})
2525
endforeach()

test/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ add_custom_target(tests.quick COMMENT "Build a subset of all the unit tests to f
1414
# dependency of the `tests` target.
1515
##############################################################################
1616

17-
function(callable_traits_add_unit_test name)
18-
callable_traits_add_test(${ARGV})
17+
function(boost_callable_traits_add_unit_test name)
18+
boost_callable_traits_add_test(${ARGV})
1919
add_dependencies(tests ${name})
2020
if ((NOT "${name}" MATCHES "\\.ext\\.") AND (NOT "${name}" MATCHES "_mcd"))
2121
add_dependencies(tests.quick ${name})
2222
endif()
2323
endfunction()
2424

25-
include_directories(${callable_traits_SOURCE_DIR}/include)
25+
include_directories(${boost_callable_traits_SOURCE_DIR}/include)
2626
include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
2727
include_directories(${CMAKE_CURRENT_LIST_DIR})
2828

2929
file(GLOB_RECURSE UNIT_TESTS "*.cpp")
3030

3131
foreach(_file IN LISTS UNIT_TESTS)
32-
callable_traits_target_name_for(_target "${_file}")
32+
boost_callable_traits_target_name_for(_target "${_file}")
3333
add_executable(${_target} EXCLUDE_FROM_ALL "${_file}")
3434
set(lazy_target "lazy_${_target}")
3535
add_executable(${lazy_target} EXCLUDE_FROM_ALL "${_file}")
3636
target_compile_definitions(${lazy_target} INTERFACE -DUSE_LAZY_TYPES)
37-
callable_traits_add_unit_test(${_target} ${CMAKE_CURRENT_BINARY_DIR}/${_target})
38-
callable_traits_add_unit_test(${lazy_target} ${CMAKE_CURRENT_BINARY_DIR}/${_target})
37+
boost_callable_traits_add_unit_test(${_target} ${CMAKE_CURRENT_BINARY_DIR}/${_target})
38+
boost_callable_traits_add_unit_test(${lazy_target} ${CMAKE_CURRENT_BINARY_DIR}/${_target})
3939
endforeach()
4040

4141
add_dependencies(callable_traits_check tests)

0 commit comments

Comments
 (0)