Initial cmake conversion of the libt2n project except the example projects. The unit...
[libt2n] / CMakeLists.txt
CommitLineData
ab2a4234
KK
1# Project
2project(libt2n)
3set(VERSION 0.6)
4set(PROTOCOL_VERSION 1) # protocol version used (integers, increase version if incompatible)
5set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
6
7# CMake
8set(CMAKE_COLOR_MAKEFILE ON)
9cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
10
11# Source package generation
12set(CPACK_SOURCE_GENERATOR TGZ)
13set(CPACK_SOURCE_IGNORE_FILES "~$;\\\\.git;build;build-rpm")
14set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${VERSION}")
15
16# Find external packages
17include(FindPkgConfig)
18
19find_package(Boost 1.33 REQUIRED COMPONENTS serialization unit_test_framework)
20include_directories(${Boost_INCLUDE_DIRS})
21
22pkg_check_modules(XMLPP REQUIRED libxml++-2.6>=2.8.1)
23include_directories(${XMLPP_INCLUDE_DIRS})
24link_directories(${XMLPP_LIBRARY_DIRS})
25
26# Documentation
27find_package(Doxygen)
28if(DOXYGEN_FOUND)
29 # Find doxy config
30 message(STATUS "Doxygen found.")
31 set(DOXY_DIR "${CMAKE_SOURCE_DIR}/doc")
32 set(DOXY_CONFIG "${DOXY_DIR}/Doxyfile.in")
33
34 # Copy doxy.config.in
35 configure_file("${DOXY_CONFIG}" "${CMAKE_BINARY_DIR}/doxy.config")
36
37 # Create doc directory
38 add_custom_command(
39 OUTPUT ${CMAKE_BINARY_DIR}/doc
40 COMMAND rm -rf ${CMAKE_BINARY_DIR}/doc/{html,man}
41 COMMAND mkdir -p ${CMAKE_BINARY_DIR}/doc
42 DEPENDS codegen examples examples-codegen src test
43 )
44
45 # Run doxygen
46 add_custom_command(
47 OUTPUT ${CMAKE_BINARY_DIR}/doc/html/index.html
48 COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_BINARY_DIR}/doxy.config"
49 DEPENDS "${CMAKE_BINARY_DIR}/doxy.config" "${CMAKE_BINARY_DIR}/doc"
50 WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/doc
51 )
52
53 add_custom_target(docs ALL DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html)
54
55 message(STATUS "Generating API documentation with Doxygen.")
56else(DOXYGEN_FOUND)
57 message(STATUS "Not generating API documentation.")
58endif(DOXYGEN_FOUND)
59
60# Spec file
61configure_file(${CMAKE_SOURCE_DIR}/libt2n.spec.in ${CMAKE_SOURCE_DIR}/libt2n.spec @ONLY)
62
63# Check include files and availability of libraries for config file
64include(CheckIncludeFiles)
65
66if(Boost_FOUND)
67 set(HAVE_BOOST 1)
68endif()
69if(Boost_SERIALIZATION_FOUND)
70 set(HAVE_BOOST_SERIALIZATION 1)
71endif()
72if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
73 set(HAVE_BOOST_UNIT_TEST_FRAMEWORK 1)
74endif()
75check_include_files(dlfcn.h HAVE_DLFCN_H)
76check_include_files(inttypes.h HAVE_INTTYPES_H)
77check_include_files(memory.h HAVE_MEMORY_H)
78check_include_files(stdint.h HAVE_STDINT_H)
79check_include_files(stdlib.h HAVE_STDLIB_H)
80check_include_files(strings.h HAVE_STRINGS_H)
81check_include_files(string.h HAVE_STRING_H)
82check_include_files(sys/stat.h HAVE_SYS_STAT_H)
83check_include_files(sys/types.h HAVE_SYS_TYPES_H)
84check_include_files(unistd.h HAVE_UNISTD_H)
85set(STDC_HEADER_NAMES
86 assert.h
87 ctype.h
88 errno.h
89 float.h
90 limits.h
91 locale.h
92 math.h
93 setjmp.h
94 signal.h
95 stdarg.h
96 stddef.h
97 stdio.h
98 stdlib.h
99 string.h
100 time.h
101)
102check_include_files("${STDC_HEADER_NAMES}" STDC_HEADERS)
103
104# Config file
105configure_file(${CMAKE_SOURCE_DIR}/config.h.in.cmake ${CMAKE_BINARY_DIR}/config.h)
106include_directories(BEFORE ${CMAKE_BINARY_DIR})
107
108# PkgConfig output
109set(prefix ${CMAKE_INSTALL_PREFIX})
110set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
111set(includedir ${CMAKE_INSTALL_PREFIX}/include)
112set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
113set(bindir ${exec_prefix})
114set(datadir ${CMAKE_INSTALL_PREFIX}/share)
115
116# PkgConfig files
117configure_file(${CMAKE_SOURCE_DIR}/libt2n.pc.in ${CMAKE_BINARY_DIR}/libt2n.pc @ONLY)
118install(FILES ${CMAKE_BINARY_DIR}/libt2n.pc DESTINATION lib/pkgconfig)
119
120# Installation of scripts
121# install(PROGRAMS libt2n-gccxml.sh DESTINATION /usr/bin)
122
123# Subdirectories
124set(CPACK_SET_DESTDIR "ON")
125add_subdirectory(src)
126add_subdirectory(test)
127# add_subdirectory(examples)
128add_subdirectory(codegen)
129# add_subdirectory(examples-codegen)
130
131include(CPack)