1#
2#
3# top level build file for cn-cbor
4
5## prepare CMAKE
6cmake_minimum_required ( VERSION 3.0.0 )
7
8set ( VERSION_MAJOR 0   CACHE STRING "Project major version number")
9set ( VERSION_MINOR "1" CACHE STRING "Project minor version number" )
10set ( VERSION_PATCH "0" CACHE STRING "Project patch version number" )
11set ( CN_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" )
12mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH CN_VERSION)
13
14project ( "cn-cbor" VERSION "${CN_VERSION}")
15
16find_package(Doxygen)
17
18## setup options
19option ( use_context    "Use context pointer for CBOR functions" OFF )
20option ( verbose        "Produce verbose makefile output" OFF )
21option ( optimize       "Optimize for size" OFF )
22option ( fatal_warnings "Treat build warnings as errors" ON )
23option ( coveralls      "Generate coveralls data" ON )
24option ( coveralls_send "Send data to coveralls site" OFF )
25option ( build_docs "Create docs using Doxygen" ${DOXYGEN_FOUND} )
26option ( no_floats "Build without floating point support" OFF )
27
28set ( dist_dir    ${CMAKE_BINARY_DIR}/dist )
29set ( prefix      ${CMAKE_INSTALL_PREFIX} )
30set ( exec_prefix ${CMAKE_INSTALL_PREFIX}/bin )
31set ( libdir      ${CMAKE_INSTALL_PREFIX}/lib )
32set ( includedir  ${CMAKE_INSTALL_PREFIX}/include )
33configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cn-cbor.pc.in
34               ${CMAKE_CURRENT_BINARY_DIR}/cn-cbor.pc @ONLY)
35install (FILES ${CMAKE_CURRENT_BINARY_DIR}/cn-cbor.pc DESTINATION lib/pkgconfig )
36
37set ( package_prefix "${CMAKE_PACKAGE_NAME}-${CMAKE_SYSTEM_NAME}" )
38
39set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${dist_dir}/bin )
40set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${dist_dir}/lib )
41set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${dist_dir}/lib )
42
43if (NOT CMAKE_BUILD_TYPE)
44  if ( optimize )
45    set ( CMAKE_BUILD_TYPE MinSizeRel )
46    set ( coveralls OFF )
47    set ( coveralls_send OFF )
48  else ()
49    set ( CMAKE_BUILD_TYPE Debug )
50  endif ()
51endif()
52
53message ( "Build type: ${CMAKE_BUILD_TYPE}" )
54
55if ( CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
56     CMAKE_C_COMPILER_ID MATCHES "Clang" )
57  message ( STATUS "adding GCC/Clang options ")
58  add_definitions ( -std=gnu99 -Wall -Wextra -pedantic )
59  if ( fatal_warnings )
60    add_definitions ( -Werror )
61  endif ()
62  if ( optimize )
63    add_definitions ( -Os )
64  endif ()
65elseif ( MSVC )
66  add_definitions ( /W3 )
67  if ( fatal_warnings )
68    add_definitions ( /WX )
69  endif ()
70else ()
71  message ( FATAL_ERROR "unhandled compiler id: ${CMAKE_C_COMPILER_ID}" )
72endif ()
73
74if ( no_floats )
75   add_definitions(-DCBOR_NO_FLOAT)
76endif()
77
78if ( verbose )
79  set ( CMAKE_VERBOSE_MAKEFILE ON )
80endif ()
81
82## include the parts
83add_subdirectory ( include )
84add_subdirectory ( src )
85add_subdirectory ( test )
86
87install (FILES LICENSE README.md DESTINATION .)
88
89## setup packaging
90set ( CPACK_GENERATOR "TGZ" )
91set ( CPACK_PACKAGE_VERSION "${PROJECT_VERSION}" )
92set ( CPACK_SOURCE_GENERATOR "TGZ" )
93set ( CPACK_SOURCE_IGNORE_FILES "/\\\\.git/" )
94file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/.gitignore igs)
95foreach (ig IN ITEMS ${igs})
96    # remove comments
97    string ( REGEX REPLACE "^\\s*#.*" "" ig "${ig}")
98    # remove any other whitespace
99    string ( STRIP "${ig}" ig)
100    # anything left?
101    if (ig)
102      # dots are literal
103      string ( REPLACE "." "\\\\." ig "${ig}" )
104      # stars are on thars
105      string ( REPLACE "*" ".*" ig "${ig}" )
106      list ( APPEND CPACK_SOURCE_IGNORE_FILES "/${ig}/" )
107    endif()
108endforeach()
109
110set ( CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md )
111set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" )
112
113include ( CPack )
114include ( CTest )
115
116set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
117include ( LCov )
118
119if (build_docs)
120    if(NOT DOXYGEN_FOUND)
121        message(FATAL_ERROR "Doxygen is needed to build the documentation.")
122    endif()
123
124    set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
125    set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
126
127    configure_file(${doxyfile_in} ${doxyfile} @ONLY)
128
129    add_custom_target(doc
130        COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
131        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
132        COMMENT "Generating API documentation with Doxygen"
133        VERBATIM)
134
135    install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
136endif()
137