blob: 695908369a7b52b44509591a24dea35afba3599f [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)
7set(LIBYANG_MICRO_VERSION 0)
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
Radek Krejcie74ea8c2015-04-09 18:06:20 +020011# check the supported platform
12if(NOT UNIX)
13 message(FATAL_ERROR "Only *nix like systems are supported.")
14endif()
15
16if(NOT LIB_INSTALL_DIR)
17 set(LIB_INSTALL_DIR lib)
18endif()
19
Tomas Cejka422c0072015-07-21 18:18:25 +020020if(NOT INCLUDE_INSTALL_DIR)
21 set(INCLUDE_INSTALL_DIR include/libyang)
22endif()
23
Radek Krejcie74ea8c2015-04-09 18:06:20 +020024# set default build type if not specified by user
25if(NOT CMAKE_BUILD_TYPE)
26 set(CMAKE_BUILD_TYPE debug)
27endif()
28
Radek Krejci2cb30542015-04-10 08:33:57 +020029set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -fvisibility=hidden")
Radek Krejci3045cf32015-05-28 10:58:52 +020030set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
Radek Krejcie74ea8c2015-04-09 18:06:20 +020031set(CMAKE_C_FLAGS_DEBUG "-g -O0")
32
Radek Krejci5a065542015-05-22 15:02:07 +020033set(libsrc
Radek Krejci9b4ca392015-04-10 08:31:27 +020034 src/common.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020035 src/context.c
Radek Krejci9b4ca392015-04-10 08:31:27 +020036 src/log.c
Radek Krejciee627582015-04-20 17:39:59 +020037 src/dict.c
Michal Vaskoc3d9f8c2015-07-31 14:37:24 +020038 src/parse.c
39 src/resolve.c
Radek Krejcib1c12512015-08-11 11:22:04 +020040 src/validation.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020041 src/xml.c
Radek Krejcib1c12512015-08-11 11:22:04 +020042 src/parser.c
Radek Krejci998a0b82015-08-17 13:14:36 +020043 src/parser_yin.c
44 src/parser_xml.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020045 src/tree.c
Radek Krejciefdd0ce2015-05-26 16:48:29 +020046 src/printer.c
Michal Vasko58953972015-07-31 14:53:05 +020047 src/yang_library.c
Radek Krejci998a0b82015-08-17 13:14:36 +020048 src/printer_yang.c
49 src/printer_tree.c
50 src/printer_info.c
51 src/printer_json.c
Radek Krejcida04f4a2015-05-21 12:54:09 +020052 src/yang_types.c)
Radek Krejcie74ea8c2015-04-09 18:06:20 +020053
Radek Krejci5a065542015-05-22 15:02:07 +020054set(lintsrc
Michal Vaskof3e59f12015-06-18 11:53:56 +020055 tools/lint/main.c
56 tools/lint/commands.c
Michal Vaskoe0cb2522015-07-01 10:24:53 +020057 tools/lint/completion.c
Michal Vasko203b4e72015-06-30 15:25:15 +020058 linenoise/linenoise.c)
Radek Krejci5a065542015-05-22 15:02:07 +020059
Tomas Cejka422c0072015-07-21 18:18:25 +020060set(headers
61 src/libyang.h
62 src/tree.h)
63
Radek Krejci5a065542015-05-22 15:02:07 +020064add_library(yang SHARED ${libsrc})
Radek Krejci8f7cf402015-08-13 08:05:48 +020065set_target_properties(yang PROPERTIES VERSION ${LIBYANG_VERSION} SOVERSION ${LIBYANG_SOVERSION})
Radek Krejcie74ea8c2015-04-09 18:06:20 +020066
67install(TARGETS yang DESTINATION ${LIB_INSTALL_DIR})
Tomas Cejka422c0072015-07-21 18:18:25 +020068install(FILES ${headers} DESTINATION ${INCLUDE_INSTALL_DIR})
Radek Krejcie74ea8c2015-04-09 18:06:20 +020069
70# generate doxygen documentation for libyang API
71add_custom_target(doc
Luka Perkovb2657a22015-08-13 13:23:34 +020072 COMMAND doxygen ${CMAKE_BINARY_DIR}/Doxyfile
Radek Krejcie74ea8c2015-04-09 18:06:20 +020073 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Radek Krejci0d817642015-08-13 10:27:20 +020074configure_file(Doxyfile.in Doxyfile)
Radek Krejcie74ea8c2015-04-09 18:06:20 +020075
76# clean cmake cache
77add_custom_target(cclean
78 COMMAND make clean
79 COMMAND find . -iname '*cmake*' -not -name CMakeLists.txt -exec rm -rf {} +
Radek Krejci0d817642015-08-13 10:27:20 +020080 COMMAND rm -rf Makefile Doxyfile
Radek Krejci2cb30542015-04-10 08:33:57 +020081 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
82
Radek Krejci5a065542015-05-22 15:02:07 +020083add_executable(yanglint ${lintsrc})
Michal Vasko203b4e72015-06-30 15:25:15 +020084target_link_libraries(yanglint yang)
Radek Krejci5a065542015-05-22 15:02:07 +020085