1 # 2 # 3 # top level build file for cn-cbor 4 5 ## prepare CMAKE 6 cmake_minimum_required ( VERSION 3.0.0 ) 7 8 set ( VERSION_MAJOR 0 CACHE STRING "Project major version number") 9 set ( VERSION_MINOR "1" CACHE STRING "Project minor version number" ) 10 set ( VERSION_PATCH "0" CACHE STRING "Project patch version number" ) 11 set ( CN_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" ) 12 mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH CN_VERSION) 13 14 project ( "cn-cbor" VERSION "${CN_VERSION}") 15 16 find_package(Doxygen) 17 18 ## setup options 19 option ( use_context "Use context pointer for CBOR functions" OFF ) 20 option ( verbose "Produce verbose makefile output" OFF ) 21 option ( optimize "Optimize for size" OFF ) 22 option ( fatal_warnings "Treat build warnings as errors" ON ) 23 option ( coveralls "Generate coveralls data" ON ) 24 option ( coveralls_send "Send data to coveralls site" OFF ) 25 option ( build_docs "Create docs using Doxygen" ${DOXYGEN_FOUND} ) 26 option ( no_floats "Build without floating point support" OFF ) 27 28 set ( dist_dir ${CMAKE_BINARY_DIR}/dist ) 29 set ( prefix ${CMAKE_INSTALL_PREFIX} ) 30 set ( exec_prefix ${CMAKE_INSTALL_PREFIX}/bin ) 31 set ( libdir ${CMAKE_INSTALL_PREFIX}/lib ) 32 set ( includedir ${CMAKE_INSTALL_PREFIX}/include ) 33 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cn-cbor.pc.in 34 ${CMAKE_CURRENT_BINARY_DIR}/cn-cbor.pc @ONLY) 35 install (FILES ${CMAKE_CURRENT_BINARY_DIR}/cn-cbor.pc DESTINATION lib/pkgconfig ) 36 37 set ( package_prefix "${CMAKE_PACKAGE_NAME}-${CMAKE_SYSTEM_NAME}" ) 38 39 set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${dist_dir}/bin ) 40 set ( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${dist_dir}/lib ) 41 set ( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${dist_dir}/lib ) 42 43 if (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 () 51 endif() 52 53 message ( "Build type: ${CMAKE_BUILD_TYPE}" ) 54 55 if ( 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 () 65 elseif ( MSVC ) 66 add_definitions ( /W3 ) 67 if ( fatal_warnings ) 68 add_definitions ( /WX ) 69 endif () 70 else () 71 message ( FATAL_ERROR "unhandled compiler id: ${CMAKE_C_COMPILER_ID}" ) 72 endif () 73 74 if ( no_floats ) 75 add_definitions(-DCBOR_NO_FLOAT) 76 endif() 77 78 if ( verbose ) 79 set ( CMAKE_VERBOSE_MAKEFILE ON ) 80 endif () 81 82 ## include the parts 83 add_subdirectory ( include ) 84 add_subdirectory ( src ) 85 add_subdirectory ( test ) 86 87 install (FILES LICENSE README.md DESTINATION .) 88 89 ## setup packaging 90 set ( CPACK_GENERATOR "TGZ" ) 91 set ( CPACK_PACKAGE_VERSION "${PROJECT_VERSION}" ) 92 set ( CPACK_SOURCE_GENERATOR "TGZ" ) 93 set ( CPACK_SOURCE_IGNORE_FILES "/\\\\.git/" ) 94 file(STRINGS ${CMAKE_CURRENT_SOURCE_DIR}/.gitignore igs) 95 foreach (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() 108 endforeach() 109 110 set ( CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/README.md ) 111 set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" ) 112 113 include ( CPack ) 114 include ( CTest ) 115 116 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) 117 include ( LCov ) 118 119 if (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) 136 endif() 137