Browse Source

Merge pull request #20 from hrittich/tmp

Allow configuration name as prefix
master
Martchus 2 months ago
committed by GitHub
parent
commit
2fc54ecdaa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      cmake/modules/AppTarget.cmake
  2. 12
      cmake/modules/BasicConfig.cmake
  3. 24
      cmake/modules/LibraryTarget.cmake
  4. 2
      cmake/templates/Config.cmake.in
  5. 1
      cmake/templates/config.h.in

4
cmake/modules/AppTarget.cmake

@ -140,7 +140,7 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
get_filename_component(ICON_FILE_EXT "${ICON_FILE}" EXT)
install(
FILES "${ICON_FILE}"
RENAME "${ICON_FILE_NAME}${META_CONFIG_SUFFIX}${ICON_FILE_EXT}"
RENAME "${NAMESPACE_PREFIX}${ICON_FILE_NAME}${META_CONFIG_SUFFIX}${ICON_FILE_EXT}"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps"
COMPONENT desktop)
endforeach ()
@ -247,7 +247,7 @@ function (add_desktop_file)
DESKTOP_FILE_CMD
"${META_TARGET_NAME}"
DESKTOP_FILE_ICON
"${META_PROJECT_NAME}${META_CONFIG_SUFFIX}"
"${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}"
DESKTOP_FILE_ADDITIONAL_ENTRIES
"${DESKTOP_FILE_ADDITIONAL_ENTRIES}")

12
cmake/modules/BasicConfig.cmake

