• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 )
27option ( align_reads    "Use memcpy in ntoh*p()" OFF )
28
29set ( dist_dir    ${CMAKE_BINARY_DIR}/dist )
30set ( prefix      ${CMAKE_INSTALL_PREFIX} )
31set ( exec_prefix ${CMAKE_INSTALL_PREFIX}/bin )
32set ( libdir      ${CMAKE_INSTALL_PREFIX}/lib )
33set ( includedir  ${CMAKE_INSTALL_PREFIX}/include )
34configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cn-cbor.pc.in
35               ${CMAKE_CURRENT_BINARY_DIR}/cn-cbor.pc @ONLY)
36install (FILES ${CMAKE_CURRENT_BINARY_DIR}/cn-cbor.pc DESTINATION lib/pkgconfig )
37
38set ( package_prefix "${CMAKE_PACKAGE_NAME}-${CMAKE_SYSTEM_NAME}" )
39
40set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${dist_dir}/bin )
41set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${dist_dir}/lib )
42set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${dist_dir}/lib )
43
44if (NOT CMAKE_BUILD_TYPE)
45  if ( optimize )
46    set ( CMAKE_BUILD_TYPE MinSizeRel )
47    set ( coveralls OFF )
48    set ( coveralls_send OFF )
49  else ()
50    set ( CMAKE_BUILD_TYPE Debug )
51  endif ()
52endif()
53
54message ( "Build type: ${CMAKE_BUILD_TYPE}" )
55
56if ( CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
57     CMAKE_C_COMPILER_ID MATCHES "Clang" )
58  message ( STATUS "adding GCC/Clang options ")
59  add_definitions ( -std=gnu99 -Wall -Wextra -pedantic )
60  if ( fatal_warnings )
61    add_definitions ( -Werror )
62  endif ()
63  if ( optimize )
64    add_definitions ( -Os )
65  endif ()
66elseif ( MSVC )
67  add_definitions ( /W3 )
68  if ( fatal_warnings )
69    add_definitions ( /WX )
70  endif ()
71else ()
72  message ( FATAL_ERROR "unhandled compiler id: ${CMAKE_C_COMPILER_ID}" )
73endif ()
74
75if ( no_floats )
76   add_definitions(-DCBOR_NO_FLOAT)
77endif()
78
79if ( verbose )
80  set ( CMAKE_VERBOSE_MAKEFILE ON )
81endif ()
82
83## include the parts
84add_subdirectory ( include )
85add_subdirectory ( src )
86add_subdirectory ( test )
87
88install (FILES LICENSE README.md DESTINATION .)
89
90## setup packaging
91set ( CPACK_GENERATOR "TGZ" )
92set ( CPACK_PACKAGE_VERSION "${PROJECT_VERSION}" )
93set ( CPACK_SOURCE_GENERATOR "TGZ" )
94set ( CPACK_SOURCE_IGNORE_FILES "/\\\\.git/" )
95file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/.gitignore igs)
96foreach (ig IN ITEMS ${igs})
97    # remove comments
98    string ( REGEX REPLACE "^\\s*#.*" "" ig "${ig}")
99    # remove any other whitespace
100    string ( STRIP "${ig}" ig)
101    # anything left?
102    if (ig)
103      # dots are literal
104      string ( REPLACE "." "\\\\." ig "${ig}" )
105      # stars are on thars
106      string ( REPLACE "*" ".*" ig "${ig}" )
107      list ( APPEND CPACK_SOURCE_IGNORE_FILES "/${ig}/" )
108    endif()
109endforeach()
110
111set ( CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md )
112set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" )
113
114include ( CPack )
115include ( CTest )
116
117set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
118include ( LCov )
119
120if (build_docs)
121    if(NOT DOXYGEN_FOUND)
122        message(FATAL_ERROR "Doxygen is needed to build the documentation.")
123    endif()
124
125    set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
126    set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
127
128    configure_file(${doxyfile_in} ${doxyfile} @ONLY)
129
130    add_custom_target(doc
131        COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
132        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
133        COMMENT "Generating API documentation with Doxygen"
134        VERBATIM)
135
136    install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
137endif()
138