-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
153 lines (130 loc) · 5.67 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
152
153
#
# Copyright (C) 2021 CESNET, https://photonics.cesnet.cz/
#
# Written by Václav Kubernát <[email protected]>
#
cmake_minimum_required(VERSION 3.19)
project(libyang-cpp LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include(CTest)
include(GNUInstallDirs)
if(NOT MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough -Wsuggest-override ${CMAKE_CXX_FLAGS}")
endif()
add_custom_target(libyang-cpp-version-cmake
cmake/ProjectGitVersion.cmake
cmake/ProjectGitVersionRunner.cmake
)
include(cmake/ProjectGitVersion.cmake)
prepare_git_version(LIBYANG_CPP_VERSION "3")
find_package(Doxygen)
option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
option(BUILD_SHARED_LIBS "By default, shared libs are enabled. Turn off for a static build." ON)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBYANG REQUIRED libyang>=3.4.2 IMPORTED_TARGET)
set(LIBYANG_CPP_PKG_VERSION "3")
# FIXME from gcc 14.1 on we should be able to use the calendar/time from libstdc++ and thus remove the date dependency
find_package(date)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include(CheckIncludeFileCXX)
check_include_file_cxx(experimental/iterator HAS_CXX_EXPERIMENTAL_ITERATOR)
if (NOT HAS_CXX_EXPERIMENTAL_ITERATOR)
message(STATUS "C++ Library fundamentals TS2 <experimental/iterator> not found, using a backport")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/compat/experimental-iterator/)
endif()
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(yang-cpp
src/ChildInstantiables.cpp
src/Context.cpp
src/DataNode.cpp
src/Enum.cpp
src/Collection.cpp
src/Module.cpp
src/SchemaNode.cpp
src/Set.cpp
src/Type.cpp
src/Utils.cpp
src/utils/exception.cpp
src/utils/ref_count.cpp
src/utils/newPath.cpp
)
target_link_libraries(yang-cpp PRIVATE PkgConfig::LIBYANG)
# We do not offer any long-term API/ABI guarantees. To make stuff easier for downstream consumers,
# we will be bumping both API and ABI versions very deliberately.
# There will be no attempts at semver tracking, for example.
set_target_properties(yang-cpp PROPERTIES
VERSION ${LIBYANG_CPP_PKG_VERSION}
SOVERSION ${LIBYANG_CPP_PKG_VERSION})
include(GenerateExportHeader)
generate_export_header(yang-cpp BASE_NAME libyang_cpp EXPORT_FILE_NAME libyang-cpp/export.h)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24")
target_sources(yang-cpp INTERFACE FILE_SET HEADERS
FILES
libyang-cpp/Collection.hpp
libyang-cpp/Context.hpp
libyang-cpp/DataNode.hpp
libyang-cpp/Enum.hpp
libyang-cpp/ChildInstantiables.hpp
libyang-cpp/Module.hpp
libyang-cpp/Set.hpp
libyang-cpp/SchemaNode.hpp
libyang-cpp/Time.hpp
libyang-cpp/Type.hpp
libyang-cpp/Utils.hpp
libyang-cpp/Value.hpp
)
set_target_properties(yang-cpp PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON)
endif()
if(BUILD_TESTING)
find_package(doctest 2.3.6 REQUIRED) # old version on Ubuntu 20.04 (that's used by TIP's OOPT build of this)
add_library(DoctestIntegration STATIC
tests/doctest-integration.cpp
)
target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/ "${CMAKE_CURRENT_BINARY_DIR}")
target_link_libraries(DoctestIntegration doctest::doctest)
target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tests/test_vars.hpp.in" "${CMAKE_CURRENT_BINARY_DIR}/test_vars.hpp" @ONLY)
function(libyang_cpp_test name)
add_executable(test_${name}
tests/${name}.cpp
)
target_link_libraries(test_${name} DoctestIntegration yang-cpp)
add_test(test_${name} test_${name})
endfunction()
libyang_cpp_test(context)
libyang_cpp_test(data_node)
target_link_libraries(test_data_node PkgConfig::LIBYANG)
libyang_cpp_test(schema_node)
libyang_cpp_test(unsafe)
target_link_libraries(test_unsafe PkgConfig::LIBYANG)
if(date_FOUND)
add_executable(test_time-stl-hhdate tests/time.cpp)
target_link_libraries(test_time-stl-hhdate DoctestIntegration yang-cpp date::date-tz)
add_test(test_time-stl-hhdate test_time-stl-hhdate)
add_executable(test_time-hhdate tests/time.cpp)
target_link_libraries(test_time-hhdate DoctestIntegration yang-cpp date::date-tz)
target_compile_definitions(test_time-hhdate PUBLIC LIBYANG_CPP_SKIP_STD_CHRONO_TZ)
add_test(test_time-hhdate test_time-hhdate)
endif()
endif()
if(WITH_DOCS)
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
SOURCES ${doxyfile_in}
)
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/libyang-cpp.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/libyang-cpp.pc" @ONLY)
install(TARGETS yang-cpp)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/libyang-cpp" TYPE INCLUDE)
install(DIRECTORY ${PROJECT_BINARY_DIR}/libyang-cpp TYPE INCLUDE)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang-cpp.pc" DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)