Fix cross-compilation against Poco pre-built (#2599) (#2679)

* Use ZLIB and PCRE imported target to improve portability
* Set EXPAT and SQLite3 library for XML and SQL if POCO_UNBUNDLED is true in cmake build
This commit is contained in:
Joerg-Christian Boehme 2019-04-22 23:47:11 +02:00 committed by GitHub
parent 02d5743a4b
commit e1435a6620
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 301 additions and 129 deletions

View File

@ -24,9 +24,15 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
# Append our module directory to CMake
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(${CMAKE_VERSION} VERSION_LESS "3.4")
if(CMAKE_VERSION VERSION_LESS "3.4")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/V33)
endif()
if(CMAKE_VERSION VERSION_LESS "3.10")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/V39)
endif()
if(CMAKE_VERSION VERSION_LESS "3.14")
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/V313)
endif()
#################################################################################
# Setup C/C++ compiler options
#################################################################################
@ -436,6 +442,15 @@ install(
Devel
)
if(POCO_UNBUNDLED)
install(FILES cmake/FindPCRE.cmake
DESTINATION "${PocoConfigPackageLocation}")
install(FILES cmake/V39/FindEXPAT.cmake
DESTINATION "${PocoConfigPackageLocation}/V39")
install(FILES cmake/V313/FindSQLite3.cmake
DESTINATION "${PocoConfigPackageLocation}/V313")
endif()
message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
message(STATUS "${PROJECT_NAME} package version: ${PROJECT_VERSION}")
if(BUILD_SHARED_LIBS)

View File

