This repository has been archived by the owner on Jan 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
113 lines (97 loc) · 4.44 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
cmake_minimum_required(VERSION 3.8)
project(retain-ptr
VERSION 0.1.0)
include(CMakeDependentOption)
include(CheckCXXCompilerFlag)
include(CTest)
find_package(PythonInterp 3.6)
find_package(PythonLibs 3.6)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(TEST_SOURCE_DIR ${PROJECT_SOURCE_DIR}/tests)
set(TEST_BINARY_DIR ${PROJECT_BINARY_DIR}/tests)
set(USE_COVERAGE "--coverage")
set(WARN_MAYBE_UNINIT "-Wmaybe-unintialized")
set(WARN_EVERYTHING "-Weverything")
set(WARN_PEDANTIC "-Wpedantic")
set(WARN_ONE_LINE "-WL")
set(WARN_ERROR "-Werror")
set(WARN_EXTRA "-Wextra")
set(WARN_ODR "-Wodr")
set(WARN_ALL "-Wall")
set(WARN_NO_DOUBLE_PROMO "-Wno-double-promotion")
set(WARN_NO_UNUSED_FUNC "-Wno-unused-function")
set(WARN_NO_FLOAT_EQUAL "-Wno-float-equal")
set(WARN_NO_DEPRECATED "-Wno-deprecated-declarations")
set(WARN_NO_ATTRIBUTES "-Wno-attributes")
set(WARN_NO_SHADOW "-Wno-shadow")
set(WARN_NO_PADDED "-Wno-padded")
check_cxx_compiler_flag(${USE_COVERAGE} CAN_USE_COVERAGE)
check_cxx_compiler_flag(${WARN_MAYBE_UNINIT} CAN_WARN_MAYBE_UNINIT)
check_cxx_compiler_flag(${WARN_EVERYTHING} CAN_WARN_EVERYTHING)
check_cxx_compiler_flag(${WARN_PEDANTIC} CAN_WARN_PEDANTIC)
check_cxx_compiler_flag(${WARN_ONE_LINE} CAN_WARN_ONE_LINE)
check_cxx_compiler_flag(${WARN_ERROR} CAN_WARN_ERROR)
check_cxx_compiler_flag(${WARN_EXTRA} CAN_WARN_EXTRA)
check_cxx_compiler_flag(${WARN_ODR} CAN_WARN_ODR)
check_cxx_compiler_flag(${WARN_ALL} CAN_WARN_ALL)
check_cxx_compiler_flag(${WARN_NO_DOUBLE_PROMO} CAN_WARN_NO_DOUBLE_PROMO)
check_cxx_compiler_flag(${WARN_NO_UNUSED_FUNC} CAN_WARN_NO_UNUSED_FUNC)
check_cxx_compiler_flag(${WARN_NO_FLOAT_EQUAL} CAN_WARN_NO_FLOAT_EQUAL)
check_cxx_compiler_flag(${WARN_NO_DEPRECATED} CAN_WARN_NO_DEPRECATED)
check_cxx_compiler_flag(${WARN_NO_ATTRIBUTES} CAN_WARN_NO_ATTRIBUTES)
check_cxx_compiler_flag(${WARN_NO_SHADOW} CAN_WARN_NO_SHADOW)
check_cxx_compiler_flag(${WARN_NO_PADDED} CAN_WARN_NO_PADDED)
add_library(retain-ptr INTERFACE)
target_compile_features(retain-ptr INTERFACE cxx_std_17)
target_include_directories(retain-ptr INTERFACE
${PROJECT_SOURCE_DIR}/include)
if (PYTHONLIBS_FOUND)
add_library(pywrap INTERFACE)
target_include_directories(pywrap INTERFACE
${PROJECT_SOURCE_DIR}/example)
target_include_directories(pywrap SYSTEM INTERFACE
${PYTHON_INCLUDE_DIR})
target_link_libraries(pywrap INTERFACE ${PYTHON_LIBRARIES})
if (MINGW)
target_compile_definitions(pywrap INTERFACE "-D_hypot=hypot")
endif()
endif ()
add_library(doctest-main STATIC ${TEST_SOURCE_DIR}/doctest.cxx)
target_compile_options(doctest-main
PUBLIC
$<$<BOOL:${CAN_USE_COVERAGE}>:${USE_COVERAGE}>
$<$<BOOL:${CAN_WARN_MAYBE_UNINIT}>:${WARN_MAYBE_UNINIT}>
$<$<BOOL:${CAN_WARN_EVERYTHING}>:${WARN_EVERYTHING}>
$<$<BOOL:${CAN_WARN_PEDANTIC}>:${WARN_PEDANTIC}>
$<$<BOOL:${CAN_WARN_EXTRA}>:${WARN_EXTRA}>
$<$<BOOL:${CAN_WARN_ODR}>:${WARN_ODR}>
$<$<BOOL:${CAN_WARN_ALL}>:${WARN_ALL}>
$<$<BOOL:${CAN_WARN_NO_DOUBLE_PROMO}>:${WARN_NO_DOUBLE_PROMO}>
$<$<BOOL:${CAN_WARN_NO_UNUSED_FUNC}>:${WARN_NO_UNUSED_FUNC}>
$<$<BOOL:${CAN_WARN_NO_FLOAT_EQUAL}>:${WARN_NO_FLOAT_EQUAL}>
$<$<BOOL:${CAN_WARN_NO_DEPRECATED}>:${WARN_NO_DEPRECATED}>
$<$<BOOL:${CAN_WARN_NO_ATTRIBUTES}>:${WARN_NO_ATTRIBUTES}>
$<$<BOOL:${CAN_WARN_NO_SHADOW}>:${WARN_NO_SHADOW}>
$<$<BOOL:${CAN_WARN_NO_PADDED}>:${WARN_NO_PADDED}>
$<$<CXX_COMPILER_ID:Clang>:-Wno-potentially-evaluated-expression>
$<$<CXX_COMPILER_ID:Clang>:-Wno-unneeded-internal-declaration>
$<$<CXX_COMPILER_ID:Clang>:-Wno-disabled-macro-expansion>
$<$<CXX_COMPILER_ID:Clang>:-Wno-unused-member-function>
$<$<CXX_COMPILER_ID:Clang>:-Wno-c++98-compat-pedantic>
$<$<CXX_COMPILER_ID:Clang>:-Wno-exit-time-destructors>
$<$<CXX_COMPILER_ID:Clang>:-Wno-c++98-compat>
$<$<CXX_COMPILER_ID:Clang>:-Wno-weak-vtables>)
if (TARGET pywrap)
add_executable(test-python ${TEST_SOURCE_DIR}/python.cxx)
add_test(python test-python)
target_include_directories(test-python SYSTEM PRIVATE ${TEST_SOURCE_DIR})
target_link_libraries(test-python PUBLIC retain-ptr pywrap doctest-main)
target_link_libraries(test-python PRIVATE
$<$<BOOL:${CAN_USE_COVERAGE}>:${USE_COVERAGE}>)
endif ()
add_executable(test-usage_example ${TEST_SOURCE_DIR}/usage_example.cxx)
add_test(usage_example test-usage_example)
target_link_libraries(test-usage_example PUBLIC retain-ptr doctest-main)
target_link_libraries(test-usage_example PRIVATE
$<$<BOOL:${CAN_USE_COVERAGE}>:${USE_COVERAGE}>)