-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
117 lines (85 loc) · 2.8 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
114
115
116
117
cmake_minimum_required(VERSION 3.14)
include(cmake/PreventInSourceBuilds.cmake)
# ---- Initialize Project ----
# used to support find_package
set(package_name "patomic")
# create base project
project(
patomic
VERSION 0.5.1
DESCRIPTION "Portable C90 Atomics Library"
HOMEPAGE_URL "https://github.com/doodspav/patomic"
LANGUAGES C
)
# don't change include order, OptionVariables checks if project is top level
include(cmake/ProjectIsTopLevel.cmake)
include(cmake/OptionVariables.cmake)
# ---- Declare Library ----
# target that we can modify (can't modify ALIAS targets)
# target name should not be the same as ${PROJECT_NAME}, causes add_subdirectory issues
set(target_name "patomic-patomic")
add_library(${target_name} ${build_type})
# alias to cause error at configuration time instead of link time if target is missing
add_library(patomic::patomic ALIAS ${target_name})
# add /include files to target
# unfortunately can't have CML file in /include
target_sources(
${target_name} PRIVATE
# include
include/patomic/patomic.h
)
# add /src files to target
add_subdirectory(src)
# ---- Generate Build Info Headers ----
# used in export header generated below
if(NOT PATOMIC_BUILD_SHARED)
target_compile_definitions(${target_name} PUBLIC PATOMIC_STATIC_DEFINE)
endif()
# generate header file with export macros prefixed with BASE_NAME
include(GenerateExportHeader)
generate_export_header(
${target_name}
BASE_NAME patomic
EXPORT_FILE_NAME include/patomic/patomic_export.h
)
# ---- Library Properties ----
# hide all symbols by default
# use SameMajorVersion versioning for shared library lookup
set_target_properties(
${target_name} PROPERTIES
C_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN YES
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
EXPORT_NAME "patomic"
OUTPUT_NAME "patomic"
)
# header files generated by CMake
target_include_directories(
${target_name} SYSTEM PUBLIC
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>"
)
# header files from /include
target_include_directories(
${target_name} ${warning_guard} PUBLIC
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
)
# require C90 compiler support
target_compile_features(${target_name} PUBLIC c_std_90)
# ---- Install Rules ----
if(NOT CMAKE_SKIP_INSTALL_RULES)
include(cmake/InstallRules.cmake)
endif()
# ---- Setup Tests ----
if(PATOMIC_BUILD_TESTING)
# need to enable testing in case BUILD_TESTING is disabled
# CTest expects that the top level project enables testing
if(PROJECT_IS_TOP_LEVEL)
enable_testing()
endif()
# tell unit tests where our files are
set(PATOMIC_BINARY_DIR "${PROJECT_BINARY_DIR}")
set(PATOMIC_SOURCE_DIR "${PROJECT_SOURCE_DIR}")
# include test project
add_subdirectory(test)
endif()