blob: 8e296957406712db1430bc07540d1e640e8c5cc9 [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 Vasko813f9a32015-09-24 13:56:48 +02007set(LIBYANG_MICRO_VERSION 27)
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 Krejci5a065542015-05-22 15:02:07 +020036set(libsrc
Radek Krejci9b4ca392015-04-10 08:31:27 +020037 src/common.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020038 src/context.c
Radek Krejci9b4ca392015-04-10 08:31:27 +020039 src/log.c
Radek Krejciee627582015-04-20 17:39:59 +020040 src/dict.c
Michal Vaskoc3d9f8c2015-07-31 14:37:24 +020041 src/resolve.c
Radek Krejcib1c12512015-08-11 11:22:04 +020042 src/validation.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020043 src/xml.c
Radek Krejcib1c12512015-08-11 11:22:04 +020044 src/parser.c
Radek Krejci998a0b82015-08-17 13:14:36 +020045 src/parser_yin.c
46 src/parser_xml.c
Michal Vasko2d162e12015-09-24 14:33:29 +020047 src/tree_schema.c
48 src/tree_data.c
Radek Krejciefdd0ce2015-05-26 16:48:29 +020049 src/printer.c
Michal Vasko58953972015-07-31 14:53:05 +020050 src/yang_library.c
Radek Krejci998a0b82015-08-17 13:14:36 +020051 src/printer_yang.c
Michal Vasko9b9e4a02015-08-21 09:11:14 +020052 src/printer_xml.c
Radek Krejci998a0b82015-08-17 13:14:36 +020053 src/printer_tree.c
54 src/printer_info.c
55 src/printer_json.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020056 src/yang_types.c)
Radek Krejcie74ea8c2015-04-09 18:06:20 +020057
Radek Krejci5a065542015-05-22 15:02:07 +020058set(lintsrc
Michal Vaskof3e59f12015-06-18 11:53:56 +020059 tools/lint/main.c
60 tools/lint/commands.c
Michal Vaskoe0cb2522015-07-01 10:24:53 +020061 tools/lint/completion.c
Michal Vasko203b4e72015-06-30 15:25:15 +020062 linenoise/linenoise.c)
Radek Krejci5a065542015-05-22 15:02:07 +020063
Tomas Cejka422c0072015-07-21 18:18:25 +020064set(headers
65 src/libyang.h
Michal Vasko2d162e12015-09-24 14:33:29 +020066 src/tree_schema.h
67 src/tree_data.h)
Tomas Cejka422c0072015-07-21 18:18:25 +020068
Radek Krejci5a065542015-05-22 15:02:07 +020069add_library(yang SHARED ${libsrc})
Radek Krejci8f7cf402015-08-13 08:05:48 +020070set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION})
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020071set(LIBS ${LIBS} yang)
72
73# find PCRE library
74find_package(PCRE REQUIRED)
75include_directories(${PCRE_INCLUDE_DIRS})
76set(LIBS ${LIBS} ${PCRE_LIBRARIES})
Radek Krejcie74ea8c2015-04-09 18:06:20 +020077
78install(TARGETS yang DESTINATION ${LIB_INSTALL_DIR})
Tomas Cejka422c0072015-07-21 18:18:25 +020079install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR})
Radek Krejcie74ea8c2015-04-09 18:06:20 +020080
81# generate doxygen documentation for libyang API
82add_custom_target(doc
Luka Perkovb2657a22015-08-13 13:23:34 +020083 COMMAND doxygen ${CMAKE_BINARY_DIR}/Doxyfile
Radek Krejcie74ea8c2015-04-09 18:06:20 +020084 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Radek Krejci0d817642015-08-13 10:27:20 +020085configure_file(Doxyfile.in Doxyfile)
Radek Krejcie74ea8c2015-04-09 18:06:20 +020086
87# clean cmake cache
88add_custom_target(cclean
89 COMMAND make clean
Radek Krejci977c1c82015-09-01 15:18:03 +020090 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -not -path './CMakeModules*' -exec rm -rf {} +
Radek Krejci0d817642015-08-13 10:27:20 +020091 COMMAND rm -rf Makefile Doxyfile
Radek Krejci2cb30542015-04-10 08:33:57 +020092 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
93
Radek Krejci5a065542015-05-22 15:02:07 +020094add_executable(yanglint ${lintsrc})
Michal Vaskoe4e8fbd2015-08-24 14:54:49 +020095target_link_libraries(yanglint ${LIBS})
Radek Krejci5a065542015-05-22 15:02:07 +020096