WIP: Avoid writing `global.h` into the source directory

Writing this file into the source directory is very annoying because when
it changes these changes occur on all repositories.

WIP because this is hard to do without breaking compatibility.
This commit is contained in:
Martchus 2024-02-06 18:51:49 +01:00
parent a4be8a56d1
commit fd3bde4651
3 changed files with 17 additions and 60 deletions

View File

@ -51,6 +51,12 @@ if (NOT BUILD_SHARED_LIBS)
endif ()
# add global library-specific header
set(TARGET_GENERATED_INCLUDE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include")
set(TARGET_GLOBAL_HEADER "${TARGET_GENERATED_INCLUDE_DIRECTORY}/global.h")
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/global.h")
# cleanup "global.h" from the source directory (which is where previous versions of c++utilities wrote this file)
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/global.h")
endif ()
find_template_file("global.h" CPP_UTILITIES GLOBAL_H_TEMPLATE_FILE)
if ("${META_PROJECT_NAME}" STREQUAL "c++utilities")
set(GENERAL_GLOBAL_H_INCLUDE_PATH "\"application/global.h\"")
@ -58,10 +64,8 @@ else ()
set(GENERAL_GLOBAL_H_INCLUDE_PATH "<c++utilities/application/global.h>")
endif ()
configure_file(
"${GLOBAL_H_TEMPLATE_FILE}" "${CMAKE_CURRENT_SOURCE_DIR}/global.h" # simply add this to source to ease inclusion
NEWLINE_STYLE UNIX # since this goes to sources ensure consistency
"${GLOBAL_H_TEMPLATE_FILE}" "${TARGET_GLOBAL_HEADER}" NEWLINE_STYLE UNIX # since this goes to sources ensure consistency
)
list(APPEND HEADER_FILES global.h)
# add header to check library version
set(VERSION_HEADER_FILE "${CMAKE_CURRENT_BINARY_DIR}/resources/version.h")
@ -138,7 +142,6 @@ if (USE_HEADER_FOR_PUBLIC_COMPILE_DEFINITIONS)
endif ()
endforeach ()
endif ()
set(TARGET_GENERATED_INCLUDE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/include")
set(TARGET_DEFINITIONS_HEADER "${TARGET_GENERATED_INCLUDE_DIRECTORY}/${META_TARGET_NAME}-definitions.h")
file(WRITE "${TARGET_DEFINITIONS_HEADER}" "${DEFS_FOR_HEADER}")
@ -580,14 +583,12 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
DESTINATION "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}/${HEADER_DIR}"
COMPONENT header)
endforeach ()
install(
FILES "${VERSION_HEADER_FILE}"
DESTINATION "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}"
COMPONENT header)
install(
FILES "${TARGET_DEFINITIONS_HEADER}"
DESTINATION "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}"
COMPONENT header)
foreach (GENERATED_HEADER ${TARGET_GLOBAL_HEADER} ${VERSION_HEADER_FILE} ${TARGET_DEFINITIONS_HEADER})
install(
FILES "${GENERATED_HEADER}"
DESTINATION "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}"
COMPONENT header)
endforeach ()
if (NOT TARGET install-header)
add_custom_target(install-header COMMAND "${CMAKE_COMMAND}" -DCMAKE_INSTALL_COMPONENT=header -P
"${CMAKE_BINARY_DIR}/cmake_install.cmake")

View File

@ -1,28 +1,12 @@
// Created via CMake from template global.h.in
// WARNING! Any changes to this file will be overwritten by the next CMake run!
// This file is only provided for compatibility.
// Include "@META_TARGET_NAME@-global.h" directly new code.
#ifndef @META_PROJECT_VARNAME_UPPER@_GLOBAL
#define @META_PROJECT_VARNAME_UPPER@_GLOBAL
#include "@META_TARGET_NAME@-definitions.h"
#include @GENERAL_GLOBAL_H_INCLUDE_PATH@
#ifdef @META_PROJECT_VARNAME_UPPER@_STATIC
#define @META_PROJECT_VARNAME_UPPER@_EXPORT
#define @META_PROJECT_VARNAME_UPPER@_IMPORT
#else
#define @META_PROJECT_VARNAME_UPPER@_EXPORT CPP_UTILITIES_GENERIC_LIB_EXPORT
#define @META_PROJECT_VARNAME_UPPER@_IMPORT CPP_UTILITIES_GENERIC_LIB_IMPORT
#endif
/*!
* \def @META_PROJECT_VARNAME_UPPER@_EXPORT
* \brief Marks the symbol to be exported by the @META_PROJECT_NAME@ library.
*/
/*!
* \def @META_PROJECT_VARNAME_UPPER@_IMPORT
* \brief Marks the symbol to be imported from the @META_PROJECT_NAME@ library.
*/
#include "@META_TARGET_NAME@-global.h"
#endif // @META_PROJECT_VARNAME_UPPER@_GLOBAL

View File

@ -1,28 +0,0 @@
// Created via CMake from template global.h.in
// WARNING! Any changes to this file will be overwritten by the next CMake run!
#ifndef CPP_UTILITIES_GLOBAL
#define CPP_UTILITIES_GLOBAL
#include "c++utilities-devel-definitions.h"
#include "application/global.h"
#ifdef CPP_UTILITIES_STATIC
#define CPP_UTILITIES_EXPORT
#define CPP_UTILITIES_IMPORT
#else
#define CPP_UTILITIES_EXPORT CPP_UTILITIES_GENERIC_LIB_EXPORT
#define CPP_UTILITIES_IMPORT CPP_UTILITIES_GENERIC_LIB_IMPORT
#endif
/*!
* \def CPP_UTILITIES_EXPORT
* \brief Marks the symbol to be exported by the c++utilities library.
*/
/*!
* \def CPP_UTILITIES_IMPORT
* \brief Marks the symbol to be imported from the c++utilities library.
*/
#endif // CPP_UTILITIES_GLOBAL