Skip to content

Commit 146c949

Browse files
committed
Modernize CMakeLists.txt
1 parent 8f88544 commit 146c949

File tree

2 files changed

+43
-24
lines changed

2 files changed

+43
-24
lines changed

CMakeLists.txt

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
1-
cmake_minimum_required (VERSION 2.8.0 FATAL_ERROR)
2-
project (TAOCPP_OPERATORS)
1+
cmake_minimum_required (VERSION 3.2.0 FATAL_ERROR)
32

4-
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
5-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /W4 /WX")
6-
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
7-
set (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
8-
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
9-
set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
10-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Werror")
11-
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
12-
set (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
13-
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g -DNDEBUG")
14-
set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
15-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -Werror")
16-
else ()
17-
message (FATAL_ERROR "Unknown C++ compiler")
18-
endif ()
3+
# set project and version
4+
project (taocpp-operators VERSION 1.0.0 LANGUAGES CXX)
5+
6+
# define a header-only library
7+
add_library (taocpp-operators INTERFACE)
8+
add_library (taocpp::operators ALIAS taocpp-operators)
9+
target_include_directories (taocpp-operators INTERFACE
10+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
11+
$<INSTALL_INTERFACE:include>
12+
)
1913

14+
# features used by taocpp/operators
15+
target_compile_features (taocpp-operators INTERFACE
16+
cxx_noexcept
17+
cxx_rvalue_references
18+
)
19+
20+
# testing
2021
enable_testing ()
22+
option (TAOCPP_OPERATORS_BUILD_TESTS "Build test programs" ON)
23+
if (TAOCPP_OPERATORS_BUILD_TESTS)
24+
add_subdirectory (src/test/operators)
25+
endif ()
2126

22-
include_directories (${CMAKE_SOURCE_DIR}/include)
27+
# installation directories
28+
set (TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR "include" CACHE STRING "The installation include directory")
29+
set (TAOCPP_OPERATORS_INSTALL_DOC_DIR "share/doc/tao/operators" CACHE STRING "The installation doc directory")
2330

24-
file (GLOB testsources src/test/operators/*.cpp)
25-
foreach (testsourcefile ${testsources})
26-
get_filename_component (exename ${testsourcefile} NAME_WE)
27-
add_executable (${exename} ${testsourcefile})
28-
add_test (NAME ${exename} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} COMMAND ${CMAKE_BINARY_DIR}/${exename})
29-
endforeach (testsourcefile)
31+
# install
32+
install (DIRECTORY include/ DESTINATION ${TAOCPP_OPERATORS_INSTALL_INCLUDE_DIR})
33+
install (FILES LICENSE DESTINATION ${TAOCPP_OPERATORS_INSTALL_DOC_DIR})

src/test/operators/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
file (GLOB testsources *.cpp)
2+
foreach (testsourcefile ${testsources})
3+
get_filename_component (exename ${testsourcefile} NAME_WE)
4+
add_executable (${exename} ${testsourcefile})
5+
set_property (TARGET ${exename} PROPERTY CXX_STANDARD 11)
6+
set_property (TARGET ${exename} PROPERTY CXX_STANDARD_REQUIRED ON)
7+
set_property (TARGET ${exename} PROPERTY CXX_EXTENSIONS OFF)
8+
target_link_libraries (${exename} taocpp::operators)
9+
if (MSVC)
10+
target_compile_options (${exename} PRIVATE /W4 /WX /utf-8)
11+
else ()
12+
target_compile_options (${exename} PRIVATE -pedantic -Wall -Wextra -Wshadow -Werror)
13+
endif ()
14+
add_test (NAME ${exename} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${exename})
15+
endforeach (testsourcefile)

0 commit comments

Comments
 (0)