Browse Source

cmake: fix find_and_handle_library and move it to external file cmake/LeptonicaFunc.cmake

master
zdenop 2 months ago
parent
commit
f7324b02b0
  1. 18
      CMakeLists.txt
  2. 36
      cmake/LeptonicaFunc.cmake

18
CMakeLists.txt

@ -74,27 +74,13 @@ set(leptonica_INSTALL_CMAKE_DIR
"lib/cmake/leptonica"
CACHE STRING "Install destination for CMake package files")
include(LeptonicaFunc)
if(NOT SW_BUILD)
find_package(PkgConfig QUIET)
set(pkgs_private "")
set(libs_private "")
function(find_and_handle_library LIB_NAME ENABLE_OPTION PKG_CONFIG_NAME)
if(${ENABLE_OPTION})
find_package(${PKG_CONFIG_NAME})
if(${PKG_CONFIG_NAME}_FOUND)
set(pkgs_private "${pkgs_private} ${PKG_CONFIG_NAME}")
else()
if(STRICT_CONF)
message(
FATAL_ERROR
"Could not find ${PKG_CONFIG_NAME} libs. Use -D${ENABLE_OPTION}=OFF to disable ${PKG_CONFIG_NAME} support."
)
endif()
endif()
endif()
endfunction()
find_and_handle_library(ZLIB ENABLE_ZLIB ZLIB)
find_and_handle_library(PNG ENABLE_PNG PNG)
find_and_handle_library(JPEG ENABLE_JPEG JPEG)

36
cmake/LeptonicaFunc.cmake

@ -0,0 +1,36 @@
# cmake/LeptonicaFunc.cmake
# ##############################################################################
# FUNCTION find_and_handle_library
# ##############################################################################
function(find_and_handle_library LIB_NAME ENABLE_OPTION PKG_CONFIG_NAME)
if(${ENABLE_OPTION})
find_package(${PKG_CONFIG_NAME})
if(${PKG_CONFIG_NAME}_FOUND)
set(pkgs_private
"${pkgs_private} ${PKG_CONFIG_NAME}"
PARENT_SCOPE)
# Propagate found variables to parent scope
set(${PKG_CONFIG_NAME}_FOUND
${${PKG_CONFIG_NAME}_FOUND}
PARENT_SCOPE)
if(DEFINED ${PKG_CONFIG_NAME}_LIBRARIES)
set(${PKG_CONFIG_NAME}_LIBRARIES
${${PKG_CONFIG_NAME}_LIBRARIES}
PARENT_SCOPE)
endif()
if(DEFINED ${PKG_CONFIG_NAME}_INCLUDE_DIRS)
set(${PKG_CONFIG_NAME}_INCLUDE_DIRS
${${PKG_CONFIG_NAME}_INCLUDE_DIRS}
PARENT_SCOPE)
endif()
else()
if(STRICT_CONF)
message(
FATAL_ERROR
"Could not find ${PKG_CONFIG_NAME} libs. Use -D${ENABLE_OPTION}=OFF to disable ${PKG_CONFIG_NAME} support."
)
endif()
endif()
endif()
endfunction()
Loading…
Cancel
Save