Author: rinrab Date: Fri Jul 12 17:10:14 2024 New Revision: 1919167 URL: http://svn.apache.org/viewvc?rev=1919167&view=rev Log: On the 'cmake' branch: Factor-out CMake module for finding the SQLite Amalgamation from CMakeLists.txt.
There were some code with a bit of magic with CMake for finding the SQLite Amalgamation in CMakeLists.txt. In this commit, this code would be moved into a CMake module FindSQLiteAmalgamation.cmake. Advantages: 1. It makes the CMakeLists.txt more structured; now it contains only a check for usage of amalgamation and two simple find_package commands. 2. Errors can be handled from the module; the find_package_handle_standard_args function simplifies the error handling a lot and does not require any additional code. * build/cmake/FindSQLiteAmalgamation.cmake: New file. * CMakeLists.txt (SVN_SQLITE_AMALGAMATION_ROOT): Rename the option to SQLiteAmalgamation_ROOT, because it is handled in the module by CMake and it requires the name to be <PackageName>_ROOT. (sqlite): Replace manual finding of the SQLite Amalgamation with find_package(SQLiteAmalgamation) command. Added: subversion/branches/cmake/build/cmake/FindSQLiteAmalgamation.cmake Modified: subversion/branches/cmake/CMakeLists.txt Modified: subversion/branches/cmake/CMakeLists.txt URL: http://svn.apache.org/viewvc/subversion/branches/cmake/CMakeLists.txt?rev=1919167&r1=1919166&r2=1919167&view=diff ============================================================================== --- subversion/branches/cmake/CMakeLists.txt (original) +++ subversion/branches/cmake/CMakeLists.txt Fri Jul 12 17:10:14 2024 @@ -193,30 +193,13 @@ endif() ### SQLite3 option(SVN_SQLITE_USE_AMALGAMATION "Use sqlite amalgamation" ON) -set(SVN_SQLITE_AMALGAMATION_ROOT "${CMAKE_SOURCE_DIR}/sqlite-amalgamation" +set(SQLiteAmalgamation_ROOT "${CMAKE_SOURCE_DIR}/sqlite-amalgamation" CACHE STRING "Directory with sqlite amalgamation" ) if(SVN_SQLITE_USE_AMALGAMATION) - add_library(external-sqlite INTERFACE) - find_path(SVN_SQLITE_AMALGAMATION_DIR - NAMES sqlite3.c - PATHS ${SVN_SQLITE_AMALGAMATION_ROOT} - ) - - mark_as_advanced(SVN_SQLITE_AMALGAMATION_DIR) - - target_include_directories(external-sqlite INTERFACE ${SVN_SQLITE_AMALGAMATION_DIR}) - target_compile_definitions(external-sqlite INTERFACE SVN_SQLITE_INLINE) - - if (SVN_SQLITE_AMALGAMATION_DIR) - file(STRINGS ${SVN_SQLITE_AMALGAMATION_DIR}/sqlite3.c _ver_line - REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\"" - LIMIT_COUNT 1) - string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" - SQLite3_VERSION "${_ver_line}") - unset(_ver_line) - endif() + find_package(SQLiteAmalgamation REQUIRED) + add_library(external-sqlite ALIAS SQLite::SQLite3Amalgamation) else() find_package(SQLite3 REQUIRED) add_library(external-sqlite ALIAS SQLite::SQLite3) Added: subversion/branches/cmake/build/cmake/FindSQLiteAmalgamation.cmake URL: http://svn.apache.org/viewvc/subversion/branches/cmake/build/cmake/FindSQLiteAmalgamation.cmake?rev=1919167&view=auto ============================================================================== --- subversion/branches/cmake/build/cmake/FindSQLiteAmalgamation.cmake (added) +++ subversion/branches/cmake/build/cmake/FindSQLiteAmalgamation.cmake Fri Jul 12 17:10:14 2024 @@ -0,0 +1,54 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# FindSQLiteAmalgamation.cmake -- CMake module for the SQLite Amalgamation +# + +find_path(SQLITE_AMALGAMATION_DIR + NAMES sqlite3.c +) + +mark_as_advanced(SQLITE_AMALGAMATION_DIR) + +if (SQLITE_AMALGAMATION_DIR AND EXISTS "${SQLITE_AMALGAMATION_DIR}/sqlite3.c") + file(STRINGS "${SQLITE_AMALGAMATION_DIR}/sqlite3.c" _ver_line + REGEX "^#define SQLITE_VERSION *\"[0-9]+\\.[0-9]+\\.[0-9]+\"" + LIMIT_COUNT 1) + string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" + SQLite3_VERSION "${_ver_line}") + unset(_ver_line) +endif() + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( + SQLiteAmalgamation + REQUIRED_VARS + SQLITE_AMALGAMATION_DIR + VERSION_VAR + SQLite3_VERSION +) + +if(SQLiteAmalgamation_FOUND AND NOT TARGET SQLite::SQLite3Amalgamation) + add_library(SQLite::SQLite3Amalgamation IMPORTED INTERFACE) + + target_include_directories(SQLite::SQLite3Amalgamation INTERFACE ${SQLITE_AMALGAMATION_DIR}) + + # TODO: maybe drop SVN_SQLITE_INLINE out of this module? + target_compile_definitions(SQLite::SQLite3Amalgamation INTERFACE SVN_SQLITE_INLINE) +endif()