-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
168 lines (134 loc) · 5.39 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#
# Copyright (C) 2020 Clovis Durand
#
# -----------------------------------------------------------------------------
# CMake version required ----------------------------------
cmake_minimum_required(VERSION 3.9)
# Project definition --------------------------------------
project(OSCO VERSION "1.0.0")
#------------------------------------------------------------------------------
# Build definition (to do before calling 'project()')
#------------------------------------------------------------------------------
# Build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif(NOT CMAKE_BUILD_TYPE)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG=1)
endif(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Build type is : ${CMAKE_BUILD_TYPE}")
# CASE OF C PROJECT
set(CMAKE_C_STANDARD 99)
if(NOT CMAKE_C_FLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wformat-security -pedantic" CACHE STRING "C99 compilation flags" FORCE)
endif(NOT CMAKE_C_FLAGS)
# CASE OF CPP PROJECT
set(CMAKE_CXX_STANDARD 17)
if(NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wformat-security -pedantic" CACHE STRING "C++17 compilation flags" FORCE)
endif(NOT CMAKE_CXX_FLAGS)
#------------------------------------------------------------------------------
# Project definition, variable and dependencies
#------------------------------------------------------------------------------
set(CMAKE_PROJECT_NAME ${PROJECT_NAME})
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_PROJECT_BRIEF "Open Source CANOpen stack")
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
if(NOT INSTALL_DESTINATION_SET)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/dest CACHE PATH "" FORCE)
set(INSTALL_DESTINATION_SET TRUE)
endif(NOT INSTALL_DESTINATION_SET)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# Allow CTest
enable_testing()
# Allow subdirectory test and docs
option(ENABLE_TESTS "Enable Tests" 1)
option(ENABLE_EXAMPLES "Enable Examples" 1)
find_package(Doxygen)
option(ENABLE_DOCS "Build API documentation" ${DOXYGEN_FOUND})
#------------------------------------------------------------------------------
# pkg-config dependencies
#------------------------------------------------------------------------------
set(ENV{PKG_CONFIG_PATH} "ENV{PKG_CONFIG_PATH}:${PKG_CONFIG_PATH}")
message(STATUS "Pkgconfig extra path are: $ENV{PKG_CONFIG_PATH}")
#------------------------------------------------------------------------------
# Project version
#------------------------------------------------------------------------------
# Get the latest abbreviated commit hash of the working branch
execute_process(
COMMAND git log -1 --format=%h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE GIT_COMMIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE
"^([\\.0-9]+).*"
"\\1"
tmp_VERSION
"${PRJ_VERSION}"
)
string(REGEX REPLACE
"^([0-9]+)\\..*"
"\\1"
tmp_SOVERSION
"${tmp_VERSION}"
)
# Major version is for product/marketing purpose
set(MAJ_MIN_VERSION ${tmp_VERSION} CACHE STRING "Major and minor version" FORCE)
set(RELEASE_VERSION ${tmp_SOVERSION} CACHE STRING "Release version" FORCE)
# Build version is generated using the hash of the current commit build with
set(BUILD_VERSION ${GIT_COMMIT_HASH} CACHE STRING "Build version" FORCE)
message(STATUS "OSCO OD Gen version : ${CMAKE_PROJECT_VERSION}")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/inc/Version.h.in
${CMAKE_CURRENT_SOURCE_DIR}/inc/Version.h
)
#------------------------------------------------------------------------------
# pkgconfig
#------------------------------------------------------------------------------
find_package(PkgConfig REQUIRED)
if(PKG_CONFIG_FOUND)
# Produce a pkg-config file
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.pc.in
${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.pc
@ONLY
)
install (
FILES ${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_PROJECT_NAME}.pc
DESTINATION lib/pkgconfig
)
endif(PKG_CONFIG_FOUND)
#------------------------------------------------------------------------------
# Project configuration
#------------------------------------------------------------------------------
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gen)
#------------------------------------------------------------------------------
# Sub-directories
#------------------------------------------------------------------------------
# Main build
add_subdirectory(gen)
add_subdirectory(src)
# Builds dependent on main build
if(ENABLE_TESTS)
message(STATUS "TESTS enabled")
add_subdirectory(tests)
else()
message(STATUS "TESTS disabled")
endif(ENABLE_TESTS)
if(ENABLE_DOCS)
message(STATUS "DOCS enabled")
add_subdirectory(docs)
else()
message(STATUS "DOCS disabled")
endif (ENABLE_DOCS)
if(ENABLE_EXAMPLES)
message(STATUS "EXAMPLES enabled")
add_subdirectory(examples)
else()
message(STATUS "EXAMPLES disabled")
endif (ENABLE_EXAMPLES)