-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
151 lines (125 loc) · 3.53 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
cmake_minimum_required(VERSION 3.11)
project(libnv-portable VERSION 1.0.1 DESCRIPTION "A cross-platform userspace version of libnv, ported from FreeBSD")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(GNUInstallDirs)
# Set options
option(NVP_TEST "Enable unit tests" OFF)
option(BUILD_SHARED_LIBS "Build as a shared library" ON)
find_package(Atf-C)
find_package(Atf-C++)
find_program(Kyua kyua)
if(NOT Atf-C_FOUND OR NOT Atf-C++_FOUND OR NOT Kyua)
message("Will not build ATF tests.")
set(TEST_ATF FALSE)
else()
set(TEST_ATF TRUE)
endif()
add_library(nvp
src/cnvlist.c
src/dnvlist.c
src/msgio.c
src/nvlist.c
src/nvpair.c
)
set(nvp_includes
include/cnv.h
include/dnv.h
include/nv.h
)
target_include_directories(nvp
PUBLIC include
PRIVATE src
)
target_compile_features(nvp
PUBLIC c_std_99
)
set_target_properties(nvp
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
C_STANDARD 99
C_STANDARD_REQUIRED TRUE
C_EXTENSIONS OFF
LIBRARY_OUTPUT_DIRECTORY bin
ARCHIVE_OUTPUT_DIRECTORY bin
PUBLIC_HEADER "${nvp_includes}"
)
target_compile_definitions(nvp
PRIVATE
_DEFAULT_SOURCE
$<$<PLATFORM_ID:Linux>:_GNU_SOURCE>
)
# If we're on Linux, link against libbsd
target_link_libraries(nvp PUBLIC $<$<PLATFORM_ID:Linux>:bsd>)
# Generate pkg-config file
set(DEST_DIR ${CMAKE_INSTALL_PREFIX})
configure_file(nvp.pc.in bin/nvp.pc @ONLY)
function(build_test target)
add_executable(${target} tests/${target}.c)
target_link_libraries(${target}
nvp
$<$<PLATFORM_ID:Linux>:bsd>
)
set_target_properties(${target}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY bin/test
)
add_test(NAME ${target} COMMAND ${target} WORKING_DIRECTORY bin/test)
set_tests_properties(${target}
PROPERTIES
PASS_REGULAR_EXPRESSION "all ok"
)
endfunction()
function(build_atf_test target atfcpp)
if(atfcpp)
add_executable(${target} tests/${target}.cc)
target_link_libraries(${target}
Atf-C++::Atf-C++
nvp
$<$<PLATFORM_ID:Linux>:bsd>
)
else()
add_executable(${target} tests/${target}.c)
target_link_libraries(${target}
Atf-C::Atf-C
nvp
$<$<PLATFORM_ID:Linux>:bsd>
)
endif()
set_target_properties(${target}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY bin/test
)
endfunction()
# If tests are enabled, make tests
if(NVP_TEST)
enable_testing()
build_test(nvlist_add_test)
build_test(nvlist_append_test)
build_test(nvlist_exists_test)
build_test(nvlist_free_test)
build_test(nvlist_get_test)
build_test(nvlist_move_test)
if(TEST_ATF)
build_atf_test(nvlist_send_recv_test NO)
build_atf_test(nv_tests YES)
build_atf_test(cnv_tests YES)
build_atf_test(dnv_tests YES)
build_atf_test(nv_array_tests YES)
add_test(NAME atf_tests
COMMAND
${Kyua} --loglevel debug test --kyuafile ${CMAKE_CURRENT_SOURCE_DIR}/tests/Kyuafile
--build-root ${CMAKE_CURRENT_BINARY_DIR}/bin/test
WORKING_DIRECTORY
bin/test
)
endif()
endif()
install(
TARGETS nvp DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/bin/nvp.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
)