Skip to content

Commit

Permalink
Improve CMake SQLite3 find module
Browse files Browse the repository at this point in the history
Make it compatible with official find module (CMake >= 3.14).
  • Loading branch information
evpobr committed Oct 27, 2020
1 parent 77209fa commit dc982da
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 58 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Expand Up @@ -64,6 +64,9 @@ option (ENABLE_PACKAGE_CONFIG "Generate and install package config file" ON)
option (INSTALL_PKGCONFIG_MODULE "Generate and install pkg-config module" ON)

list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if (CMAKE_VERSION VERSION_LESS 3.14)
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/sqlite")
endif ()

#
# Setup definitions
Expand Down Expand Up @@ -667,7 +670,7 @@ if (BUILD_REGTEST)
target_link_libraries(sndfile-regtest
PRIVATE
sndfile
SQLite3::SQLite3
SQLite::SQLite3
$<$<BOOL:${LIBM_REQUIRED}>:m>
)

Expand Down
2 changes: 1 addition & 1 deletion Makefile.am
Expand Up @@ -19,7 +19,7 @@ EXTRA_DIST = libsndfile.spec.in sndfile.pc.in Scripts/android-configure.sh \
cmake_files = cmake/ClipMode.cmake cmake/FindFLAC.cmake \
cmake/CMakeAutoGen.cmake cmake/CMakeAutoGenScript.cmake \
cmake/FindOgg.cmake cmake/FindVorbis.cmake cmake/FindSndio.cmake \
cmake/FindSpeex.cmake cmake/FindSQLite3.cmake \
cmake/FindSpeex.cmake cmake/sqlite/FindSQLite3.cmake \
cmake/SndFileChecks.cmake cmake/TestInline.cmake \
cmake/TestLargeFiles.cmake cmake/TestInline.c.in \
cmake/FindOpus.cmake cmake/SndFileConfig.cmake.in
Expand Down
56 changes: 0 additions & 56 deletions cmake/FindSQLite3.cmake

This file was deleted.

56 changes: 56 additions & 0 deletions cmake/sqlite/FindSQLite3.cmake
@@ -0,0 +1,56 @@
# - Find SQLite3
# Find the native SQLite3 includes and libraries
#
# SQLite3_INCLUDE_DIRS - where to find sqlite3.h, etc.
# SQLite3_LIBRARIES - List of libraries when using SQLite3.
# SQLite3_FOUND - True if SQLite3 found.

if (SQLite3_INCLUDE_DIR)
# Already in cache, be silent
set (SQLite3_FIND_QUIETLY TRUE)
endif ()

find_package (PkgConfig QUIET)
pkg_check_modules (PC_SQLite3 QUIET sqlite3)

set (SQLite3_VERSION ${PC_SQLite3_VERSION})

find_path (SQLite3_INCLUDE_DIR sqlite3.h
HINTS
${PC_SQLite3_INCLUDEDIR}
${PC_SQLite3_INCLUDE_DIRS}
${SQLite3_ROOT}
)

find_library (SQLite3_LIBRARY
NAMES
sqlite3
HINTS
${PC_SQLite3_LIBDIR}
${PC_SQLite3_LIBRARY_DIRS}
${SQLite3_ROOT}
)

include (FindPackageHandleStandardArgs)

find_package_handle_standard_args (SQLite3
REQUIRED_VARS
SQLite3_LIBRARY
SQLite3_INCLUDE_DIR
VERSION_VAR
SQLite3_VERSION
)

if (SQLite3_FOUND)
set SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
set SQLite3_LIBRARIES ${SQLite3_LIBRARY})
if (NOT TARGET SQLite::SQLite3)
add_library (SQLite::SQLite3 UNKNOWN IMPORTED)
set_target_properties (SQLite::SQLite3 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIRS}"
IMPORTED_LOCATION "${SQLite3_LIBRARIES}"
)
endif ()
endif ()

mark_as_advanced (SQLite3_INCLUDE_DIR SQLite3_LIBRARY)

0 comments on commit dc982da

Please sign in to comment.