@ -59,6 +59,14 @@ if (CONFIGURATION_DISPLAY_NAME)
set(META_APP_NAME "${META_APP_NAME} (${CONFIGURATION_DISPLAY_NAME})")
endif ()
set(NAMESPACE
""
CACHE STRING "adds a prefix to files and folders installed in the OS toplevel")
if (NAMESPACE)
set(NAMESPACE_PREFIX "${NAMESPACE}-")
set(TARGET_PREFIX "${NAMESPACE}-")
endif ()
# allow setting a library/application target suffix - A different configuration name might not require a different target
# name since it might differ anyways (e.g. library extensions for static and shared configuration). Hence there's not simply
# the configuration name used to distinguish targets as well.
@ -103,8 +111,8 @@ include(GNUInstallDirs)
# define a few variables
set(META_TARGET_NAME "${TARGET_PREFIX}${META_PROJECT_NAME}${TARGET_SUFFIX}")
set(META_DATA_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
set(META_DATA_DIR_ABSOLUTE "${CMAKE_INSTALL_FULL_DATAROOTDIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
set(META_DATA_DIR "${CMAKE_INSTALL_DATAROOTDIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
set(META_DATA_DIR_ABSOLUTE "${CMAKE_INSTALL_FULL_DATAROOTDIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" META_CURRENT_CONFIGURATION)
# set META_GENERIC_NAME to META_APP_NAME if not specified explicitly

24
cmake/modules/LibraryTarget.cmake

@ -32,9 +32,9 @@ include(TemplateFinder)
# set install destination for the CMake modules, config files and header files
set(INCLUDE_SUBDIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(HEADER_INSTALL_DESTINATION "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
if (META_CONFIG_SUFFIX)
set(INCLUDE_SUBDIR "${INCLUDE_SUBDIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
set(HEADER_INSTALL_DESTINATION "${HEADER_INSTALL_DESTINATION}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
if (NAMESPACE_PREFIX OR META_CONFIG_SUFFIX)
set(INCLUDE_SUBDIR "${INCLUDE_SUBDIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
set(HEADER_INSTALL_DESTINATION "${HEADER_INSTALL_DESTINATION}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
endif ()
set(CMAKE_MODULE_INSTALL_DESTINATION "${META_DATA_DIR_ABSOLUTE}/cmake/modules")
set(CMAKE_CONFIG_INSTALL_DESTINATION "${META_DATA_DIR_ABSOLUTE}/cmake")
@ -250,7 +250,7 @@ endforeach ()
# generate CMake code to configure CMake-target to pkg-config module mapping
set(TARGET_TO_PKG_CONFIG_MODULE_NAME_MAPPING
"set(PKG_CONFIG_${META_TARGET_NAME} \"${META_PROJECT_NAME}${META_CONFIG_SUFFIX}\")")
"set(PKG_CONFIG_${META_TARGET_NAME} \"${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}\")")
foreach (INTERFACE_REQUIRED_PKG_CONFIG_MODULE ${INTERFACE_REQUIRED_PKG_CONFIG_MODULES})
string(REPLACE "::" "_" INTERFACE_REQUIRED_PKG_CONFIG_MODULE_VARNAME "${INTERFACE_REQUIRED_PKG_CONFIG_MODULE}")
set(TARGET_TO_PKG_CONFIG_MODULE_NAME_MAPPING
@ -267,8 +267,8 @@ if (INTERFACE_REQUIRED_PKG_CONFIG_MODULES)
list(REMOVE_ITEM INTERFACE_REQUIRED_PKG_CONFIG_MODULES "")
list(REMOVE_DUPLICATES INTERFACE_REQUIRED_PKG_CONFIG_MODULES)
endif ()
set(CONFIG_TARGETS "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Config.cmake")
if (META_CONFIG_SUFFIX)
set(CONFIG_TARGETS "${CMAKE_CURRENT_BINARY_DIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Config.cmake")
if (NAMESPACE_PREFIX OR META_CONFIG_SUFFIX)
list(APPEND CONFIG_TARGETS "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}Config.cmake")
endif ()
find_template_file("Config.cmake" CPP_UTILITIES CONFIG_TEMPLATE_FILE)
@ -279,12 +279,12 @@ foreach (CONFIG_TARGET ${CONFIG_TARGETS})
PATH_VARS CMAKE_MODULE_INSTALL_DESTINATION CMAKE_CONFIG_INSTALL_DESTINATION HEADER_INSTALL_DESTINATION
BIN_INSTALL_DESTINATION LIB_INSTALL_DESTINATION META_DATA_DIR)
endforeach ()
list(APPEND CMAKE_CONFIG_FILES "${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}ConfigVersion.cmake")
list(APPEND CMAKE_CONFIG_FILES "${CMAKE_CURRENT_BINARY_DIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}ConfigVersion.cmake")
# write the CMake version config file
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/${META_PROJECT_NAME}${META_CONFIG_SUFFIX}ConfigVersion.cmake
${CMAKE_CURRENT_BINARY_DIR}/${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}ConfigVersion.cmake
VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}"
COMPATIBILITY SameMajorVersion)
@ -402,7 +402,7 @@ if (META_PUBLIC_LIB_DEPENDS_FOR_PC)
endif ()
# compute other values for pkg-config
set(META_PROJECT_NAME_FOR_PC "${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
set(META_PROJECT_NAME_FOR_PC "${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}")
foreach (COMPILE_DEFINITION ${META_PUBLIC_COMPILE_DEFINITIONS})
set(META_COMPILE_DEFINITIONS_FOR_PC "${META_COMPILE_DEFINITIONS_FOR_PC} -D${COMPILE_DEFINITION}")
endforeach ()
@ -499,14 +499,14 @@ if (NOT META_NO_INSTALL_TARGETS AND ENABLE_INSTALL_TARGETS)
endif ()
install(
TARGETS ${TARGETS_TO_EXPORT}
EXPORT "${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Targets"
EXPORT "${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Targets"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT binary
LIBRARY DESTINATION ${LIBRARY_DESTINATION} COMPONENT binary
ARCHIVE DESTINATION ${LIBRARY_DESTINATION} COMPONENT binary)
add_dependencies(install-binary "${META_TARGET_NAME}")
add_dependencies(install-binary-strip "${META_TARGET_NAME}")
install(
EXPORT ${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Targets
EXPORT ${NAMESPACE_PREFIX}${META_PROJECT_NAME}${META_CONFIG_SUFFIX}Targets
DESTINATION "${META_DATA_DIR}/cmake"
EXPORT_LINK_INTERFACE_LIBRARIES
COMPONENT cmake-config)

2
cmake/templates/Config.cmake.in

@ -38,7 +38,7 @@ set(@META_PROJECT_VARNAME_UPPER@_QT_RESOURCES @QT_RESOURCES@)
# define additional find_package arguments for required CMake-packages
@ADDITIONAL_ARGUMENTS_FOR_REQUIRED_CMAKE_PACKAGES@
# define library config, add imported target
set(@META_PROJECT_VARNAME_UPPER@_PACKAGE "@META_PROJECT_NAME@@META_CONFIG_SUFFIX@")
set(@META_PROJECT_VARNAME_UPPER@_PACKAGE "@NAMESPACE_PREFIX@@META_PROJECT_NAME@@META_CONFIG_SUFFIX@")
set(@META_PROJECT_VARNAME_UPPER@_LIB "@META_TARGET_NAME@")
set(@META_PROJECT_VARNAME_UPPER@_LIB_IS_SHARED "@BUILD_SHARED_LIBS@")
set(@META_PROJECT_VARNAME_UPPER@_STATIC_LINKAGE "@STATIC_LINKAGE_CONFIGURED@")

1
cmake/templates/config.h.in

@ -9,6 +9,7 @@
#define PROJECT_VARNAME_UPPER "@META_PROJECT_VARNAME_UPPER@"
#define PROJECT_LICENSE "@META_PROJECT_LICENSE@"
#define PROJECT_CONFIG_NAME "@META_CONFIG_NAME@"
#define PROJECT_NAMESPACE "@NAMESPACE_PREFIX@"
#define PROJECT_CONFIG_SUFFIX "@META_CONFIG_SUFFIX@"
#define PROJECT_CONFIG_TARGET_SUFFIX "@TARGET_SUFFIX@"
#define APP_NAME "@META_APP_NAME@"

Loading…
Cancel
Save