| 1 |
################################################################################### |
| 2 |
# # |
| 3 |
# NAME: CMakeLists.txt # |
| 4 |
# # |
| 5 |
# AUTHOR: Mike Karlesky, Mark VanderVoord, Greg Williams. # |
| 6 |
# WRITTEN BY: Michael Brockus. # |
| 7 |
# # |
| 8 |
# License: MIT # |
| 9 |
# # |
| 10 |
################################################################################### |
| 11 |
|
| 12 |
cmake_minimum_required(VERSION 3.12) |
| 13 |
|
| 14 |
# Read src/unity.h file and get project version from it |
| 15 |
set(UNITY_HEADER "src/unity.h") |
| 16 |
|
| 17 |
file(STRINGS "${UNITY_HEADER}" UNITY_HEADER_CONTENT |
| 18 |
REGEX "^#define UNITY_VERSION_(MAJOR|MINOR|BUILD) +[0-9]+$" |
| 19 |
) |
| 20 |
|
| 21 |
set(UNITY_HEADER_VERSION_MAJOR 0) |
| 22 |
set(UNITY_HEADER_VERSION_MINOR 0) |
| 23 |
set(UNITY_HEADER_VERSION_BUILD 0) |
| 24 |
|
| 25 |
foreach(VERSION_LINE IN LISTS UNITY_HEADER_CONTENT) |
| 26 |
foreach(VERSION_PART MAJOR MINOR BUILD) |
| 27 |
string(CONCAT REGEX_STRING "#define UNITY_VERSION_" |
| 28 |
"${VERSION_PART}" |
| 29 |
" +([0-9]+)" |
| 30 |
) |
| 31 |
|
| 32 |
if(VERSION_LINE MATCHES "${REGEX_STRING}") |
| 33 |
set(UNITY_HEADER_VERSION_${VERSION_PART} "${CMAKE_MATCH_1}") |
| 34 |
endif() |
| 35 |
endforeach() |
| 36 |
endforeach() |
| 37 |
|
| 38 |
project(unity |
| 39 |
VERSION ${UNITY_HEADER_VERSION_MAJOR}.${UNITY_HEADER_VERSION_MINOR}.${UNITY_HEADER_VERSION_BUILD} |
| 40 |
LANGUAGES C |
| 41 |
DESCRIPTION "C Unit testing framework." |
| 42 |
) |
| 43 |
|
| 44 |
# Options to Build With Extras ------------------------------------------------- |
| 45 |
option(UNITY_EXTENSION_FIXTURE "Compiles Unity with the \"fixture\" extension." OFF) |
| 46 |
option(UNITY_EXTENSION_MEMORY "Compiles Unity with the \"memory\" extension." OFF) |
| 47 |
|
| 48 |
set(UNITY_EXTENSION_FIXTURE_ENABLED $<BOOL:${UNITY_EXTENSION_FIXTURE}>) |
| 49 |
set(UNITY_EXTENSION_MEMORY_ENABLED $<OR:${UNITY_EXTENSION_FIXTURE_ENABLED},$<BOOL:${UNITY_EXTENSION_MEMORY}>>) |
| 50 |
|
| 51 |
if(${UNITY_EXTENSION_FIXTURE}) |
| 52 |
message(STATUS "Unity: Building with the fixture extension.") |
| 53 |
endif() |
| 54 |
|
| 55 |
if(${UNITY_EXTENSION_MEMORY}) |
| 56 |
message(STATUS "Unity: Building with the memory extension.") |
| 57 |
endif() |
| 58 |
|
| 59 |
# Main target ------------------------------------------------------------------ |
| 60 |
add_library(${PROJECT_NAME} STATIC) |
| 61 |
add_library(${PROJECT_NAME}::framework ALIAS ${PROJECT_NAME}) |
| 62 |
|
| 63 |
# Includes --------------------------------------------------------------------- |
| 64 |
include(GNUInstallDirs) |
| 65 |
include(CMakePackageConfigHelpers) |
| 66 |
|
| 67 |
target_sources(${PROJECT_NAME} |
| 68 |
PRIVATE |
| 69 |
src/unity.c |
| 70 |
$<$<BOOL:${UNITY_EXTENSION_FIXTURE_ENABLED}>:extras/fixture/src/unity_fixture.c> |
| 71 |
$<$<BOOL:${UNITY_EXTENSION_MEMORY_ENABLED}>:extras/memory/src/unity_memory.c> |
| 72 |
) |
| 73 |
|
| 74 |
target_include_directories(${PROJECT_NAME} |
| 75 |
PUBLIC |
| 76 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> |
| 77 |
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> |
| 78 |
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}> |
| 79 |
$<BUILD_INTERFACE:$<$<BOOL:${UNITY_EXTENSION_MEMORY_ENABLED}>:${CMAKE_CURRENT_SOURCE_DIR}/extras/memory/src>> |
| 80 |
$<BUILD_INTERFACE:$<$<BOOL:${UNITY_EXTENSION_FIXTURE_ENABLED}>:${CMAKE_CURRENT_SOURCE_DIR}/extras/fixture/src>> |
| 81 |
) |
| 82 |
|
| 83 |
set(${PROJECT_NAME}_PUBLIC_HEADERS |
| 84 |
src/unity.h |
| 85 |
src/unity_internals.h |
| 86 |
$<$<BOOL:${UNITY_EXTENSION_FIXTURE_ENABLED}>:${CMAKE_CURRENT_SOURCE_DIR}/extras/fixture/src/unity_fixture.h> |
| 87 |
$<$<BOOL:${UNITY_EXTENSION_FIXTURE_ENABLED}>:${CMAKE_CURRENT_SOURCE_DIR}/extras/fixture/src/unity_fixture_internals.h> |
| 88 |
$<$<BOOL:${UNITY_EXTENSION_MEMORY_ENABLED}>:${CMAKE_CURRENT_SOURCE_DIR}/extras/memory/src/unity_memory.h> |
| 89 |
) |
| 90 |
|
| 91 |
set_target_properties(${PROJECT_NAME} |
| 92 |
PROPERTIES |
| 93 |
C_STANDARD 11 |
| 94 |
C_STANDARD_REQUIRED ON |
| 95 |
C_EXTENSIONS OFF |
| 96 |
PUBLIC_HEADER "${${PROJECT_NAME}_PUBLIC_HEADERS}" |
| 97 |
EXPORT_NAME framework |
| 98 |
) |
| 99 |
|
| 100 |
target_compile_options(${PROJECT_NAME} |
| 101 |
PRIVATE |
| 102 |
# Clang |
| 103 |
$<$<C_COMPILER_ID:Clang>: |
| 104 |
-Wcast-align |
| 105 |
-Wcast-qual |
| 106 |
-Wconversion |
| 107 |
-Wexit-time-destructors |
| 108 |
-Wglobal-constructors |
| 109 |
-Wmissing-noreturn |
| 110 |
-Wmissing-prototypes |
| 111 |
-Wno-missing-braces |
| 112 |
-Wold-style-cast |
| 113 |
-Wshadow |
| 114 |
-Wweak-vtables |
| 115 |
-Werror |
| 116 |
-Wall |
| 117 |
$<$<VERSION_GREATER_EQUAL:$<C_COMPILER_VERSION>,8.0.0>:-Wextra-semi-stmt> |
| 118 |
> |
| 119 |
|
| 120 |
# GCC |
| 121 |
$<$<C_COMPILER_ID:GNU>: |
| 122 |
-Waddress |
| 123 |
-Waggregate-return |
| 124 |
-Wformat-nonliteral |
| 125 |
-Wformat-security |
| 126 |
-Wformat |
| 127 |
-Winit-self |
| 128 |
-Wmissing-declarations |
| 129 |
-Wmissing-include-dirs |
| 130 |
-Wno-multichar |
| 131 |
-Wno-parentheses |
| 132 |
-Wno-type-limits |
| 133 |
-Wno-unused-parameter |
| 134 |
-Wunreachable-code |
| 135 |
-Wwrite-strings |
| 136 |
-Wpointer-arith |
| 137 |
-Werror |
| 138 |
-Wall |
| 139 |
> |
| 140 |
|
| 141 |
# MSVC |
| 142 |
$<$<C_COMPILER_ID:MSVC>: |
| 143 |
/Wall |
| 144 |
> |
| 145 |
) |
| 146 |
|
| 147 |
write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake |
| 148 |
VERSION ${PROJECT_VERSION} |
| 149 |
COMPATIBILITY SameMajorVersion |
| 150 |
) |
| 151 |
|
| 152 |
## Target installation |
| 153 |
install(TARGETS ${PROJECT_NAME} |
| 154 |
EXPORT ${PROJECT_NAME}Targets |
| 155 |
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 156 |
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 157 |
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} |
| 158 |
COMPONENT library |
| 159 |
) |
| 160 |
|
| 161 |
## Target's cmake files: targets export |
| 162 |
install(EXPORT ${PROJECT_NAME}Targets |
| 163 |
NAMESPACE ${PROJECT_NAME}:: |
| 164 |
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} |
| 165 |
) |
| 166 |
|
| 167 |
## Target's cmake files: config and version config for find_package() |
| 168 |
install(FILES ${PROJECT_NAME}Config.cmake |
| 169 |
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake |
| 170 |
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} |
| 171 |
) |