a58ffe7673de0bbc52da5735eb5fb7789be69a75
[libasyncio] / CMakeLists.txt
1 # Project
2 project(libasyncio)
3 set(VERSION 0.3)
4 set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}")
5
6 # CMake
7 set(CMAKE_COLOR_MAKEFILE ON)
8 cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
9
10 # Source package generation
11 set(CPACK_SOURCE_GENERATOR             TGZ)
12 set(CPACK_SOURCE_IGNORE_FILES          "~$;\\\\.git;build;build-rpm")
13 set(CPACK_SOURCE_PACKAGE_FILE_NAME     "${PROJECT_NAME}-${VERSION}")
14
15 # Find external packages
16 include(FindPkgConfig)
17
18 option(WITH_LIBI2NCOMMON "Build with libi2ncommon support" OFF)
19 if(WITH_LIBI2NCOMMON)
20     message(STATUS "[!] Building *with* libi2ncommon support. [!]")
21     pkg_check_modules(LIBI2NCOMMON REQUIRED libi2ncommon)
22     include_directories(${LIBI2NCOMMON_INCLUDE_DIRS})
23     link_directories(${LIBI2NCOMMON_LIBRARY_DIRS})
24 else(WITH_LIBI2NCOMMON)
25     message(STATUS "[!] Building *without* libi2ncommon support. [!]")
26 endif(WITH_LIBI2NCOMMON)
27
28 find_package(Boost 1.34 REQUIRED COMPONENTS signals unit_test_framework)
29 include_directories(${Boost_INCLUDE_DIRS})
30
31 option(WITH_LIBT2N "Build with libt2n support" OFF)
32 if(WITH_LIBT2N)
33     message(STATUS "[!] Building *with* libt2n support. [!]")
34     pkg_check_modules(LIBT2N REQUIRED libt2n)
35     include_directories(${LIBT2N_INCLUDE_DIRS})
36     link_directories(${LIBT2N_LIBRARY_DIRS})
37     add_subdirectory(glue_t2n)
38 else(WITH_LIBT2N)
39     message(STATUS "[!] Building *without* libt2n support. [!]")
40 endif(WITH_LIBT2N)
41
42 # Documentation
43 find_package(Doxygen)
44 if(DOXYGEN_FOUND)
45    # Find doxy config
46    message(STATUS "Doxygen found.")
47    set(DOXY_DIR "${CMAKE_SOURCE_DIR}/doc")
48    set(DOXY_CONFIG "${DOXY_DIR}/Doxyfile.in")
49    set(top_srcdir ${CMAKE_SOURCE_DIR})
50
51    # Copy doxy.config.in
52    configure_file("${DOXY_CONFIG}" "${CMAKE_BINARY_DIR}/doxy.config")
53
54    # Create doc directory
55    add_custom_command(
56    OUTPUT ${CMAKE_BINARY_DIR}/doc
57    COMMAND rm -rf ${CMAKE_BINARY_DIR}/doc/{html,man}
58    COMMAND mkdir -p ${CMAKE_BINARY_DIR}/doc
59    DEPENDS utils asyncio ${T2NDIRS} unittest
60    )
61
62    # Run doxygen
63    add_custom_command(
64    OUTPUT ${CMAKE_BINARY_DIR}/doc/html/index.html
65    COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_BINARY_DIR}/doxy.config"
66    DEPENDS "${CMAKE_BINARY_DIR}/doxy.config" "${CMAKE_BINARY_DIR}/doc"
67    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/doc
68    )
69
70    add_custom_target(docs ALL DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html)
71
72    message(STATUS "Generating API documentation with Doxygen.")
73 else(DOXYGEN_FOUND)
74    message(STATUS "Not generating API documentation.")
75 endif(DOXYGEN_FOUND)
76
77 # Spec file
78 configure_file(${CMAKE_SOURCE_DIR}/libasyncio.spec.in ${CMAKE_SOURCE_DIR}/libasyncio.spec @ONLY)
79
80 # Check include files and availability of libraries for config file
81 include(CheckIncludeFiles)
82
83 if(Boost_FOUND)
84     set(HAVE_BOOST 1)
85 endif()
86 if(Boost_SIGNALS_FOUND)
87     set(HAVE_BOOST_SIGNALS 1)
88 endif()
89 if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
90     set(HAVE_BOOST_UNIT_TEST_FRAMEWORK 1)
91 endif()
92 if(LIBI2NCOMMON_FOUND)
93     set(HAVE_LIBI2NCOMMON 1)
94 endif()
95 if(LIBT2N_FOUND)
96     set(HAVE_LIBT2N 1)
97 endif()
98 check_include_files(dlfcn.h HAVE_DLFCN_H)
99 check_include_files(inttypes.h HAVE_INTTYPES_H)
100 check_include_files(memory.h HAVE_MEMORY_H)
101 check_include_files(stdint.h HAVE_STDINT_H)
102 check_include_files(stdlib.h HAVE_STDLIB_H)
103 check_include_files(strings.h HAVE_STRINGS_H)
104 check_include_files(string.h HAVE_STRING_H)
105 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
106 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
107 check_include_files(unistd.h HAVE_UNISTD_H)
108 set(STDC_HEADER_NAMES
109     assert.h
110     ctype.h
111     errno.h
112     float.h
113     limits.h
114     locale.h
115     math.h
116     setjmp.h
117     signal.h
118     stdarg.h
119     stddef.h
120     stdio.h
121     stdlib.h
122     string.h
123     time.h
124 )
125 check_include_files("${STDC_HEADER_NAMES}" STDC_HEADERS)
126
127 # Config file
128 # configure_file(${CMAKE_SOURCE_DIR}/asyncio_config.hpp.in.cmake ${CMAKE_BINARY_DIR}/asyncio_config.hpp)
129 # include_directories(BEFORE ${CMAKE_BINARY_DIR})
130 configure_file(${CMAKE_SOURCE_DIR}/asyncio_config.hpp.in.cmake ${CMAKE_SOURCE_DIR}/asyncio/asyncio_config.hpp)
131 # include_directories(BEFORE ${CMAKE_SOURCE_DIR}/asyncio)
132
133 # PkgConfig output
134 set(prefix      ${CMAKE_INSTALL_PREFIX})
135 set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
136 set(includedir  ${CMAKE_INSTALL_PREFIX}/include)
137 set(libdir      ${CMAKE_INSTALL_PREFIX}/lib)
138
139 # PkgConfig files
140 configure_file(${CMAKE_SOURCE_DIR}/asyncio/libasyncio.pc.in ${CMAKE_BINARY_DIR}/asyncio/libasyncio.pc @ONLY)
141 configure_file(${CMAKE_SOURCE_DIR}/utils/libasyncio_utils.pc.in ${CMAKE_BINARY_DIR}/utils/libasyncio_utils.pc @ONLY)
142 configure_file(${CMAKE_SOURCE_DIR}/glue_t2n/libasyncio_t2n.pc.in ${CMAKE_BINARY_DIR}/glue_t2n/libasyncio_t2n.pc @ONLY)
143
144 install(FILES ${CMAKE_BINARY_DIR}/asyncio/libasyncio.pc DESTINATION lib/pkgconfig)
145 install(FILES ${CMAKE_BINARY_DIR}/utils/libasyncio_utils.pc DESTINATION lib/pkgconfig)
146 install(FILES ${CMAKE_BINARY_DIR}/glue_t2n/libasyncio_t2n.pc DESTINATION lib/pkgconfig)
147
148 # Subdirectories
149 set(CPACK_SET_DESTDIR "ON")
150 add_subdirectory(utils)
151 add_subdirectory(asyncio)
152 add_subdirectory(unittest)
153
154 include(CPack)