Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 1 | # |
| 2 | # top level build file for COSE-C |
| 3 | # |
| 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 (COSE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") |
| 12 | mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH COSE_VERSION) |
| 13 | |
| 14 | project ("cose-c" VERSION "${COSE_VERSION}") |
| 15 | |
| 16 | find_package(Doxygen) |
Jim Schaad | 0e727e8 | 2015-09-02 18:21:39 -0700 | [diff] [blame] | 17 | find_package(OpenSSL 1.0 REQUIRED) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 18 | |
| 19 | ### setup options |
| 20 | option (use_context "Use context pointer for COSE functions" ON) |
| 21 | option (verbose "Produce verbose makefile output" OFF) |
| 22 | option (optimize "Optimize for size" OFF) |
| 23 | option (fatal_warnings "Treat build warnings as error" OFF) |
Jim Schaad | d09c211 | 2015-12-26 21:48:53 -0800 | [diff] [blame] | 24 | option (coveralls "Generate coveralls data" ON) |
Jim Schaad | f6addf0 | 2015-11-22 12:58:30 -0800 | [diff] [blame] | 25 | option ( coveralls_send "Send data to coveralls site" OFF ) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 26 | option (build_docs "Create docs using Doxygen" ${DOXYGEN_FOUND} ) |
Jim Schaad | d09c211 | 2015-12-26 21:48:53 -0800 | [diff] [blame] | 27 | option (build_shared_libs "Build Shared Libraries" ON) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 28 | |
| 29 | set ( dist_dir ${CMAKE_BINARY_DIR}/dist ) |
| 30 | set ( prefix ${CMAKE_INSTALL_PREFIX} ) |
| 31 | set ( exec_prefix ${CMAKE_INSTALL_PREFIX}/bin ) |
| 32 | set ( libdir ${CMAKE_INSTALL_PREFIX}/lib ) |
| 33 | set ( includedir ${CMAKE_INSTALL_PREFIX}/include ) |
| 34 | |
| 35 | |
| 36 | if (NOT CMAKE_BUILD_TYPE) |
| 37 | if (optimize) |
| 38 | set ( CMAKE_BUILD_TYPE MinSizeRel ) |
| 39 | set ( coveralls OFF ) |
Jim Schaad | f727122 | 2015-09-04 22:12:59 -0700 | [diff] [blame] | 40 | set ( coveralls_send OFF ) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 41 | else () |
| 42 | set ( CMAKE_BUILD_TYPE Debug) |
| 43 | endif () |
| 44 | endif () |
| 45 | |
Jim Schaad | d09c211 | 2015-12-26 21:48:53 -0800 | [diff] [blame] | 46 | if ( MSVC ) |
| 47 | set (coveralls OFF) |
| 48 | endif () |
| 49 | |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 50 | message ( "Build type: ${CMAKE_BUILD_TYPE}" ) |
| 51 | |
| 52 | add_definitions( -DUSE_ARRAY ) |
| 53 | if ( CMAKE_C_COMPILER_ID STREQUAL "GNU" OR |
| 54 | CMAKE_C_COMPILER_ID MATCHES "Clang") |
| 55 | message ( STATUS "adding GCC/Clang options ") |
| 56 | add_definitions( -std=gnu99 -Wall -Wextra -pedantic ) |
| 57 | if ( fatal_warnings ) |
| 58 | add_definitions( -Werror ) |
| 59 | endif () |
| 60 | if (optimize) |
Jim Schaad | c6ccea1 | 2015-12-29 18:09:12 -0800 | [diff] [blame] | 61 | add_definitions( -Os ) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 62 | endif () |
Jim Schaad | af88411 | 2016-01-03 16:11:19 -0800 | [diff] [blame] | 63 | add_definitions( -DNDEBUG ) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 64 | elseif (MSVC) |
Jim Schaad | f83908c | 2015-09-02 10:56:01 -0700 | [diff] [blame] | 65 | add_definitions ( /W4 ) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 66 | if (fatal_warnings) |
| 67 | add_definitions( /WX ) |
| 68 | endif () |
| 69 | else () |
Jim Schaad | f6addf0 | 2015-11-22 12:58:30 -0800 | [diff] [blame] | 70 | message ( FATAL_ERROR "unhandled compiler id: ${CMAKE_C_COMPILER_ID}" ) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 71 | endif () |
| 72 | |
Jim Schaad | f6addf0 | 2015-11-22 12:58:30 -0800 | [diff] [blame] | 73 | set (LIB_TYPE STATIC) |
| 74 | if (build_shared_libs) |
| 75 | set (LIB_TYPE SHARED) |
| 76 | endif (build_shared_libs) |
| 77 | |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 78 | if (versbose) |
| 79 | set (CMAKE_VERBOSE_MAKEFILE ON) |
| 80 | endif () |
| 81 | |
Jim Schaad | c4b2d05 | 2015-09-03 19:58:43 -0700 | [diff] [blame] | 82 | include (CTest) |
Jim Schaad | 4ac33ab | 2015-09-01 19:06:35 -0700 | [diff] [blame] | 83 | |
| 84 | ## try for documentation |
| 85 | if (build_docs) |
| 86 | if (NOT DOXYGEN_FOUND) |
| 87 | message(FATAL_ERROR "Doxygen is needed to build the documenation") |
| 88 | endif() |
| 89 | |
| 90 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 91 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 92 | |
| 93 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 94 | |
| 95 | add_custom_target(doc |
| 96 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 97 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 98 | COMMENT "Generating API documentation with Doxygen" |
| 99 | VERBATIM) |
| 100 | |
| 101 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc) |
| 102 | endif() |
Jim Schaad | f83908c | 2015-09-02 10:56:01 -0700 | [diff] [blame] | 103 | |
| 104 | Include(ExternalProject) |
| 105 | ExternalProject_Add( |
| 106 | project_cn-cbor |
Jim Schaad | ab94ae7 | 2015-09-02 11:29:54 -0700 | [diff] [blame] | 107 | GIT_REPOSITORY https://github.com/jimsch/cn-cbor |
Jim Schaad | 9196709 | 2015-12-29 18:07:04 -0800 | [diff] [blame] | 108 | GIT_TAG PrettyPrint |
Jim Schaad | 779cde5 | 2015-12-29 18:04:13 -0800 | [diff] [blame] | 109 | CMAKE_ARGS -Doptimize=OFF -Duse_context=${use_context} -Dbuild_docs=OFF -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -Dcoveralls=OFF -Dbuild_shared_libs=${build_shared_libs} -Dfatal_warnings=OFF |
Jim Schaad | f83908c | 2015-09-02 10:56:01 -0700 | [diff] [blame] | 110 | INSTALL_DIR "${dist_dir}" |
| 111 | UPDATE_DISCONNECTED 1 |
| 112 | ) |
| 113 | |
| 114 | ExternalProject_Get_Property(project_cn-cbor install_dir) |
| 115 | include_directories ( "${install_dir}/include" ) |
| 116 | add_library (cn-cbor STATIC IMPORTED) |
| 117 | set_property (TARGET cn-cbor PROPERTY IMPORTED_LOCATION "${install_dir}/lib/${CMAKE_SHARED_MODULE_PREFIX}cn-cbor${CMAKE_SHARED_LIBRARY_SUFFIX}") |
Jim Schaad | ab94ae7 | 2015-09-02 11:29:54 -0700 | [diff] [blame] | 118 | add_dependencies(cn-cbor project_cn-cbor) |
Jim Schaad | 0e727e8 | 2015-09-02 18:21:39 -0700 | [diff] [blame] | 119 | |
| 120 | |
| 121 | ## include the parts |
| 122 | add_subdirectory(src) |
| 123 | add_subdirectory(test) |
Jim Schaad | f6addf0 | 2015-11-22 12:58:30 -0800 | [diff] [blame] | 124 | add_subdirectory(dumper) |
| 125 | |