Skip to content

Commit

Permalink
feat: auto-update list of provided_snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
UnePierre committed Sep 12, 2024
1 parent 8234b16 commit bf7741a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 46 deletions.
2 changes: 1 addition & 1 deletion CMakeEssentialConfig.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(CMakeEssential_VERSION 1.1.1)
set(CMakeEssential_VERSION 1.1.1.1)


####### Expanded from @PACKAGE_INIT@ by configure_package_config_file() #######
Expand Down
22 changes: 19 additions & 3 deletions CMakeEssentialConfigVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
# The variable CVF_VERSION must be set before calling configure_file().


set(PACKAGE_VERSION "1.1.1")
set(PACKAGE_VERSION "1.1.1.1")

if(PACKAGE_VERSION VERSION_LESS PACKAGE_FIND_VERSION)
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()

if("1.1.1" MATCHES "^([0-9]+)\\.")
if("1.1.1.1" MATCHES "^([0-9]+)\\.")
set(CVF_VERSION_MAJOR "${CMAKE_MATCH_1}")
if(NOT CVF_VERSION_MAJOR VERSION_EQUAL 0)
string(REGEX REPLACE "^0+" "" CVF_VERSION_MAJOR "${CVF_VERSION_MAJOR}")
endif()
else()
set(CVF_VERSION_MAJOR "1.1.1")
set(CVF_VERSION_MAJOR "1.1.1.1")
endif()

if(PACKAGE_FIND_VERSION_RANGE)
Expand Down Expand Up @@ -52,3 +52,19 @@ else()
endif()


# if the installed project requested no architecture check, don't perform the check
if("TRUE")
return()
endif()

# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")
return()
endif()

# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
if(NOT CMAKE_SIZEOF_VOID_P STREQUAL "8")
math(EXPR installedBits "8 * 8")
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()
45 changes: 24 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include("include/Policies.cmake")
include("include/Project.cmake")

# This project can be used via 'git subtree' or copy&paste, where git cannot provide the version number.
set(PROJECT_VERSION "1.1.1")
set(PROJECT_VERSION "1.1.1.1")

project(
CMakeEssential
Expand All @@ -15,14 +15,14 @@ project(
project_message_context()

set(provided_snippets
"Assert.cmake"
"Ccache.cmake"
"Git.cmake"
"MessageContext.cmake"
"ParseArguments.cmake"
"Policies.cmake"
"Project.cmake"
"TestByCompilation.cmake")
Assert.cmake
Ccache.cmake
Git.cmake
MessageContext.cmake
ParseArguments.cmake
Policies.cmake
Project.cmake
TestByCompilation.cmake)

if(PROJECT_IS_TOP_LEVEL)
include(CMakePackageConfigHelpers)
Expand All @@ -31,6 +31,19 @@ if(PROJECT_IS_TOP_LEVEL)
include(GNUInstallDirs)
set(INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

# Search for include/*.cmake and check against the list of provided_snippets.
file(
GLOB found_snippets CONFIGURE_DEPENDS
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_LIST_DIR}/include"
"include/*.cmake")
list(SORT found_snippets CASE INSENSITIVE)
if(NOT provided_snippets STREQUAL found_snippets)
message(AUTHOR_WARNING "The lists of provided (${provided_snippets}) and found snippets (${found_snippets}) differ, taking the latter!")
set(provided_snippets ${found_snippets})
endif()

# Make all provided snippets available in this project for itself.
foreach(snippet ${provided_snippets})
include("include/${snippet}")
endforeach()
Expand All @@ -50,18 +63,6 @@ if(PROJECT_IS_TOP_LEVEL)
if(is_dirty)
git_status(AUTHOR_WARNING)
endif()

# Search for include/*.cmake and check against the list of provided_snippets.
file(
GLOB found_snippets CONFIGURE_DEPENDS
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_LIST_DIR}/include"
"include/*.cmake")
list(SORT found_snippets CASE INSENSITIVE)