@ -28,7 +28,7 @@ set_target_properties(DataSQLite
OUTPUT_NAME PocoDataSQLite
DEFINE_SYMBOL SQLite_EXPORTS
)
target_link_libraries(DataSQLite PUBLIC Poco::Data ${SQLITE3_LIBRARIES})
target_link_libraries(DataSQLite PUBLIC Poco::Data)
target_include_directories(DataSQLite
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@ -37,7 +37,7 @@ target_include_directories(DataSQLite
)
if(POCO_UNBUNDLED)
target_include_directories(DataSQLite PUBLIC "${SQLITE3_INCLUDE_DIRS}")
target_link_libraries(DataSQLite PUBLIC SQLite::SQLite3)
target_compile_definitions(DataSQLite PUBLIC POCO_UNBUNDLED)
else()
if(WINCE)

View File

@ -1,4 +1,11 @@
include(CMakeFindDependencyMacro)
find_dependency(PocoFoundation)
find_dependency(PocoData)
if(@POCO_UNBUNDLED@)
if(CMAKE_VERSION VERSION_LESS "3.14")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/V313")
endif()
find_dependency(SQLite3 REQUIRED)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/PocoDataSQLiteTargets.cmake")

View File

@ -94,7 +94,11 @@ set_target_properties(Foundation
DEFINE_SYMBOL Foundation_EXPORTS
)
target_link_libraries(Foundation PUBLIC ${PCRE_LIBRARIES} ${ZLIB_LIBRARIES})
if (POCO_UNBUNDLED)
target_link_libraries(Foundation PUBLIC Pcre::Pcre ZLIB::ZLIB)
target_compile_definitions(Foundation PUBLIC POCO_UNBUNDLED)
endif (POCO_UNBUNDLED)
target_include_directories(Foundation
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@ -209,11 +213,6 @@ if (ANDROID)
target_link_libraries(Foundation PUBLIC log)
endif()
if(POCO_UNBUNDLED)
target_include_directories(Foundation PUBLIC "${PCRE_INCLUDE_DIRS}" "${ZLIB_INCLUDE_DIRS}")
target_compile_definitions(Foundation PUBLIC POCO_UNBUNDLED)
endif()
POCO_INSTALL(Foundation)
POCO_GENERATE_PACKAGE(Foundation)

View File

@ -1 +1,8 @@
include("${CMAKE_CURRENT_LIST_DIR}/PocoFoundationTargets.cmake")
if(@POCO_UNBUNDLED@)
include(CMakeFindDependencyMacro)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")
find_dependency(ZLIB REQUIRED)
find_dependency(PCRE REQUIRED)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/PocoFoundationTargets.cmake")

View File

@ -125,7 +125,11 @@ set_target_properties(PDF
DEFINE_SYMBOL PDF_EXPORTS
)
target_link_libraries(PDF PUBLIC ${ZLIB_LIBRARIES} Poco::XML Poco::Util)
if (POCO_UNBUNDLED)
target_link_libraries(PDF PUBLIC ZLIB::ZLIB)
target_compile_definitions(PDF PUBLIC POCO_UNBUNDLED)
endif (POCO_UNBUNDLED)
target_link_libraries(PDF PUBLIC Poco::XML Poco::Util)
target_include_directories(PDF
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@ -133,9 +137,6 @@ target_include_directories(PDF
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src
)
if (POCO_UNBUNDLED)
target_include_directories(PDF PUBLIC "${ZLIB_INCLUDE_DIRS}")
target_compile_definitions(PDF PUBLIC POCO_UNBUNDLED)
endif()
POCO_INSTALL(PDF)

View File

@ -1,3 +1,7 @@
include(CMakeFindDependencyMacro)
find_dependency(PocoFoundation)
if(@POCO_UNBUNDLED@)
find_dependency(ZLIB REQUIRED)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/PocoPDFTargets.cmake")

View File

@ -35,7 +35,7 @@ set_target_properties( XML
DEFINE_SYMBOL XML_EXPORTS
)
target_link_libraries(XML PUBLIC ${EXPAT_LIBRARIES} Poco::Foundation)
target_link_libraries(XML PUBLIC Poco::Foundation)
target_include_directories(XML
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
@ -44,7 +44,7 @@ target_include_directories(XML
)
if (POCO_UNBUNDLED)
target_include_directories(XML PUBLIC "${EXPAT_INCLUDE_DIRS}")
target_link_libraries(XML PUBLIC EXPAT::EXPAT)
target_compile_definitions(XML PUBLIC POCO_UNBUNDLED)
else()
if(WIN32)

View File

@ -1,3 +1,10 @@
include(CMakeFindDependencyMacro)
find_dependency(PocoFoundation)
if(@POCO_UNBUNDLED@)
if(CMAKE_VERSION VERSION_LESS "3.10")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/V39")
endif()
find_dependency(EXPAT REQUIRED)
endif()
include("${CMAKE_CURRENT_LIST_DIR}/PocoXMLTargets.cmake")

View File

@ -1,33 +1,107 @@
#
# - Find pcre
# Find the native PCRE includes and library
#
# PCRE_INCLUDE_DIRS - where to find pcre.h, etc.
# PCRE_LIBRARIES - List of libraries when using pcre.
# PCRE_FOUND - True if pcre found.
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindPCRE
-------
IF (PCRE_INCLUDE_DIRS)
# Already in cache, be silent
SET(PCRE_FIND_QUIETLY TRUE)
ENDIF (PCRE_INCLUDE_DIRS)
Finds the PCRE library.
FIND_PATH(PCRE_INCLUDE_DIR pcre.h)
Imported Targets
^^^^^^^^^^^^^^^^
SET(PCRE_NAMES pcre)
FIND_LIBRARY(PCRE_LIBRARY NAMES ${PCRE_NAMES} )
This module provides the following imported targets, if found:
# handle the QUIETLY and REQUIRED arguments and set PCRE_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR)
``Pcre::Pcre``
The PCRE library
IF(PCRE_FOUND)
SET( PCRE_LIBRARIES ${PCRE_LIBRARY} )
SET( PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR} )
ELSE(PCRE_FOUND)
SET( PCRE_LIBRARIES )
SET( PCRE_INCLUDE_DIRS )
ENDIF(PCRE_FOUND)
Result Variables
^^^^^^^^^^^^^^^^
MARK_AS_ADVANCED( PCRE_LIBRARIES PCRE_INCLUDE_DIRS )
This will define the following variables:
``PCRE_FOUND``
True if the system has the PCRE library.
``PCRE_VERSION``
The version of the PCRE library which was found.
``PCRE_INCLUDE_DIRS``
Include directories needed to use PCRE.
``PCRE_LIBRARIES``
Libraries needed to link to PCRE.
Cache Variables
^^^^^^^^^^^^^^^
The following cache variables may also be set:
``PCRE_INCLUDE_DIR``
The directory containing ``foo.h``.
``PCRE_LIBRARY``
The path to the PCRE library.
Hints
^^^^^
``PCRE_ROOT_DIR``
The path to the root directory of a PCRE installation.
``PCRE_ROOT_INCLUDE_DIRS``
The path to the include directory of a PCRE installation.
``PCRE_ROOT_LIBRARY_DIRS``
The path to the library directory of a PCRE installation.
#]=======================================================================]#
include(FindPackageHandleStandardArgs)
find_package(PkgConfig QUIET)
pkg_check_modules(PC_PCRE QUIET pcre)
find_path(PCRE_INCLUDE_DIR
NAMES pcre.h
HINTS
${PCRE_ROOT_DIR}/include
${PCRE_ROOT_INCLUDE_DIRS}
PATHS
${PC_PCRE_INCLUDE_DIRS}
DOC "Specify the include directory containing pcre.h"
)
find_library(PCRE_LIBRARY
NAMES pcre
HINTS
${PCRE_ROOT_DIR}/lib
${PCRE_ROOT_LIBRARY_DIRS}
PATHS
${PC_PCRE_LIBRARY_DIRS}
DOC "Specify the lib directory containing pcre"
)
set(PCRE_VERSION ${PC_PCRE_VERSION})
find_package_handle_standard_args(PCRE
FOUND_VAR PCRE_FOUND
REQUIRED_VARS
PCRE_LIBRARY
PCRE_INCLUDE_DIR
VERSION_VAR PCRE_VERSION
)
if(PCRE_FOUND)
set(PCRE_LIBRARIES ${PCRE_LIBRARY})
set(PCRE_INCLUDE_DIRS ${PCRE_INCLUDE_DIR})
set(PCRE_DEFINITIONS ${PC_PCRE_CFLAGS_OTHER})
endif()
if(PCRE_FOUND AND NOT TARGET Pcre::Pcre)
add_library(Pcre::Pcre UNKNOWN IMPORTED)
set_target_properties(Pcre::Pcre PROPERTIES
IMPORTED_LOCATION "${PCRE_LIBRARY}"
INTERFACE_COMPILE_OPTIONS "${PC_PCRE_CFLAGS_OTHER}"
INTERFACE_INCLUDE_DIRECTORIES "${PCRE_INCLUDE_DIR}"
)
endif()
mark_as_advanced(
PCRE_INCLUDE_DIR
PCRE_LIBRARY
)

View File

@ -1,87 +0,0 @@
# - Try to find Sqlite3
# Once done this will define
#
# SQLITE3_FOUND - system has Sqlite3
# SQLITE3_INCLUDE_DIRS - the Sqlite3 include directory
# SQLITE3_LIBRARIES - Link these to use Sqlite3
# SQLITE3_DEFINITIONS - Compiler switches required for using Sqlite3
#
# Copyright (c) 2008 Andreas Schneider <mail@cynapses.org>
#
# Redistribution and use is allowed according to the terms of the New
# BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
#
if (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS)
# in cache already
set(SQLITE3_FOUND TRUE)
else (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS)
# use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
include(UsePkgConfig)
pkgconfig(sqlite3 _SQLITE3_INCLUDEDIR _SQLITE3_LIBDIR _SQLITE3_LDFLAGS _SQLITE3_CFLAGS)
else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(_SQLITE3 sqlite3)
endif (PKG_CONFIG_FOUND)
endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
find_path(SQLITE3_INCLUDE_DIR
NAMES
sqlite3.h
PATHS
${_SQLITE3_INCLUDEDIR}
/usr/include
/usr/local/include
/opt/local/include
/sw/include
)
find_library(SQLITE3_LIBRARY
NAMES
sqlite3
PATHS
${_SQLITE3_LIBDIR}
/usr/lib
/usr/local/lib
/opt/local/lib
/sw/lib
)
if (SQLITE3_LIBRARY)
set(SQLITE3_FOUND TRUE)
endif (SQLITE3_LIBRARY)
set(SQLITE3_INCLUDE_DIRS
${SQLITE3_INCLUDE_DIR}
)
if (SQLITE3_FOUND)
set(SQLITE3_LIBRARIES
${SQLITE3_LIBRARIES}
${SQLITE3_LIBRARY}
)
endif (SQLITE3_FOUND)
if (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
set(SQLITE3_FOUND TRUE)
endif (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
if (SQLITE3_FOUND)
if (NOT Sqlite3_FIND_QUIETLY)
message(STATUS "Found Sqlite3: ${SQLITE3_LIBRARIES}")
endif (NOT Sqlite3_FIND_QUIETLY)
else (SQLITE3_FOUND)
if (Sqlite3_FIND_REQUIRED)
message(FATAL_ERROR "Could not find Sqlite3")
endif (Sqlite3_FIND_REQUIRED)
endif (SQLITE3_FOUND)
# show the SQLITE3_INCLUDE_DIRS and SQLITE3_LIBRARIES variables only in the advanced view
mark_as_advanced(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
endif (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS)

View File

@ -0,0 +1,66 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
FindSQLite3
-----------
Find the SQLite libraries, v3
IMPORTED targets
^^^^^^^^^^^^^^^^
This module defines the following :prop_tgt:`IMPORTED` target:
``SQLite::SQLite3``
Result variables
^^^^^^^^^^^^^^^^
This module will set the following variables if found:
``SQLite3_INCLUDE_DIRS``
where to find sqlite3.h, etc.
``SQLite3_LIBRARIES``
the libraries to link against to use SQLite3.
``SQLite3_VERSION``
version of the SQLite3 library found
``SQLite3_FOUND``
TRUE if found
#]=======================================================================]
# Look for the necessary header
find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h)
mark_as_advanced(SQLite3_INCLUDE_DIR)
# Look for the necessary library
find_library(SQLite3_LIBRARY NAMES sqlite3 sqlite)
mark_as_advanced(SQLite3_LIBRARY)
# Extract version information from the header file
if(SQLite3_INCLUDE_DIR)
file(STRINGS ${SQLite3_INCLUDE_DIR}/sqlite3.h _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(SQLite3
REQUIRED_VARS SQLite3_INCLUDE_DIR SQLite3_LIBRARY
VERSION_VAR SQLite3_VERSION)
# Create the imported target
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
IMPORTED_LOCATION "${SQLite3_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SQLite3_INCLUDE_DIR}")
endif()
endif()

79
cmake/V39/FindEXPAT.cmake Normal file
View File

@ -0,0 +1,79 @@
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#.rst:
# FindEXPAT
# ---------
#
# Find the native Expat headers and library.
#
# Imported Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines the following :prop_tgt:`IMPORTED` targets:
#
# ``EXPAT::EXPAT``
# The Expat ``expat`` library, if found.
#
# Result Variables
# ^^^^^^^^^^^^^^^^
#
# This module will set the following variables in your project:
#
# ``EXPAT_INCLUDE_DIRS``
# where to find expat.h, etc.
# ``EXPAT_LIBRARIES``
# the libraries to link against to use Expat.
# ``EXPAT_FOUND``
# true if the Expat headers and libraries were found.
#
find_package(PkgConfig QUIET)
pkg_check_modules(PC_EXPAT QUIET expat)
# Look for the header file.
find_path(EXPAT_INCLUDE_DIR NAMES expat.h HINTS ${PC_EXPAT_INCLUDE_DIRS})
# Look for the library.
find_library(EXPAT_LIBRARY NAMES expat libexpat HINTS ${PC_EXPAT_LIBRARY_DIRS})
if (EXPAT_INCLUDE_DIR AND EXISTS "${EXPAT_INCLUDE_DIR}/expat.h")
file(STRINGS "${EXPAT_INCLUDE_DIR}/expat.h" expat_version_str
REGEX "^#[\t ]*define[\t ]+XML_(MAJOR|MINOR|MICRO)_VERSION[\t ]+[0-9]+$")
unset(EXPAT_VERSION_STRING)
foreach(VPART MAJOR MINOR MICRO)
foreach(VLINE ${expat_version_str})
if(VLINE MATCHES "^#[\t ]*define[\t ]+XML_${VPART}_VERSION[\t ]+([0-9]+)$")
set(EXPAT_VERSION_PART "${CMAKE_MATCH_1}")
if(EXPAT_VERSION_STRING)
string(APPEND EXPAT_VERSION_STRING ".${EXPAT_VERSION_PART}")
else()
set(EXPAT_VERSION_STRING "${EXPAT_VERSION_PART}")
endif()
endif()
endforeach()
endforeach()
endif ()
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(EXPAT
REQUIRED_VARS EXPAT_LIBRARY EXPAT_INCLUDE_DIR
VERSION_VAR EXPAT_VERSION_STRING)
# Copy the results to the output variables and target.
if(EXPAT_FOUND)
set(EXPAT_LIBRARIES ${EXPAT_LIBRARY})
set(EXPAT_INCLUDE_DIRS ${EXPAT_INCLUDE_DIR})
if(NOT TARGET EXPAT::EXPAT)
add_library(EXPAT::EXPAT UNKNOWN IMPORTED)
set_target_properties(EXPAT::EXPAT PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${EXPAT_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${EXPAT_INCLUDE_DIRS}")
endif()
endif()
mark_as_advanced(EXPAT_INCLUDE_DIR EXPAT_LIBRARY)