From d603ccdc3b67501ef3375d347864f04e682d6547 Mon Sep 17 00:00:00 2001 From: Vitalii Shylienkov Date: Thu, 9 Apr 2020 13:58:45 +0200 Subject: [PATCH 1/4] cmake: update CMake --- CMakeLists.txt | 110 +++++++++++++++++++++++++---- cmake/templates/unity_version.h.in | 12 ++++ src/CMakeLists.txt | 22 ------ src/unity.h | 5 +- unityConfig.cmake | 1 + 5 files changed, 111 insertions(+), 39 deletions(-) create mode 100644 cmake/templates/unity_version.h.in delete mode 100644 src/CMakeLists.txt create mode 100644 unityConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 08fafd9d..ecfb539f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,24 +8,108 @@ # License: MIT # # # ################################################################################### -cmake_minimum_required(VERSION 3.0 FATAL_ERROR) +cmake_minimum_required(VERSION 3.12) +project(unity + VERSION 2.5.0 + 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) + +# Configuration ---------------------------------------------------------------- +configure_file(cmake/templates/${PROJECT_NAME}_version.h.in + ${PROJECT_NAME}_version.h + @ONLY +) + +target_sources(${PROJECT_NAME} + PRIVATE + src/unity.c +) + +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + $ +) + +set(${PROJECT_NAME}_PUBLIC_HEADERS src/unity.h + src/unity_internals.h + ${CMAKE_CURRENT_BINARY_DIR}/unity_version.h +) -project(unity LANGUAGES C DESCRIPTION "C Unit testing framework.") +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 +) -add_subdirectory(src) -target_include_directories(unity - PUBLIC - "$" - "$" +target_compile_options(${PROJECT_NAME} + PRIVATE + $<$:-Wcast-align> + $<$:-Wcast-qual> + $<$:-Wconversion> + $<$:-Wexit-time-destructors> + $<$:-Wglobal-constructors> + $<$:-Wmissing-noreturn> + $<$:-Wmissing-prototypes> + $<$:-Wno-missing-braces> + $<$:-Wold-style-cast> + $<$:-Wshadow> + $<$:-Wweak-vtables> + $<$:-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 + -Wall + -Werror +) - PRIVATE "src" +write_basic_package_version_file(${PROJECT_NAME}ConfigVersion.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion ) -add_library(unity::framework ALIAS unity) +## 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 +) -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/ DESTINATION src) -install(EXPORT unityConfig DESTINATION share/unityConfig/cmake) +## Target's cmake files: targets export +install(EXPORT ${PROJECT_NAME}Targets + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) -# This makes the project importable from the build directory -export(TARGETS unity FILE unityConfig.cmake) +## 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} +) diff --git a/cmake/templates/unity_version.h.in b/cmake/templates/unity_version.h.in new file mode 100644 index 00000000..7c89e773 --- /dev/null +++ b/cmake/templates/unity_version.h.in @@ -0,0 +1,12 @@ +#ifndef UNITY_CONFIG_H +#define UNITY_CONFIG_H + +#define UNITY_VERSION_STRING "@PROJECT_VERSION@" +#define UNITY_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ +#define UNITY_VERSION_MINOR @PROJECT_VERSION_MINOR@ +#define UNITY_VERSION_BUILD @PROJECT_VERSION_PATCH@ +#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | \ + (UNITY_VERSION_MINOR << 8) | \ + UNITY_VERSION_BUILD) + +#endif /* UNITY_CONFIG_H */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt deleted file mode 100644 index c747cb0a..00000000 --- a/src/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -################################################################################### -# # -# NAME: CMakeLists.txt # -# # -# AUTHOR: Mike Karlesky, Mark VanderVoord, Greg Williams. # -# WRITTEN BY: Michael Brockus. # -# # -# License: MIT # -# # -################################################################################### -cmake_minimum_required(VERSION 3.0 FATAL_ERROR) - - -add_library(unity STATIC "unity.c") - -install(TARGETS unity EXPORT unityConfig - ARCHIVE DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_BINDIR}" - INCLUDES DESTINATION "${CMAKE_INSTALL_LIBDIR}") - - diff --git a/src/unity.h b/src/unity.h index 925cd4d5..6eceb8da 100644 --- a/src/unity.h +++ b/src/unity.h @@ -8,10 +8,7 @@ #define UNITY_FRAMEWORK_H #define UNITY -#define UNITY_VERSION_MAJOR 2 -#define UNITY_VERSION_MINOR 5 -#define UNITY_VERSION_BUILD 0 -#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD) +#include "unity_version.h" #ifdef __cplusplus extern "C" diff --git a/unityConfig.cmake b/unityConfig.cmake new file mode 100644 index 00000000..55410ccc --- /dev/null +++ b/unityConfig.cmake @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_LIST_DIR}/unityTargets.cmake) \ No newline at end of file From 2a2a4d19c545aed85dfb541e8b0a5ccbe4b1deb7 Mon Sep 17 00:00:00 2001 From: Vitalii Shylienkov Date: Mon, 13 Apr 2020 12:47:07 +0200 Subject: [PATCH 2/4] meson: supports version - generate version header --- meson.build | 3 ++- src/meson.build | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 968e5b13..33d58875 100644 --- a/meson.build +++ b/meson.build @@ -7,7 +7,8 @@ project('unity', 'c', license: 'MIT', meson_version: '>=0.53.0', - default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11'] + default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11'], + version: '2.5.0' ) lang = 'c' cc = meson.get_compiler(lang) diff --git a/src/meson.build b/src/meson.build index 7ede15af..19e7bd8e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,6 +4,15 @@ # # license: MIT # +conf_data = configuration_data() +conf_data.set('PROJECT_VERSION', meson.project_version()) +conf_data.set('PROJECT_VERSION_MAJOR',meson.project_version().split('.')[0]) +conf_data.set('PROJECT_VERSION_MINOR',meson.project_version().split('.')[1]) +conf_data.set('PROJECT_VERSION_PATCH',meson.project_version().split('.')[2]) +unity_version_template = join_paths(meson.source_root(), 'cmake/templates/unity_version.h.in') +unity_version_file =configure_file(input : unity_version_template, + output : 'unity_version.h', + configuration : conf_data) unity_dir = include_directories('.') unity_lib = static_library(meson.project_name(), From b397a72e897a55bb34eaebfcf27ec65eef85dd00 Mon Sep 17 00:00:00 2001 From: Vitalii Shylienkov Date: Mon, 13 Apr 2020 13:08:18 +0200 Subject: [PATCH 3/4] cmake: get version from meson --- CMakeLists.txt | 64 +++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ecfb539f..70de467c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,18 @@ ################################################################################### cmake_minimum_required(VERSION 3.12) + +# Read root meson.build file and get project version from it +set(ROOT_MESON_BUILD_FILE "meson.build") +file(READ "${ROOT_MESON_BUILD_FILE}" ROOT_MESON_BUILD_CONTENT) +string(REGEX MATCH " *version: '[.0-9]+'" UNITY_VERSION "${ROOT_MESON_BUILD_CONTENT}") +if(NOT UNITY_VERSION) + message(FATAL_ERROR "Cannot define version from meson build file") +endif() +string(REGEX REPLACE " *version: '([.0-9]+)'" "\\1" UNITY_VERSION "${UNITY_VERSION}") + project(unity - VERSION 2.5.0 + VERSION ${UNITY_VERSION} LANGUAGES C DESCRIPTION "C Unit testing framework." ) @@ -58,32 +68,32 @@ set_target_properties(${PROJECT_NAME} target_compile_options(${PROJECT_NAME} PRIVATE - $<$:-Wcast-align> - $<$:-Wcast-qual> - $<$:-Wconversion> - $<$:-Wexit-time-destructors> - $<$:-Wglobal-constructors> - $<$:-Wmissing-noreturn> - $<$:-Wmissing-prototypes> - $<$:-Wno-missing-braces> - $<$:-Wold-style-cast> - $<$:-Wshadow> - $<$:-Wweak-vtables> - $<$:-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 + $<$:-Wcast-align + -Wcast-qual + -Wconversion + -Wexit-time-destructors + -Wglobal-constructors + -Wmissing-noreturn + -Wmissing-prototypes + -Wno-missing-braces + -Wold-style-cast + -Wshadow + -Wweak-vtables> + $<$:-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> -Wall -Werror ) From a2af08c773803755e90614615fe9b649f5b242e6 Mon Sep 17 00:00:00 2001 From: Vitalii Shylienkov Date: Tue, 14 Apr 2020 11:02:24 +0200 Subject: [PATCH 4/4] project: revert UNITY_VERSION_* to unity.h --- CMakeLists.txt | 40 ++++++++++++++++++------------ cmake/templates/unity_version.h.in | 12 --------- meson.build | 3 +-- src/meson.build | 9 ------- src/unity.h | 5 +++- 5 files changed, 29 insertions(+), 40 deletions(-) delete mode 100644 cmake/templates/unity_version.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 70de467c..3a9d8a94 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,17 +11,32 @@ cmake_minimum_required(VERSION 3.12) -# Read root meson.build file and get project version from it -set(ROOT_MESON_BUILD_FILE "meson.build") -file(READ "${ROOT_MESON_BUILD_FILE}" ROOT_MESON_BUILD_CONTENT) -string(REGEX MATCH " *version: '[.0-9]+'" UNITY_VERSION "${ROOT_MESON_BUILD_CONTENT}") -if(NOT UNITY_VERSION) - message(FATAL_ERROR "Cannot define version from meson build file") -endif() -string(REGEX REPLACE " *version: '([.0-9]+)'" "\\1" UNITY_VERSION "${UNITY_VERSION}") +# 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_VERSION} + VERSION ${UNITY_HEADER_VERSION_MAJOR}.${UNITY_HEADER_VERSION_MINOR}.${UNITY_HEADER_VERSION_BUILD} LANGUAGES C DESCRIPTION "C Unit testing framework." ) @@ -34,12 +49,6 @@ add_library(${PROJECT_NAME}::framework ALIAS ${PROJECT_NAME}) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -# Configuration ---------------------------------------------------------------- -configure_file(cmake/templates/${PROJECT_NAME}_version.h.in - ${PROJECT_NAME}_version.h - @ONLY -) - target_sources(${PROJECT_NAME} PRIVATE src/unity.c @@ -54,7 +63,6 @@ target_include_directories(${PROJECT_NAME} set(${PROJECT_NAME}_PUBLIC_HEADERS src/unity.h src/unity_internals.h - ${CMAKE_CURRENT_BINARY_DIR}/unity_version.h ) set_target_properties(${PROJECT_NAME} diff --git a/cmake/templates/unity_version.h.in b/cmake/templates/unity_version.h.in deleted file mode 100644 index 7c89e773..00000000 --- a/cmake/templates/unity_version.h.in +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef UNITY_CONFIG_H -#define UNITY_CONFIG_H - -#define UNITY_VERSION_STRING "@PROJECT_VERSION@" -#define UNITY_VERSION_MAJOR @PROJECT_VERSION_MAJOR@ -#define UNITY_VERSION_MINOR @PROJECT_VERSION_MINOR@ -#define UNITY_VERSION_BUILD @PROJECT_VERSION_PATCH@ -#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | \ - (UNITY_VERSION_MINOR << 8) | \ - UNITY_VERSION_BUILD) - -#endif /* UNITY_CONFIG_H */ diff --git a/meson.build b/meson.build index 33d58875..968e5b13 100644 --- a/meson.build +++ b/meson.build @@ -7,8 +7,7 @@ project('unity', 'c', license: 'MIT', meson_version: '>=0.53.0', - default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11'], - version: '2.5.0' + default_options: ['layout=flat', 'warning_level=3', 'werror=true', 'c_std=c11'] ) lang = 'c' cc = meson.get_compiler(lang) diff --git a/src/meson.build b/src/meson.build index 19e7bd8e..7ede15af 100644 --- a/src/meson.build +++ b/src/meson.build @@ -4,15 +4,6 @@ # # license: MIT # -conf_data = configuration_data() -conf_data.set('PROJECT_VERSION', meson.project_version()) -conf_data.set('PROJECT_VERSION_MAJOR',meson.project_version().split('.')[0]) -conf_data.set('PROJECT_VERSION_MINOR',meson.project_version().split('.')[1]) -conf_data.set('PROJECT_VERSION_PATCH',meson.project_version().split('.')[2]) -unity_version_template = join_paths(meson.source_root(), 'cmake/templates/unity_version.h.in') -unity_version_file =configure_file(input : unity_version_template, - output : 'unity_version.h', - configuration : conf_data) unity_dir = include_directories('.') unity_lib = static_library(meson.project_name(), diff --git a/src/unity.h b/src/unity.h index 6eceb8da..925cd4d5 100644 --- a/src/unity.h +++ b/src/unity.h @@ -8,7 +8,10 @@ #define UNITY_FRAMEWORK_H #define UNITY -#include "unity_version.h" +#define UNITY_VERSION_MAJOR 2 +#define UNITY_VERSION_MINOR 5 +#define UNITY_VERSION_BUILD 0 +#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD) #ifdef __cplusplus extern "C"