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