Skip to content

Commit c9fa8a1

Browse files
committed
Modernize CMake support
1 parent 9500b37 commit c9fa8a1

File tree

3 files changed

+74
-45
lines changed

3 files changed

+74
-45
lines changed

CMakeLists.txt

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,66 @@
1-
cmake_minimum_required (VERSION 3.2.0 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.2.0 FATAL_ERROR)
22

3-
project (taocpp-operators VERSION 1.1.1 LANGUAGES CXX)
3+
project(taocpp-operators VERSION 1.2.0 LANGUAGES CXX)
4+
5+
if(${PROJECT_NAME}_FOUND)
6+
# multiple versions can't co-exist
7+
if(NOT ${PROJECT_NAME}_VERSION STREQUAL ${PROJECT_VERSION})
8+
message(FATAL_ERROR "Multiple mismatched versions")
9+
endif()
10+
11+
# only include if this is the first include
12+
if(NOT ${PROJECT_NAME}_DIR STREQUAL "${PROJECT_BINARY_DIR}")
13+
return()
14+
endif()
15+
endif()
16+
17+
# keep track of version
18+
set(${PROJECT_NAME}_FOUND TRUE CACHE BOOL "" FORCE)
19+
set(${PROJECT_NAME}_VERSION "${PROJECT_VERSION}" CACHE STRING "" FORCE)
20+
set(${PROJECT_NAME}_DIR "${PROJECT_BINARY_DIR}" CACHE PATH "" FORCE)
21+
22+
mark_as_advanced(${PROJECT_NAME}_FOUND)
23+
mark_as_advanced(${PROJECT_NAME}_VERSION)
24+
mark_as_advanced(${PROJECT_NAME}_DIR)
425

526
# installation directories
6-
set (TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR "include" CACHE STRING "The installation include directory")
7-
set (TAOCPP_OPERATORS_INSTALL_DOC_DIR "share/doc/tao/operators" CACHE STRING "The installation doc directory")
8-
set (TAOCPP_OPERATORS_INSTALL_CMAKE_DIR "share/taocpp-operators/cmake" CACHE STRING "The installation cmake directory")
27+
set(TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR "include" CACHE STRING "The installation include directory")
28+
set(TAOCPP_OPERATORS_INSTALL_DOC_DIR "share/doc/tao/operators" CACHE STRING "The installation doc directory")
29+
set(TAOCPP_OPERATORS_INSTALL_CMAKE_DIR "share/taocpp-operators/cmake" CACHE STRING "The installation cmake directory")
930

