forked from cose-wg/COSE-C
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
143 lines (117 loc) · 4.56 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#
# top level build file for COSE-C
#
## prepare CMAKE
cmake_minimum_required( VERSION 3.0.0)
set (VERSION_MAJOR 0 CACHE STRING "Project major version number")
set (VERSION_MINOR "1" CACHE STRING "Project minor version number")
set (VERSION_PATCH "0" CACHE STRING "Project patch version number")
set (COSE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
mark_as_advanced(VERSION_MAJOR VERSION_MINOR VERSION_PATCH COSE_VERSION)
project ("cose-c" VERSION "${COSE_VERSION}")
find_package(Doxygen)
find_package(OpenSSL 1.0 REQUIRED)
### setup options
option (use_context "Use context pointer for COSE functions" ON)
option (verbose "Produce verbose makefile output" OFF)
option (optimize "Optimize for size" OFF)
option (fatal_warnings "Treat build warnings as error" OFF)
option (coveralls "Generate coveralls data" ON)
option ( coveralls_send "Send data to coveralls site" OFF )
option (build_docs "Create docs using Doxygen" ${DOXYGEN_FOUND} )
option (build_shared_libs "Build Shared Libraries" ON)
option (use_embedtls "Use MBedTLS for the Crypto Package" OFF)
set ( dist_dir ${CMAKE_BINARY_DIR}/dist )
set ( prefix ${CMAKE_INSTALL_PREFIX} )
set ( exec_prefix ${CMAKE_INSTALL_PREFIX}/bin )
set ( libdir ${CMAKE_INSTALL_PREFIX}/lib )
set ( includedir ${CMAKE_INSTALL_PREFIX}/include )
if (NOT CMAKE_BUILD_TYPE)
if (optimize)
set ( CMAKE_BUILD_TYPE MinSizeRel )
set ( coveralls OFF )
set ( coveralls_send OFF )
else ()
set ( CMAKE_BUILD_TYPE Debug)
endif ()
endif ()
if ( MSVC )
set (coveralls OFF)
endif ()
message ( "Build type: ${CMAKE_BUILD_TYPE}" )
add_definitions( -DUSE_ARRAY )
if ( CMAKE_C_COMPILER_ID STREQUAL "GNU" OR
CMAKE_C_COMPILER_ID MATCHES "Clang")
message ( STATUS "adding GCC/Clang options ")
add_definitions( -std=gnu99 -Wall -Wextra -pedantic )
if ( fatal_warnings )
add_definitions( -Werror )
endif ()
if (optimize)
add_definitions( -Os )
endif ()
add_definitions( -DNDEBUG )
elseif (MSVC)
add_definitions ( /W4 )
if (fatal_warnings)
add_definitions( /WX )
endif ()
else ()
message ( FATAL_ERROR "unhandled compiler id: ${CMAKE_C_COMPILER_ID}" )
endif ()
set (LIB_TYPE STATIC)
if (build_shared_libs)
set (LIB_TYPE SHARED)
endif (build_shared_libs)
if (versbose)
set (CMAKE_VERBOSE_MAKEFILE ON)
endif ()
include (CTest)
## try for documentation
if (build_docs)
if (NOT DOXYGEN_FOUND)
message(FATAL_ERROR "Doxygen is needed to build the documenation")
endif()
set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION share/doc)
endif()
Include(ExternalProject)
ExternalProject_Add(
project_cn-cbor
GIT_REPOSITORY https://github.com/jimsch/cn-cbor
GIT_TAG complete
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
INSTALL_DIR "${dist_dir}"
UPDATE_DISCONNECTED 1
)
ExternalProject_Get_Property(project_cn-cbor install_dir)
include_directories ( "${install_dir}/include" )
add_library (cn-cbor STATIC IMPORTED)
set_property (TARGET cn-cbor PROPERTY IMPORTED_LOCATION "${install_dir}/lib/${CMAKE_SHARED_MODULE_PREFIX}cn-cbor${CMAKE_SHARED_LIBRARY_SUFFIX}")
add_dependencies(cn-cbor project_cn-cbor)
if (use_embedtls)
add_definitions( -DUSE_MBED_TLS )
ExternalProject_Add(
project_embedtls
GIT_REPOSITORY https://github.com/ARMmbed/mbedtls
CMAKE_ARGS -DENABLED_PROGRAMS=OFF -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -Dcoveralls=OFF -DUSE_SHARED_MBEDTLS_LIBRARY=${build_shared_libs} -Dfatal_warnings=OFF -DENABLE_TESTING=OFF -DLIB_INSTALL_DIR=${install_dir}/lib
INTALL_DIR "${dist_dir}"
UPDATE_DISCONNECTED 1
)
ExternalProject_Get_Property(project_embedtls install_dir)
include_directories( "${install_dir}/include" )
add_library( embedtls STATIC IMPORTED)
set_property (TARGET embedtls PROPERTY IMPORTED_LOCATION "${dist_dir}/lib/${CMAKE_SHARED_MODULE_PREFIX}mbedcrypto${CMAKE_SHARED_LIBRARY_SUFFIX}")
add_dependencies(embedtls project_embedtls)
endif ()
## include the parts
add_subdirectory(src)
add_subdirectory(test)
add_subdirectory(dumper)