blob: 863bc2702c82123bc064950128c2278ed710e372 [file] [log] [blame]
Jim Schaad4ac33ab2015-09-01 19:06:35 -07001#
2# top level build file for COSE-C
3#
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 (COSE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
12mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH COSE_VERSION)
13
14project ("cose-c" VERSION "${COSE_VERSION}")
15
16find_package(Doxygen)
Jim Schaad0e727e82015-09-02 18:21:39 -070017find_package(OpenSSL 1.0 REQUIRED)
Jim Schaad4ac33ab2015-09-01 19:06:35 -070018
19### setup options
20option (use_context "Use context pointer for COSE functions" ON)
21option (verbose "Produce verbose makefile output" OFF)
22option (optimize "Optimize for size" OFF)
23option (fatal_warnings "Treat build warnings as error" OFF)
Jim Schaadd09c2112015-12-26 21:48:53 -080024option (coveralls "Generate coveralls data" ON)
Jim Schaadf6addf02015-11-22 12:58:30 -080025option ( coveralls_send "Send data to coveralls site" OFF )
Jim Schaad4ac33ab2015-09-01 19:06:35 -070026option (build_docs "Create docs using Doxygen" ${DOXYGEN_FOUND} )
Jim Schaadd09c2112015-12-26 21:48:53 -080027option (build_shared_libs "Build Shared Libraries" ON)
Jim Schaad4ac33ab2015-09-01 19:06:35 -070028
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 )
34
35
36if (NOT CMAKE_BUILD_TYPE)
37 if (optimize)
38 set ( CMAKE_BUILD_TYPE MinSizeRel )
39 set ( coveralls OFF )
Jim Schaadf7271222015-09-04 22:12:59 -070040 set ( coveralls_send OFF )
Jim Schaad4ac33ab2015-09-01 19:06:35 -070041 else ()
42 set ( CMAKE_BUILD_TYPE Debug)
43 endif ()
44endif ()
45
Jim Schaadd09c2112015-12-26 21:48:53 -080046if ( MSVC )
47 set (coveralls OFF)
48endif ()
49
Jim Schaad4ac33ab2015-09-01 19:06:35 -070050message ( "Build type: ${CMAKE_BUILD_TYPE}" )
51
52add_definitions( -DUSE_ARRAY )
53if ( 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 Schaadc6ccea12015-12-29 18:09:12 -080061 add_definitions( -Os )
Jim Schaad4ac33ab2015-09-01 19:06:35 -070062 endif ()
Jim Schaadaf884112016-01-03 16:11:19 -080063 add_definitions( -DNDEBUG )
Jim Schaad4ac33ab2015-09-01 19:06:35 -070064elseif (MSVC)
Jim Schaadf83908c2015-09-02 10:56:01 -070065 add_definitions ( /W4 )
Jim Schaad4ac33ab2015-09-01 19:06:35 -070066 if (fatal_warnings)
67 add_definitions( /WX )
68 endif ()
69else ()
Jim Schaadf6addf02015-11-22 12:58:30 -080070 message ( FATAL_ERROR "unhandled compiler id: ${CMAKE_C_COMPILER_ID}" )
Jim Schaad4ac33ab2015-09-01 19:06:35 -070071endif ()
72
Jim Schaadf6addf02015-11-22 12:58:30 -080073set (LIB_TYPE STATIC)
74if (build_shared_libs)
75 set (LIB_TYPE SHARED)
76endif (build_shared_libs)
77
Jim Schaad4ac33ab2015-09-01 19:06:35 -070078if (versbose)
79 set (CMAKE_VERBOSE_MAKEFILE ON)
80endif ()
81
Jim Schaadc4b2d052015-09-03 19:58:43 -070082include (CTest)
Jim Schaad4ac33ab2015-09-01 19:06:35 -070083
84## try for documentation
85if (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)
102endif()
Jim Schaadf83908c2015-09-02 10:56:01 -0700103
104Include(ExternalProject)
105ExternalProject_Add(
106 project_cn-cbor
Jim Schaadab94ae72015-09-02 11:29:54 -0700107 GIT_REPOSITORY https://github.com/jimsch/cn-cbor
Jim Schaad91967092015-12-29 18:07:04 -0800108 GIT_TAG PrettyPrint
Jim Schaad779cde52015-12-29 18:04:13 -0800109 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 Schaadf83908c2015-09-02 10:56:01 -0700110 INSTALL_DIR "${dist_dir}"
111 UPDATE_DISCONNECTED 1
112)
113
114ExternalProject_Get_Property(project_cn-cbor install_dir)
115include_directories ( "${install_dir}/include" )
116add_library (cn-cbor STATIC IMPORTED)
117set_property (TARGET cn-cbor PROPERTY IMPORTED_LOCATION "${install_dir}/lib/${CMAKE_SHARED_MODULE_PREFIX}cn-cbor${CMAKE_SHARED_LIBRARY_SUFFIX}")
Jim Schaadab94ae72015-09-02 11:29:54 -0700118add_dependencies(cn-cbor project_cn-cbor)
Jim Schaad0e727e82015-09-02 18:21:39 -0700119
120
121## include the parts
122add_subdirectory(src)
123add_subdirectory(test)
Jim Schaadf6addf02015-11-22 12:58:30 -0800124add_subdirectory(dumper)
125