CMake: De-duplicate extraction of copyright line from license file

This commit is contained in:
Brad King
2025-03-02 19:32:57 -05:00
parent 068ea4bfc1
commit 3035ee4ff3
4 changed files with 14 additions and 8 deletions

View File

@@ -386,6 +386,7 @@ endif()
# The main section of the CMakeLists file
#
#-----------------------------------------------------------------------
include(Source/CMakeCopyright.cmake)
include(Source/CMakeVersion.cmake)
include(CTest)

View File

@@ -0,0 +1,10 @@
# CMake license file and copyright line.
set(CMake_LICENSE_FILE "${CMake_SOURCE_DIR}/Copyright.txt")
file(STRINGS "${CMake_LICENSE_FILE}" CMake_COPYRIGHT_LINE LIMIT_COUNT 1 REGEX "^Copyright ")
if(NOT CMake_COPYRIGHT_LINE MATCHES [[^Copyright 2000-2[0-9][0-9][0-9] Kitware, Inc\. and Contributors$]])
message(FATAL_ERROR
"The CMake license file:\n"
" ${CMake_LICENSE_FILE}\n"
"does not contain a copyright line matching the expected pattern."
)
endif()

View File

@@ -306,15 +306,12 @@ Checks: '-*,llvm-twine-local'
")
if(APPLE)
file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
LIMIT_COUNT 1 REGEX "^Copyright 2000-20[0-9][0-9] Kitware")
set_target_properties(cmake-gui PROPERTIES
OUTPUT_NAME CMake
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/Info.plist.in"
MACOSX_BUNDLE_SHORT_VERSION_STRING "${CMAKE_BUNDLE_VERSION}"
# TBD: MACOSX_BUNDLE_BUNDLE_VERSION "${CMAKE_BUNDLE_VERSION}"
MACOSX_BUNDLE_COPYRIGHT "${copyright_line}"
MACOSX_BUNDLE_COPYRIGHT "${CMake_COPYRIGHT_LINE}"
MACOSX_BUNDLE_GUI_IDENTIFIER "org.cmake.cmake"
)

View File

@@ -7,6 +7,7 @@ if(NOT CMake_SOURCE_DIR)
get_filename_component(tmp "${CMAKE_CURRENT_SOURCE_DIR}" PATH)
get_filename_component(CMake_SOURCE_DIR "${tmp}" PATH)
include(${CMake_SOURCE_DIR}/Modules/CTestUseLaunchers.cmake)
include(${CMake_SOURCE_DIR}/Source/CMakeCopyright.cmake)
include(${CMake_SOURCE_DIR}/Source/CMakeVersion.cmake)
include(${CMake_SOURCE_DIR}/Source/CMakeInstallDestinations.cmake)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake @ONLY)
@@ -50,10 +51,7 @@ elseif(NOT SPHINX_EXECUTABLE)
message(FATAL_ERROR "SPHINX_EXECUTABLE (sphinx-build) is not found!")
endif()
set(copyright_line_regex "^Copyright (2000-20[0-9][0-9] Kitware.*)")
file(STRINGS "${CMake_SOURCE_DIR}/Copyright.txt" copyright_line
LIMIT_COUNT 1 REGEX "${copyright_line_regex}")
if(copyright_line MATCHES "${copyright_line_regex}")
if(CMake_COPYRIGHT_LINE MATCHES "^Copyright (.*)$")
set(conf_copyright "${CMAKE_MATCH_1}")
else()
set(conf_copyright "Kitware, Inc.")