From a91e75829ff175b949594b9d36b13039b4be6641 Mon Sep 17 00:00:00 2001 From: King_DuckZ Date: Sun, 27 Dec 2015 03:09:08 +0000 Subject: [PATCH] Fix libpqtypes as external project. Note: due to a bug in cmake/ninja, this change introduces problems when building with ninja. See: https://cmake.org/Bug/view.php?id=15256 --- CMakeLists.txt | 22 ++--------------- cmake/Modules/Buildlibpqtypes.cmake | 37 +++++++++++++++++++++++++++++ src/pq/CMakeLists.txt | 2 +- 3 files changed, 40 insertions(+), 21 deletions(-) create mode 100644 cmake/Modules/Buildlibpqtypes.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index dd719db..bcc5533 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project("${bare_name}-if" VERSION 0.1.3 LANGUAGES CXX C) list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules) include(GetGitRevisionDescription) -include(ExternalProject) +include(Buildlibpqtypes) option(DINDEXER_DEBUG_CFG_FILE "Enable to set the config file path to the build path" OFF) option(DINDEXER_WITH_MEDIA_AUTODETECT "Enable code that tries to autodetect the media type and sets --type automatically" ON) @@ -27,6 +27,7 @@ message(STATUS "Config file set to \"${DINDEXER_CONFIG_FILE}\"") find_package(Boost 1.53.0 REQUIRED COMPONENTS program_options) find_package(PostgreSQL 8.3 REQUIRED) find_package(YamlCpp 0.5.1 REQUIRED) +import_libpqtypes_project("${PostgreSQL_INCLUDE_DIRS}") add_library(${PROJECT_NAME} INTERFACE) add_library(${bare_name}-inc INTERFACE) @@ -48,25 +49,6 @@ target_include_directories(${bare_name}-inc INTERFACE ${CMAKE_SOURCE_DIR}/include ) -string(REPLACE ";" " -I" pqtypes_inc_dirs "-I${PostgreSQL_INCLUDE_DIRS}") -set(pqtypes_name "libpqtypes-1.5.1") -set(pqtypes_prefix ${CMAKE_CURRENT_BINARY_DIR}/lib/${pqtypes_name}) - -ExternalProject_Add(pqtypes_working - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/${pqtypes_name} - PREFIX lib/${pqtypes_name} - CONFIGURE_COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/lib/${pqtypes_name}/configure --prefix ${pqtypes_prefix} "CPPFLAGS=${pqtypes_inc_dirs}" --quiet - BUILD_COMMAND ${MAKE} - BUILD_IN_SOURCE 0 - INSTALL_DIR ${pqtypes_prefix} -) -add_library(pqtypes SHARED IMPORTED) -set_target_properties(pqtypes PROPERTIES - IMPORTED_LOCATION ${pqtypes_prefix}/lib/libpqtypes.so - IMPORTED_LINK_INTERFACE_LANGUAGES C - #INCLUDE_DIRECTORIES ${pqtypes_prefix}/include -) - add_subdirectory(src/scan) add_subdirectory(src/pq) add_subdirectory(src/main) diff --git a/cmake/Modules/Buildlibpqtypes.cmake b/cmake/Modules/Buildlibpqtypes.cmake new file mode 100644 index 0000000..31aca55 --- /dev/null +++ b/cmake/Modules/Buildlibpqtypes.cmake @@ -0,0 +1,37 @@ +include(ExternalProject) + +function (import_libpqtypes_project PostgreSQL_INCLUDE_DIRS) + #find_path(libpqtypes_base_path NAMES src/libpqtypes.h PATHS ${CMAKE_CURRENT_SOURCE_DIR}/lib NO_DEFAULT_PATH) + file(GLOB_RECURSE libpqtypes_base_path "lib/**libpqtypes.h") + + string(REPLACE ";" " -I" libpqtypes_inc_dirs "-I${PostgreSQL_INCLUDE_DIRS}") + string(REPLACE "src/libpqtypes.h" "" libpqtypes_base_path "${libpqtypes_base_path}") + string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" libpqtypes_prefix "${libpqtypes_base_path}") + string(REGEX REPLACE "/$" "" libpqtypes_prefix "${libpqtypes_prefix}") + + ExternalProject_Add(ext_project_pqtypes + DOWNLOAD_COMMAND "" + SOURCE_DIR ${libpqtypes_base_path} + PREFIX ${libpqtypes_prefix} + CONFIGURE_COMMAND ${libpqtypes_base_path}/configure --prefix ${libpqtypes_prefix} "CPPFLAGS=${libpqtypes_inc_dirs}" --quiet + BUILD_COMMAND ${MAKE} + BUILD_IN_SOURCE 0 + ) + add_library(pqtypes SHARED IMPORTED) + add_dependencies(pqtypes ext_project_pqtypes) + set_target_properties(pqtypes PROPERTIES + IMPORTED_LOCATION ${libpqtypes_prefix}/lib/libpqtypes.so + ) + + if(EXISTS "${libpqtypes_base_path}/configure.ac") + file(STRINGS "${libpqtypes_base_path}/configure.ac" libpqtypes_version_str REGEX "^AC_INIT[\t ]*\\([\t ]*libpqtypes[\t ]*,[\t ]*[0-9].*$") + string(REGEX REPLACE "^AC_INIT[\t ]*\\([\t ]*libpqtypes[\t ]*,[\t ]*([^,]+)[\t ]*,.*$" "\\1" libpqtypes_version "${libpqtypes_version_str}") + unset(libpqtypes_version_str) + message(STATUS "libpqtypes v${libpqtypes_version} found") + endif() + + set(libpqtypes_INCLUDE_DIRS "${libpqtypes_prefix}/include" PARENT_SCOPE) + + unset(libpqtypes_prefix) + unset(libpqtypes_inc_dirs) +endfunction() diff --git a/src/pq/CMakeLists.txt b/src/pq/CMakeLists.txt index ab7ebc2..6ebee00 100644 --- a/src/pq/CMakeLists.txt +++ b/src/pq/CMakeLists.txt @@ -7,7 +7,7 @@ add_library(${PROJECT_NAME} STATIC ) target_include_directories(${PROJECT_NAME} - PRIVATE ${pqtypes_prefix}/include + PRIVATE ${libpqtypes_INCLUDE_DIRS} ) target_link_libraries(${PROJECT_NAME} PRIVATE ${bare_name}-if