-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
148 lines (117 loc) · 4.36 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
#
# Copyright (c) 2020 Bjørn Fuglestad, Jaersense AS ([email protected])
#
# Distributed under the Boost Software License, Version 1.0. (See accompanying
# file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
#
# Official repository: https://github.com/bjorn-jaes/jay
#
cmake_minimum_required(VERSION 3.13)
# ============================================================================================
# Constants
# ============================================================================================
string(APPEND APPLICATION_NAME "jay")
string(APPEND INCLUDE_DIR "include")
#string(APPEND USR_INCLUDE_PREFIX "/usr/include/")
#string(APPEND TRIPLE_LIB_PREFIX "/usr/lib/aarch64-linux-gnu/")
# ============================================================================================
# Project Description
# ============================================================================================
project(jay VERSION 0.2 DESCRIPTION "J1939 library" LANGUAGES CXX)
# ============================================================================================
# Build Options
# ============================================================================================
#set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
option(THREADS_PREFER_PTHREAD_FLAG "Prefere pthread threads" ON)
option(BUILD_TESTING "Build jay tests." ON)
option(BUILD_EXAMPLES "Build examples." ON)
option(BUILD_DOCS "Build jay documentation." OFF)
# ============================================================================================
# Libraries
# ============================================================================================
#find_package(PkgConfig REQUIRED)
# Dont need to look for SML as its a single header file
#Fing Canary
find_package(canary REQUIRED)
#Find Boost
find_package(Boost COMPONENTS system REQUIRED) # header only libraries must not be added here
#Find threads
find_package(Threads)
# ============================================================================================
# Declare Executable, This creates targets
# ============================================================================================
add_library(${APPLICATION_NAME} INTERFACE)
add_library(jay::jay ALIAS ${APPLICATION_NAME})
target_include_directories(${APPLICATION_NAME} INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(
${APPLICATION_NAME}
INTERFACE
Boost::system
canary::canary
Threads::Threads
)
target_compile_features(${APPLICATION_NAME} INTERFACE cxx_std_17)
# =============================================
# Build Tests
# =============================================
#include(CTest)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
# =============================================
# Build Examples
# =============================================
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# =============================================
# Build Doc
# =============================================
if (BUILD_DOCS)
file(GLOB JAY_HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}/${APPLICATION_NAME}/*.hpp")
find_package(standardese REQUIRED)
standardese_generate(jay_docs
INCLUDE_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}
${Boost_INCLUDE_DIR}
INPUT ${JAY_HEADERS})
endif()
# =============================================
# Install Target
# =============================================
include(GNUInstallDirs)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${INCLUDE_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.ipp"
)
install(TARGETS ${APPLICATION_NAME}
EXPORT jayTargets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
set(jay_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
unset(CMAKE_SIZEOF_VOID_P)
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"jayConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion
)
set(CMAKE_SIZEOF_VOID_P ${jay_SIZEOF_VOID_P})
unset(jay_SIZEOF_VOID_P)
install(FILES
"jayConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/jayConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${APPLICATION_NAME}
)
install(EXPORT jayTargets
FILE jayTargets.cmake
NAMESPACE ${APPLICATION_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${APPLICATION_NAME}
)