blob: 43d5d2725e908f2225d983d0265e5c46f6782ac5 [file] [log] [blame]
Radek Krejcie74ea8c2015-04-09 18:06:20 +02001cmake_minimum_required(VERSION 2.6)
2project(libyang C)
3
Michal Vaskoe5cf9922015-11-11 11:06:40 +01004set(LIBYANG_DESCRIPTION "libyang is YANG data modelling language parser and toolkit written (and providing API) in C.")
5
Radek Krejci8f7cf402015-08-13 08:05:48 +02006# set version
7set(LIBYANG_MAJOR_VERSION 0)
Radek Krejci70673972016-01-04 17:13:23 +01008set(LIBYANG_MINOR_VERSION 5)
Radek Krejci04a19dc2016-02-04 15:00:45 +01009set(LIBYANG_MICRO_VERSION 31)
Radek Krejci8f7cf402015-08-13 08:05:48 +020010set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
11set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION})
12
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020013# include custom Modules
Radek Krejci977c1c82015-09-01 15:18:03 +020014set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020015
Radek Krejcie74ea8c2015-04-09 18:06:20 +020016# check the supported platform
17if(NOT UNIX)
18 message(FATAL_ERROR "Only *nix like systems are supported.")
19endif()
20
21if(NOT LIB_INSTALL_DIR)
22 set(LIB_INSTALL_DIR lib)
23endif()
24
Tomas Cejka422c0072015-07-21 18:18:25 +020025if(NOT INCLUDE_INSTALL_DIR)
26 set(INCLUDE_INSTALL_DIR include/libyang)
27endif()
28
Radek Krejcie74ea8c2015-04-09 18:06:20 +020029# set default build type if not specified by user
30if(NOT CMAKE_BUILD_TYPE)
31 set(CMAKE_BUILD_TYPE debug)
32endif()
33
Radek Krejci2cb30542015-04-10 08:33:57 +020034set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden")
Radek Krejci3045cf32015-05-28 10:58:52 +020035set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
Radek Krejcie74ea8c2015-04-09 18:06:20 +020036set(CMAKE_C_FLAGS_DEBUG "-g -O0")
37
Radek Krejci61cd5562015-10-05 14:06:34 +020038if(CMAKE_BUILD_TYPE STREQUAL debug)
39 option(ENABLE_BUILD_TESTS "Build tests" ON)
40 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
41else()
42 option(ENABLE_BUILD_TESTS "Build tests" OFF)
43 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
44endif()
Mislav Novakovic021b9a12015-10-01 20:50:21 +020045
Radek Krejci5a065542015-05-22 15:02:07 +020046set(libsrc
Radek Krejci9b4ca392015-04-10 08:31:27 +020047 src/common.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020048 src/context.c
Radek Krejci9b4ca392015-04-10 08:31:27 +020049 src/log.c
Radek Krejciee627582015-04-20 17:39:59 +020050 src/dict.c
Michal Vaskoc3d9f8c2015-07-31 14:37:24 +020051 src/resolve.c
Radek Krejcib1c12512015-08-11 11:22:04 +020052 src/validation.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020053 src/xml.c
Radek Krejcib1c12512015-08-11 11:22:04 +020054 src/parser.c
Radek Krejci998a0b82015-08-17 13:14:36 +020055 src/parser_yin.c
56 src/parser_xml.c
Radek Krejci5449d472015-10-26 14:35:56 +010057 src/parser_json.c
Michal Vasko2d162e12015-09-24 14:33:29 +020058 src/tree_schema.c
59 src/tree_data.c
Radek Krejciefdd0ce2015-05-26 16:48:29 +020060 src/printer.c
Michal Vaskoabbdaa02015-10-06 15:47:25 +020061 src/xpath.c
Radek Krejci998a0b82015-08-17 13:14:36 +020062 src/printer_yang.c
Michal Vasko9b9e4a02015-08-21 09:11:14 +020063 src/printer_xml.c
Radek Krejci998a0b82015-08-17 13:14:36 +020064 src/printer_tree.c
65 src/printer_info.c
66 src/printer_json.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020067 src/yang_types.c)
Radek Krejcie74ea8c2015-04-09 18:06:20 +020068
Radek Krejci5a065542015-05-22 15:02:07 +020069set(lintsrc
Michal Vaskof3e59f12015-06-18 11:53:56 +020070 tools/lint/main.c
71 tools/lint/commands.c
Michal Vaskoe0cb2522015-07-01 10:24:53 +020072 tools/lint/completion.c
Michal Vasko203b4e72015-06-30 15:25:15 +020073 linenoise/linenoise.c)
Radek Krejci5a065542015-05-22 15:02:07 +020074
Tomas Cejka422c0072015-07-21 18:18:25 +020075set(headers
76 src/libyang.h
Michal Vasko2d162e12015-09-24 14:33:29 +020077 src/tree_schema.h
Radek Krejcic6704c82015-10-06 11:12:45 +020078 src/tree_data.h
Radek Krejci41912fe2015-10-22 10:22:12 +020079 src/xml.h
80 src/dict.h)
Tomas Cejka422c0072015-07-21 18:18:25 +020081
Radek Krejci5a065542015-05-22 15:02:07 +020082add_library(yang SHARED ${libsrc})
Radek Krejci8f7cf402015-08-13 08:05:48 +020083set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION})
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020084
Radek Krejci7d9f46a2016-01-29 13:53:18 +010085# find pthreads
86set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
87find_package(Threads REQUIRED)
88target_link_libraries(yang ${CMAKE_THREAD_LIBS_INIT})
89
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020090# find PCRE library
91find_package(PCRE REQUIRED)
92include_directories(${PCRE_INCLUDE_DIRS})
Radek Krejci1d949ec2015-10-02 13:35:05 +020093target_link_libraries(yang ${PCRE_LIBRARIES})
Radek Krejcie74ea8c2015-04-09 18:06:20 +020094
95install(TARGETS yang DESTINATION ${LIB_INSTALL_DIR})
Tomas Cejka422c0072015-07-21 18:18:25 +020096install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR})
Radek Krejcie74ea8c2015-04-09 18:06:20 +020097
Michal Vaskoe5cf9922015-11-11 11:06:40 +010098find_package(PkgConfig)
99if(PKG_CONFIG_FOUND)
100 # generate and install pkg-config file
101 configure_file("libyang.pc.in" "libyang.pc" @ONLY)
102 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libyang.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
Michal Vasko98ae1e12015-12-15 11:11:28 +0100103 # check that pkg-config includes the used path
104 execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable pc_path pkg-config RESULT_VARIABLE RETURN OUTPUT_VARIABLE PC_PATH ERROR_QUIET)
105 if(RETURN EQUAL 0)
106 string(FIND ${PC_PATH} "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig" PC_PATH_IDX)
107 if(PC_PATH_IDX EQUAL -1)
108 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}/lib/pkgconfig\".")
109 endif()
110 endif()
Michal Vaskoe5cf9922015-11-11 11:06:40 +0100111endif()
112
Radek Krejcie74ea8c2015-04-09 18:06:20 +0200113# generate doxygen documentation for libyang API
Radek Krejcie2626092015-10-08 11:25:44 +0200114find_package(Doxygen)
115if(DOXYGEN_FOUND)
116 set(DOXYGEN_SKIP_DOT TRUE)
117 add_custom_target(doc
118 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
119 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
120 configure_file(Doxyfile.in Doxyfile)
121endif()
Radek Krejcie74ea8c2015-04-09 18:06:20 +0200122
123# clean cmake cache
124add_custom_target(cclean
Radek Krejci25155ac2015-10-08 11:26:20 +0200125 COMMAND make clean
126 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} +
127 COMMAND rm -rf Makefile Doxyfile
128 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Radek Krejci2cb30542015-04-10 08:33:57 +0200129
Radek Krejci5a065542015-05-22 15:02:07 +0200130add_executable(yanglint ${lintsrc})
Radek Krejci1d949ec2015-10-02 13:35:05 +0200131target_link_libraries(yanglint yang)
Radek Krejci5a065542015-05-22 15:02:07 +0200132
Mislav Novakovic021b9a12015-10-01 20:50:21 +0200133if(ENABLE_VALGRIND_TESTS)
134 set(ENABLE_BUILD_TESTS ON)
135endif()
136
137if(ENABLE_BUILD_TESTS)
Radek Krejcie02ce0a2015-11-04 14:14:20 +0100138 find_package(CMocka 1.0.0)
139 if(CMOCKA_FOUND)
140 enable_testing()
141 add_subdirectory(tests)
142 endif(CMOCKA_FOUND)
143endif(ENABLE_BUILD_TESTS)