forked from ThrowTheSwitch/Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
136 lines (118 loc) · 5.09 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
###################################################################################
# #
# NAME: CMakeLists.txt #
# #
# AUTHOR: Mike Karlesky, Mark VanderVoord, Greg Williams. #
# WRITTEN BY: Michael Brockus. #
# #
# License: MIT #
# #
###################################################################################
cmake_minimum_required(VERSION 3.12)
# Read src/unity.h file and get project version from it
set(UNITY_HEADER "src/unity.h")
file(STRINGS "${UNITY_HEADER}" UNITY_HEADER_CONTENT
REGEX "^#define UNITY_VERSION_(MAJOR|MINOR|BUILD) +[0-9]+$"
)
set(UNITY_HEADER_VERSION_MAJOR 0)
set(UNITY_HEADER_VERSION_MINOR 0)
set(UNITY_HEADER_VERSION_BUILD 0)
foreach(VERSION_LINE IN LISTS UNITY_HEADER_CONTENT)
foreach(VERSION_PART MAJOR MINOR BUILD)
string(CONCAT REGEX_STRING "#define UNITY_VERSION_"
"${VERSION_PART}"
" +([0-9]+)"
)
if(VERSION_LINE MATCHES "${REGEX_STRING}")
set(UNITY_HEADER_VERSION_${VERSION_PART} "${CMAKE_MATCH_1}")
endif()
endforeach()
endforeach()
project(unity
VERSION ${UNITY_HEADER_VERSION_MAJOR}.${UNITY_HEADER_VERSION_MINOR}.${UNITY_HEADER_VERSION_BUILD}
LANGUAGES C
DESCRIPTION "C Unit testing framework."
)
# Main target ------------------------------------------------------------------
add_library(${PROJECT_NAME} STATIC)
add_library(${PROJECT_NAME}::framework ALIAS ${PROJECT_NAME})
# Includes ---------------------------------------------------------------------
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
target_sources(${PROJECT_NAME}
PRIVATE
src/unity.c
)
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}>
)
set(${PROJECT_NAME}_PUBLIC_HEADERS src/unity.h
src/unity_internals.h
)
set_target_properties(${PROJECT_NAME}
PROPERTIES
C_STANDARD 11
C_STANDARD_REQUIRED ON
C_EXTENSIONS OFF
PUBLIC_HEADER "${${PROJECT_NAME}_PUBLIC_HEADERS}"
EXPORT_NAME framework
)
target_compile_options(${PROJECT_NAME}
PRIVATE
$<$<C_COMPILER_ID:Clang>:-Wcast-align
-Wcast-qual
-Wconversion
-Wexit-time-destructors
-Wglobal-constructors
-Wmissing-noreturn
-Wmissing-prototypes
-Wno-missing-braces
-Wold-style-cast
-Wshadow
-Wweak-vtables
-Werror
-Wall>
$<$<C_COMPILER_ID:GNU>:-Waddress
-Waggregate-return
-Wformat-nonliteral
-Wformat-security
-Wformat
-Winit-self
-Wmissing-declarations
-Wmissing-include-dirs
-Wno-multichar
-Wno-parentheses
-Wno-type-limits
-Wno-unused-parameter
-Wunreachable-code
-Wwrite-strings
-Wpointer-arith
-Werror
-Wall>
$<$<C_COMPILER_ID:MSVC>:/Wall>
)
write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
## Target installation
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
COMPONENT library
)
## Target's cmake files: targets export
install(EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
## Target's cmake files: config and version config for find_package()
install(FILES ${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)