Fix CMake conversion.
[libasyncio] / CMakeLists.txt
1 # Project
2 project(libasyncio)
3 set(VERSION 0.2)
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
50    # Copy doxy.config.in
51    configure_file("${DOXY_CONFIG}" "${CMAKE_BINARY_DIR}/doxy.config")
52
53    # Create doc directory
54    add_custom_command(
55    OUTPUT ${CMAKE_BINARY_DIR}/doc
56    COMMAND rm -rf ${CMAKE_BINARY_DIR}/doc/{html,man}
57    COMMAND mkdir -p ${CMAKE_BINARY_DIR}/doc
58    DEPENDS utils asyncio ${T2NDIRS} unittest
59    )
60
61    # Run doxygen
62    add_custom_command(
63    OUTPUT ${CMAKE_BINARY_DIR}/doc/html/index.html
64    COMMAND ${DOXYGEN_EXECUTABLE} "${CMAKE_BINARY_DIR}/doxy.config"
65    DEPENDS "${CMAKE_BINARY_DIR}/doxy.config" "${CMAKE_BINARY_DIR}/doc"
66    WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/doc
67    )
68
69    add_custom_target(docs ALL DEPENDS ${CMAKE_BINARY_DIR}/doc/html/index.html)
70
71    message(STATUS "Generating API documentation with Doxygen.")
72 else(DOXYGEN_FOUND)
73    message(STATUS "Not generating API documentation.")
74 endif(DOXYGEN_FOUND)
75
76 # Spec file
77 configure_file(${CMAKE_SOURCE_DIR}/libasyncio.spec.in ${CMAKE_SOURCE_DIR}/libasyncio.spec @ONLY)
78
79 # Check include files and availability of libraries for config file
80 include(CheckIncludeFiles)
81
82 if(Boost_FOUND)
83     set(HAVE_BOOST 1)
84 endif()
85 if(Boost_SIGNALS_FOUND)
86     set(HAVE_BOOST_SIGNALS 1)
87 endif()
88 if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
89     set(HAVE_BOOST_UNIT_TEST_FRAMEWORK 1)
90 endif()
91 if(LIBI2NCOMMON_FOUND)
92     set(HAVE_LIBI2NCOMMON 1)
93 endif()
94 if(LIBT2N_FOUND)
95     set(HAVE_LIBT2N 1)
96 endif()
97 check_include_files(dlfcn.h HAVE_DLFCN_H)
98 check_include_files(inttypes.h HAVE_INTTYPES_H)
99 check_include_files(memory.h HAVE_MEMORY_H)
100 check_include_files(stdint.h HAVE_STDINT_H)
101 check_include_files(stdlib.h HAVE_STDLIB_H)
102 check_include_files(strings.h HAVE_STRINGS_H)
103 check_include_files(string.h HAVE_STRING_H)
104 check_include_files(sys/stat.h HAVE_SYS_STAT_H)
105 check_include_files(sys/types.h HAVE_SYS_TYPES_H)
106 check_include_files(unistd.h HAVE_UNISTD_H)
107 set(STDC_HEADER_NAMES
108     assert.h
109     ctype.h
110     errno.h
111     float.h
112     limits.h
113     locale.h
114     math.h
115     setjmp.h
116     signal.h
117     stdarg.h
118     stddef.h
119     stdio.h
120     stdlib.h
121     string.h
122     time.h
123 )
124 check_include_files("${STDC_HEADER_NAMES}" STDC_HEADERS)
125
126 # Config file
127 # configure_file(${CMAKE_SOURCE_DIR}/asyncio_config.hpp.in.cmake ${CMAKE_BINARY_DIR}/asyncio_config.hpp)
128 # include_directories(BEFORE ${CMAKE_BINARY_DIR})
129 configure_file(${CMAKE_SOURCE_DIR}/asyncio_config.hpp.in.cmake ${CMAKE_SOURCE_DIR}/asyncio/asyncio_config.hpp)
130 # include_directories(BEFORE ${CMAKE_SOURCE_DIR}/asyncio)
131
132 # PkgConfig output
133 set(prefix      ${CMAKE_INSTALL_PREFIX})
134 set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
135 set(includedir  ${CMAKE_INSTALL_PREFIX}/include)
136 set(libdir      ${CMAKE_INSTALL_PREFIX}/lib)
137
138 # PkgConfig files
139 configure_file(${CMAKE_SOURCE_DIR}/asyncio/libasyncio.pc.in ${CMAKE_BINARY_DIR}/asyncio/libasyncio.pc @ONLY)
140 configure_file(${CMAKE_SOURCE_DIR}/utils/libasyncio_utils.pc.in ${CMAKE_BINARY_DIR}/utils/libasyncio_utils.pc @ONLY)
141 configure_file(${CMAKE_SOURCE_DIR}/glue_t2n/libasyncio_t2n.pc.in ${CMAKE_BINARY_DIR}/glue_t2n/libasyncio_t2n.pc @ONLY)
142
143 install(FILES ${CMAKE_BINARY_DIR}/asyncio/libasyncio.pc DESTINATION lib/pkgconfig)
144 install(FILES ${CMAKE_BINARY_DIR}/utils/libasyncio_utils.pc DESTINATION lib/pkgconfig)
145 install(FILES ${CMAKE_BINARY_DIR}/glue_t2n/libasyncio_t2n.pc DESTINATION lib/pkgconfig)
146
147 # Subdirectories
148 set(CPACK_SET_DESTDIR "ON")
149 add_subdirectory(utils)
150 add_subdirectory(asyncio)
151 add_subdirectory(unittest)
152
153 include(CPack)