forked from CESNET/libyang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
193 lines (165 loc) · 6.25 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
cmake_minimum_required(VERSION 2.8.9)
project(libyang C)
include(GNUInstallDirs)
set(LIBYANG_DESCRIPTION "libyang is YANG data modelling language parser and toolkit written (and providing API) in C.")
# set version
set(LIBYANG_MAJOR_VERSION 0)
set(LIBYANG_MINOR_VERSION 11)
set(LIBYANG_MICRO_VERSION 110)
set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION})
configure_file(${PROJECT_SOURCE_DIR}/src/libyang.h.in ${PROJECT_SOURCE_DIR}/src/libyang.h)
# include custom Modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
find_package(FLEX)
find_package(BISON)
find_program (SED_TOOL NAMES sed)
if(NOT BISON_FOUND)
message(WARNING "Missing Bison.\nYou won't be able to generate source codes from changed flex/bison files.\nCompiling libyang should still works fine.")
elseif (NOT FLEX_FOUND)
message(WARNING "Missing Flex.\nYou won't be able to generate source codes from changed flex/bison files.\nCompiling libyang should still works fine.")
else()
if (BISON_VERSION VERSION_LESS 3)
set(EMPTYDIR "")
else ()
set(EMPTYDIR "%empty")
endif()
configure_file(${PROJECT_SOURCE_DIR}/src/yang.y.in ${PROJECT_SOURCE_DIR}/src/yang.y)
add_custom_target(bison
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src
COMMAND bison -Wno-other -l -o parser_yang_bis.c --defines=parser_yang_bis.h yang.y
COMMAND flex -8 -L -o parser_yang_lex.c --header-file=parser_yang_lex.h yang.l
COMMAND ${SED_TOOL} -i 's/int yychar\;/int yychar\;\\nchar *s = NULL, *tmp_s = NULL\;\\nstruct lys_include inc\;\\nstruct lys_module *trg = NULL\;\\nstruct lys_node *tpdf_parent = NULL, *data_node = NULL\;\\nvoid *actual = NULL\;\\nstruct lys_node_uses *refine_parent = NULL\;\\nint config_inherit = 0, actual_type = 0\;\\nint64_t cnt_val\;\\nint read_string = read_all\;\\nvoid *yang_type = NULL\;/' parser_yang_bis.c
)
endif()
# check the supported platform
if(NOT UNIX)
message(FATAL_ERROR "Only *nix like systems are supported.")
endif()
# set default build type if not specified by user
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE debug)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
if(CMAKE_BUILD_TYPE STREQUAL debug)
option(ENABLE_BUILD_TESTS "Build tests" ON)
option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
else()
option(ENABLE_BUILD_TESTS "Build tests" OFF)
option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
endif()
set(libsrc
src/common.c
src/context.c
src/log.c
src/dict.c
src/resolve.c
src/validation.c
src/xml.c
src/parser.c
src/parser_yin.c
src/parser_xml.c
src/parser_json.c
src/parser_yang_bis.c
src/parser_yang_lex.c
src/parser_yang.c
src/tree_schema.c
src/tree_data.c
src/printer.c
src/xpath.c
src/printer_yang.c
src/printer_yin.c
src/printer_xml.c
src/printer_tree.c
src/printer_info.c
src/printer_json.c
src/yang_types.c)
set(lintsrc
tools/lint/main.c
tools/lint/main_ni.c
tools/lint/commands.c
tools/lint/completion.c
linenoise/linenoise.c)
set(yang2yinsrc
tools/yang2yin/main.c)
set(headers
src/libyang.h
src/tree_schema.h
src/tree_data.h
src/xml.h
src/dict.h)
# create static libyang library
if(STATIC)
add_library(yang_static STATIC ${libsrc})
set_target_properties(yang_static PROPERTIES OUTPUT_NAME yang)
target_link_libraries(yang_static m)
target_link_libraries(yang_static ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(yang_static ${PCRE_LIBRARIES})
install(TARGETS yang_static DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif(STATIC)
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
add_library(yangobj OBJECT ${libsrc})
add_library(yang SHARED $<TARGET_OBJECTS:yangobj>)
set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION})
# link math
target_link_libraries(yang m)
# find pthreads
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT})
# find PCRE library
find_package(PCRE REQUIRED)
include_directories(${PCRE_INCLUDE_DIRS})
target_link_libraries(yang ${PCRE_LIBRARIES})
install(TARGETS yang DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${headers} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libyang)
find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
# generate and install pkg-config file
configure_file("libyang.pc.in" "libyang.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
# check that pkg-config includes the used path
execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET)
if(RETURN EQUAL 0)
string(REGEX MATCH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig" SUBSTR "${PC_PATH}")
string(LENGTH "${SUBSTR}" SUBSTR_LEN)
if(SUBSTR_LEN EQUAL 0)
message(WARNING "pkg-config will not detect the new package after installation, adjust PKG_CONFIG_PATH using \"export PKG_CONFIG_PATH=\${PKG_CONFIG_PATH}:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig\".")
endif()
endif()
endif()
# generate doxygen documentation for libyang API
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYGEN_SKIP_DOT TRUE)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
configure_file(Doxyfile.in Doxyfile)
endif()
# clean cmake cache
add_custom_target(cclean
COMMAND make clean
COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} +
COMMAND rm -rf Makefile Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_executable(yanglint ${lintsrc})
target_link_libraries(yanglint yang)
install(TARGETS yanglint DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${PROJECT_SOURCE_DIR}/tools/lint/yanglint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
add_executable(yang2yin ${yang2yinsrc})
if(ENABLE_VALGRIND_TESTS)
set(ENABLE_BUILD_TESTS ON)
endif()
if(ENABLE_BUILD_TESTS)
find_package(CMocka 1.0.0)
if(CMOCKA_FOUND)
enable_testing()
add_subdirectory(tests)
endif(CMOCKA_FOUND)
endif(ENABLE_BUILD_TESTS)
if(JAVASCRIPT_BINDING)
include(swig/javascript/CMakeLists.txt)
endif()