blob: 100d29fe35e00e6b418d69ca196636d275fd675a [file] [log] [blame]
Radek Krejcie74ea8c2015-04-09 18:06:20 +02001cmake_minimum_required(VERSION 2.6)
2project(libyang C)
3
Radek Krejci8f7cf402015-08-13 08:05:48 +02004# set version
5set(LIBYANG_MAJOR_VERSION 0)
Radek Krejcid66c7782015-08-17 10:25:06 +02006set(LIBYANG_MINOR_VERSION 2)
Michal Vaskobeed9ba2015-10-23 16:24:22 +02007set(LIBYANG_MICRO_VERSION 70)
Radek Krejci8f7cf402015-08-13 08:05:48 +02008set(LIBYANG_VERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION}.${LIBYANG_MICRO_VERSION})
9set(LIBYANG_SOVERSION ${LIBYANG_MAJOR_VERSION}.${LIBYANG_MINOR_VERSION})
10
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020011# include custom Modules
Radek Krejci977c1c82015-09-01 15:18:03 +020012set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020013
Radek Krejcie74ea8c2015-04-09 18:06:20 +020014# check the supported platform
15if(NOT UNIX)
16 message(FATAL_ERROR "Only *nix like systems are supported.")
17endif()
18
19if(NOT LIB_INSTALL_DIR)
20 set(LIB_INSTALL_DIR lib)
21endif()
22
Tomas Cejka422c0072015-07-21 18:18:25 +020023if(NOT INCLUDE_INSTALL_DIR)
24 set(INCLUDE_INSTALL_DIR include/libyang)
25endif()
26
Radek Krejcie74ea8c2015-04-09 18:06:20 +020027# set default build type if not specified by user
28if(NOT CMAKE_BUILD_TYPE)
29 set(CMAKE_BUILD_TYPE debug)
30endif()
31
Radek Krejci2cb30542015-04-10 08:33:57 +020032set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden")
Radek Krejci3045cf32015-05-28 10:58:52 +020033set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
Radek Krejcie74ea8c2015-04-09 18:06:20 +020034set(CMAKE_C_FLAGS_DEBUG "-g -O0")
35
Radek Krejci61cd5562015-10-05 14:06:34 +020036if(CMAKE_BUILD_TYPE STREQUAL debug)
37 option(ENABLE_BUILD_TESTS "Build tests" ON)
38 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
39else()
40 option(ENABLE_BUILD_TESTS "Build tests" OFF)
41 option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
42endif()
Mislav Novakovic021b9a12015-10-01 20:50:21 +020043
Radek Krejci5a065542015-05-22 15:02:07 +020044set(libsrc
Radek Krejci9b4ca392015-04-10 08:31:27 +020045 src/common.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020046 src/context.c
Radek Krejci9b4ca392015-04-10 08:31:27 +020047 src/log.c
Radek Krejciee627582015-04-20 17:39:59 +020048 src/dict.c
Michal Vaskoc3d9f8c2015-07-31 14:37:24 +020049 src/resolve.c
Radek Krejcib1c12512015-08-11 11:22:04 +020050 src/validation.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020051 src/xml.c
Radek Krejcib1c12512015-08-11 11:22:04 +020052 src/parser.c
Radek Krejci998a0b82015-08-17 13:14:36 +020053 src/parser_yin.c
54 src/parser_xml.c
Radek Krejci5449d472015-10-26 14:35:56 +010055 src/parser_json.c
Michal Vasko2d162e12015-09-24 14:33:29 +020056 src/tree_schema.c
57 src/tree_data.c
Radek Krejciefdd0ce2015-05-26 16:48:29 +020058 src/printer.c
Michal Vaskoabbdaa02015-10-06 15:47:25 +020059 src/xpath.c
Radek Krejci998a0b82015-08-17 13:14:36 +020060 src/printer_yang.c
Michal Vasko9b9e4a02015-08-21 09:11:14 +020061 src/printer_xml.c
Radek Krejci998a0b82015-08-17 13:14:36 +020062 src/printer_tree.c
63 src/printer_info.c
64 src/printer_json.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020065 src/yang_types.c)
Radek Krejcie74ea8c2015-04-09 18:06:20 +020066
Radek Krejci5a065542015-05-22 15:02:07 +020067set(lintsrc
Michal Vaskof3e59f12015-06-18 11:53:56 +020068 tools/lint/main.c
69 tools/lint/commands.c
Michal Vaskoe0cb2522015-07-01 10:24:53 +020070 tools/lint/completion.c
Michal Vasko203b4e72015-06-30 15:25:15 +020071 linenoise/linenoise.c)
Radek Krejci5a065542015-05-22 15:02:07 +020072
Tomas Cejka422c0072015-07-21 18:18:25 +020073set(headers
74 src/libyang.h
Michal Vasko2d162e12015-09-24 14:33:29 +020075 src/tree_schema.h
Radek Krejcic6704c82015-10-06 11:12:45 +020076 src/tree_data.h
Radek Krejci41912fe2015-10-22 10:22:12 +020077 src/xml.h
78 src/dict.h)
Tomas Cejka422c0072015-07-21 18:18:25 +020079
Radek Krejci5a065542015-05-22 15:02:07 +020080add_library(yang SHARED ${libsrc})
Radek Krejci8f7cf402015-08-13 08:05:48 +020081set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION})
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020082
83# find PCRE library
84find_package(PCRE REQUIRED)
85include_directories(${PCRE_INCLUDE_DIRS})
Radek Krejci1d949ec2015-10-02 13:35:05 +020086target_link_libraries(yang ${PCRE_LIBRARIES})
Radek Krejcie74ea8c2015-04-09 18:06:20 +020087
88install(TARGETS yang DESTINATION ${LIB_INSTALL_DIR})
Tomas Cejka422c0072015-07-21 18:18:25 +020089install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR})
Radek Krejcie74ea8c2015-04-09 18:06:20 +020090
91# generate doxygen documentation for libyang API
Radek Krejcie2626092015-10-08 11:25:44 +020092find_package(Doxygen)
93if(DOXYGEN_FOUND)
94 set(DOXYGEN_SKIP_DOT TRUE)
95 add_custom_target(doc
96 COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
97 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
98 configure_file(Doxyfile.in Doxyfile)
99endif()
Radek Krejcie74ea8c2015-04-09 18:06:20 +0200100
101# clean cmake cache
102add_custom_target(cclean
Radek Krejci25155ac2015-10-08 11:26:20 +0200103 COMMAND make clean
104 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} +
105 COMMAND rm -rf Makefile Doxyfile
106 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Radek Krejci2cb30542015-04-10 08:33:57 +0200107
Radek Krejci5a065542015-05-22 15:02:07 +0200108add_executable(yanglint ${lintsrc})
Radek Krejci1d949ec2015-10-02 13:35:05 +0200109target_link_libraries(yanglint yang)
Radek Krejci5a065542015-05-22 15:02:07 +0200110
Mislav Novakovic021b9a12015-10-01 20:50:21 +0200111if(ENABLE_VALGRIND_TESTS)
112 set(ENABLE_BUILD_TESTS ON)
113endif()
114
115if(ENABLE_BUILD_TESTS)
Radek Krejci800a0792015-10-05 14:05:48 +0200116 enable_testing()
Mislav Novakovic021b9a12015-10-01 20:50:21 +0200117 add_subdirectory(tests)
118endif()