if(NOT provided_snippets STREQUAL found_snippets)
message(AUTHOR_WARNING "The lists of provided (${provided_snippets}) and found snippets (${found_snippets}) differ!")
endif()
endif()

message_context(README)
Expand All @@ -73,6 +74,8 @@ if(PROJECT_IS_TOP_LEVEL)
end_message_context()

message_context(CMakeLists.txt)
set(LIST_OF_PROVIDED_SNIPPETS ${provided_snippets})
list(JOIN LIST_OF_PROVIDED_SNIPPETS "\n " LIST_OF_PROVIDED_SNIPPETS)
configure_file(tools/CMakeLists.in.cmake "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" @ONLY)
configure_file(CMakeLists.txt CMakeLists.txt COPYONLY)
install(FILES CMakeLists.txt DESTINATION "${INSTALL_LIBDIR}")
Expand Down
2 changes: 1 addition & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
:author: Max FERGER
// Metadata:
:description: Essential CMake snippets for software development with modern CMake
:revnumber: 1.1.1
:revnumber: 1.1.1.1
// References:
:url-repo: https://github.com/UnePierre/cmake-essential
:url-issues: {url-repo}/-/issues
Expand Down
36 changes: 16 additions & 20 deletions tools/CMakeLists.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ project(
project_message_context()

set(provided_snippets
"Assert.cmake"
"Ccache.cmake"
"Git.cmake"
"MessageContext.cmake"
"ParseArguments.cmake"
"Policies.cmake"
"Project.cmake"
"TestByCompilation.cmake")
@LIST_OF_PROVIDED_SNIPPETS@)

if(PROJECT_IS_TOP_LEVEL)
include(CMakePackageConfigHelpers)
Expand All @@ -31,6 +24,19 @@ if(PROJECT_IS_TOP_LEVEL)
include(GNUInstallDirs)
set(INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")

# Search for include/*.cmake and check against the list of provided_snippets.
file(
GLOB found_snippets CONFIGURE_DEPENDS
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_LIST_DIR}/include"
"include/*.cmake")
list(SORT found_snippets CASE INSENSITIVE)
if(NOT provided_snippets STREQUAL found_snippets)
message(AUTHOR_WARNING "The lists of provided (${provided_snippets}) and found snippets (${found_snippets}) differ, taking the latter!")
set(provided_snippets ${found_snippets})
endif()

# Make all provided snippets available in this project for itself.
foreach(snippet ${provided_snippets})
include("include/${snippet}")
endforeach()
Expand All @@ -50,18 +56,6 @@ if(PROJECT_IS_TOP_LEVEL)
if(is_dirty)
git_status(AUTHOR_WARNING)
endif()

# Search for include/*.cmake and check against the list of provided_snippets.
file(
GLOB found_snippets CONFIGURE_DEPENDS
LIST_DIRECTORIES false
RELATIVE "${CMAKE_CURRENT_LIST_DIR}/include"
"include/*.cmake")
list(SORT found_snippets CASE INSENSITIVE)

if(NOT provided_snippets STREQUAL found_snippets)
message(AUTHOR_WARNING "The lists of provided (${provided_snippets}) and found snippets (${found_snippets}) differ!")
endif()
endif()

message_context(README)
Expand All @@ -73,6 +67,8 @@ if(PROJECT_IS_TOP_LEVEL)
end_message_context()

message_context(CMakeLists.txt)
set(LIST_OF_PROVIDED_SNIPPETS ${provided_snippets})
list(JOIN LIST_OF_PROVIDED_SNIPPETS "\n " LIST_OF_PROVIDED_SNIPPETS)
configure_file(tools/CMakeLists.in.cmake "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" @ONLY)
configure_file(CMakeLists.txt CMakeLists.txt COPYONLY)
install(FILES CMakeLists.txt DESTINATION "${INSTALL_LIBDIR}")
Expand Down

0 comments on commit bf7741a

Please sign in to comment.