diff --git a/CMakeLists.txt b/CMakeLists.txt index abb480c899..cd5ffe83c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1257,7 +1257,13 @@ target_link_libraries(${PACKAGE_NAME} PRIVATE ocpn::sqlite) add_subdirectory("libs/SQLiteCpp") target_link_libraries(${PACKAGE_NAME} PRIVATE ocpn::sqlite_cpp) -add_subdirectory("libs/shapelib") +find_package(Shapelib) +if (SHAPELIB_FOUND) + message(STATUS "Using system shapelib") +else () + message(STATUS "Using bundled shapelib") + add_subdirectory("libs/shapelib") +endif () target_link_libraries(${PACKAGE_NAME} PRIVATE shapelib::shapelib) add_subdirectory("libs/ShapefileCpp") diff --git a/cmake/FindShapelib.cmake b/cmake/FindShapelib.cmake new file mode 100644 index 0000000000..c55b618811 --- /dev/null +++ b/cmake/FindShapelib.cmake @@ -0,0 +1,27 @@ +# Find the shapelib a k a shp libraries +# +# Defines: +# SHAPELIB_FOUND - true if shapelib libs and headers found +# +# Exports: +# shapelib::shapelib transitive link target if SHAPELIB_FOUND is true +# +# Copyright (c) 2024 Alec Leamas +# License: GPL 2+ + +find_path(SHAPELIB_INCLUDE_DIR shapefil.h) + +find_library(SHAPELIB_LIBRARY NAMES shp shapelib) + +find_package_handle_standard_args(Shapelib + DEFAULT_MSG SHAPELIB_LIBRARY SHAPELIB_INCLUDE_DIR +) + +if (Shapelib_FOUND) + add_library(_shapelib INTERFACE) + target_link_libraries(_shapelib INTERFACE ${SHAPELIB_LIBRARY}) + target_include_directories(_shapelib INTERFACE ${SHAPELIB_INCLUDE_DIR}) + add_library(shapelib::shapelib ALIAS _shapelib) +endif() + +mark_as_advanced(SHAPELIB_INCLUDE_DIR SHAPELIB_LIBRARY)