1031
# define a header-only library
11-
add_library (operators INTERFACE)
12-
add_library (taocpp::operators ALIAS operators)
13-
target_include_directories (operators INTERFACE
32+
add_library(taocpp-operators INTERFACE)
33+
add_library(taocpp::operators ALIAS taocpp-operators)
34+
target_include_directories(taocpp-operators INTERFACE
1435
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
1536
$<INSTALL_INTERFACE:${TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR}>
1637
)
1738

1839
# features used by taocpp/operators
19-
target_compile_features (operators INTERFACE
40+
target_compile_features(taocpp-operators INTERFACE
2041
cxx_constexpr
2142
cxx_noexcept
2243
cxx_rvalue_references
2344
)
2445

2546
# testing
26-
enable_testing ()
27-
option (TAOCPP_OPERATORS_BUILD_TESTS "Build test programs" ON)
28-
if (TAOCPP_OPERATORS_BUILD_TESTS)
29-
add_subdirectory (src/test/operators)
30-
endif ()
47+
enable_testing()
48+
option(TAOCPP_OPERATORS_BUILD_TESTS "Build test programs" ON)
49+
if(TAOCPP_OPERATORS_BUILD_TESTS)
50+
add_subdirectory(src/test/operators)
51+
endif()
52+
53+
# make package findable
54+
configure_file(cmake/dummy-config.cmake.in taocpp-operators-config.cmake @ONLY)
3155

3256
# install and export target
33-
install (TARGETS operators EXPORT operators-targets)
57+
install(TARGETS taocpp-operators EXPORT taocpp-operators-targets)
3458

35-
install (EXPORT operators-targets
59+
install(EXPORT taocpp-operators-targets
3660
FILE taocpp-operators-config.cmake
3761
NAMESPACE taocpp::
3862
DESTINATION ${TAOCPP_OPERATORS_INSTALL_CMAKE_DIR}
3963
)
4064

41-
install (DIRECTORY include/ DESTINATION ${TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR})
42-
install (FILES LICENSE DESTINATION ${TAOCPP_OPERATORS_INSTALL_DOC_DIR})
65+
install(DIRECTORY include/ DESTINATION ${TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR})
66+
install(FILES LICENSE DESTINATION ${TAOCPP_OPERATORS_INSTALL_DOC_DIR})

cmake/dummy-config.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Dummy config file
2+
# When a dependency is added with add_subdirectory, but searched with find_package
3+
4+
# Redirect to the directory added with add_subdirectory
5+
add_subdirectory(@PROJECT_SOURCE_DIR@ @PROJECT_BINARY_DIR@)

src/test/operators/CMakeLists.txt

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
1-
cmake_minimum_required (VERSION 3.3.0 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.3.0 FATAL_ERROR)
22

3-
set (test_sources
3+
set(test_sources
44
no_rvalue_reference_results.cpp
55
test_operators.cpp
66
)
77

8-
# file (GLOB ...) is used to validate the above list of test_sources
9-
file (GLOB glob_test_sources RELATIVE ${CMAKE_CURRENT_LIST_DIR} *.cpp)
8+
# file(GLOB ...) is used to validate the above list of test_sources
9+
file(GLOB glob_test_sources RELATIVE ${CMAKE_CURRENT_LIST_DIR} *.cpp)
1010

11-
foreach (testsourcefile ${test_sources})
12-
if (${testsourcefile} IN_LIST glob_test_sources)
13-
list (REMOVE_ITEM glob_test_sources ${testsourcefile})
14-
else ()
15-
message (SEND_ERROR "File ${testsourcefile} is missing from src/test/operators")
16-
endif ()
11+
foreach(testsourcefile ${test_sources})
12+
if(${testsourcefile} IN_LIST glob_test_sources)
13+
list(REMOVE_ITEM glob_test_sources ${testsourcefile})
14+
else()
15+
message(SEND_ERROR "File ${testsourcefile} is missing from src/test/operators")
16+
endif()
1717

18-
get_filename_component (exename ${testsourcefile} NAME_WE)
19-
set (exename "tao-operators-test-${exename}")
20-
add_executable (${exename} ${testsourcefile})
21-
target_link_libraries (${exename} PRIVATE taocpp::operators)
22-
set_target_properties (${exename} PROPERTIES
18+
get_filename_component(exename ${testsourcefile} NAME_WE)
19+
set(exename "tao-operators-test-${exename}")
20+
add_executable(${exename} ${testsourcefile})
21+
target_link_libraries(${exename} PRIVATE taocpp::operators)
22+
set_target_properties(${exename} PROPERTIES
2323
CXX_STANDARD 11
2424
CXX_STANDARD_REQUIRED ON
2525
CXX_EXTENSIONS OFF
2626
)
27-
if (MSVC)
28-
target_compile_options (${exename} PRIVATE /W4 /WX /utf-8)
29-
else ()
30-
target_compile_options (${exename} PRIVATE -pedantic -Wall -Wextra -Wshadow -Werror)
31-
endif ()
32-
add_test (NAME ${exename} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${exename})
33-
endforeach (testsourcefile)
27+
if(MSVC)
28+
target_compile_options(${exename} PRIVATE /W4 /WX /utf-8)
29+
else()
30+
target_compile_options(${exename} PRIVATE -pedantic -Wall -Wextra -Wshadow -Werror)
31+
endif()
32+
add_test(NAME ${exename} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. COMMAND ${exename})
33+
endforeach(testsourcefile)
3434

35-
if (glob_test_sources)
36-
foreach (ignored_source_file ${glob_test_sources})
37-
message (SEND_ERROR "File ${ignored_source_file} in src/test/operators is ignored")
38-
endforeach (ignored_source_file)
39-
endif ()
35+
if(glob_test_sources)
36+
foreach(ignored_source_file ${glob_test_sources})
37+
message(SEND_ERROR "File ${ignored_source_file} in src/test/operators is ignored")
38+
endforeach(ignored_source_file)
39+
endif()

0 commit comments

Comments
 (0)