From 7af67dc4da98d439aff7d702b6fc19f29e9ca961 Mon Sep 17 00:00:00 2001 From: An Tao Date: Wed, 18 Mar 2020 19:54:48 +0800 Subject: [PATCH] Make CMake install files relocatable (#387) --- CMakeLists.txt | 149 ++++++++++---------------- cmake/templates/DrogonConfig.cmake.in | 18 +++- cmake_modules/FindJsoncpp.cmake | 99 +++++++++-------- cmake_modules/FindMySQL.cmake | 69 ++++++------ cmake_modules/FindSQLite3.cmake | 60 ++++++----- cmake_modules/FindUUID.cmake | 109 ++----------------- cmake_modules/Findpg.cmake | 23 ++++ drogon_ctl/CMakeLists.txt | 12 +-- trantor | 2 +- 9 files changed, 233 insertions(+), 308 deletions(-) create mode 100644 cmake_modules/Findpg.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0486b11a..afa204a2 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,17 +25,6 @@ set(DEF_INSTALL_DROGON_CMAKE_DIR lib/cmake/Drogon) set(INSTALL_DROGON_CMAKE_DIR ${DEF_INSTALL_DROGON_CMAKE_DIR} CACHE PATH "Installation directory for cmake files") -# Make relative paths absolute (needed later on) -foreach(p - LIB - BIN - INCLUDE - DROGON_CMAKE) - set(var INSTALL_${p}_DIR) - if(NOT IS_ABSOLUTE "${${var}}") - set(${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") - endif() -endforeach() if(BUILD_DROGON_SHARED) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) @@ -74,10 +63,10 @@ if(WIN32) endif(WIN32) # set the include list for dynamic view compiling -list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW - ${PROJECT_SOURCE_DIR}/lib/inc - ${PROJECT_SOURCE_DIR}/orm_lib/inc - ${PROJECT_SOURCE_DIR}/trantor) +# list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW +# ${PROJECT_SOURCE_DIR}/lib/inc +# ${PROJECT_SOURCE_DIR}/orm_lib/inc +# ${PROJECT_SOURCE_DIR}/trantor) add_subdirectory(trantor) @@ -85,14 +74,17 @@ target_link_libraries(${PROJECT_NAME} PUBLIC trantor) if(NOT WIN32) target_link_libraries(${PROJECT_NAME} PRIVATE dl) +else(NOT WIN32) + target_link_libraries(${PROJECT_NAME} PRIVATE shlwapi) endif(NOT WIN32) if(DROGON_CXX_STANDARD LESS 17) # With C++14, use boost to support any and string_view message(STATUS "use c++14") find_package(Boost 1.61.0 REQUIRED) - target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS}) - list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${Boost_INCLUDE_DIRS}) + message(STATUS "boost include dir:" ${Boost_INCLUDE_DIR}) + target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost) + list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${Boost_INCLUDE_DIR}) else(DROGON_CXX_STANDARD LESS 17) message(STATUS "use c++17") endif(DROGON_CXX_STANDARD LESS 17) @@ -101,43 +93,19 @@ set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules/) # jsoncpp find_package(Jsoncpp REQUIRED) -target_include_directories(${PROJECT_NAME} PUBLIC ${JSONCPP_INCLUDE_DIRS}) -target_link_libraries(${PROJECT_NAME} PUBLIC ${JSONCPP_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} PUBLIC Jsoncpp_lib) list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${JSONCPP_INCLUDE_DIRS}) -message(STATUS "jsoncpp inc path:" ${JSONCPP_INCLUDE_DIRS}) - -# message(STATUS ${JSONCPP_LIBRARIES}) -if(NOT EXISTS ${JSONCPP_INCLUDE_DIRS}/json/version.h) - message(FATAL_ERROR "Error: jsoncpp lib is too old.....stop") -endif() if(NOT WIN32) - exec_program( - cat - ARGS - "${JSONCPP_INCLUDE_DIRS}/json/version.h |grep JSONCPP_VERSION_STRING|sed s'/.*define/define/'|awk '{printf $3}'|sed s'/\"//g'" - OUTPUT_VARIABLE - jsoncpp_ver) - message(STATUS "jsoncpp verson:" ${jsoncpp_ver}) - if(jsoncpp_ver LESS 1.7) - message( - FATAL_ERROR - "jsoncpp lib is too old,please get new version from https://github.com/open-source-parsers/jsoncpp" - ) - endif(jsoncpp_ver LESS 1.7) - find_package(UUID REQUIRED) - target_include_directories(${PROJECT_NAME} PRIVATE ${UUID_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${UUID_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} PRIVATE PkgConfig::libuuid) try_compile(normal_uuid ${CMAKE_BINARY_DIR}/cmaketest ${PROJECT_SOURCE_DIR}/cmake/tests/normal_uuid_lib_test.cc - LINK_LIBRARIES ${UUID_LIBRARIES} - CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${UUID_INCLUDE_DIR}") + LINK_LIBRARIES PkgConfig::libuuid) try_compile(ossp_uuid ${CMAKE_BINARY_DIR}/cmaketest ${PROJECT_SOURCE_DIR}/cmake/tests/ossp_uuid_lib_test.cc - LINK_LIBRARIES ${UUID_LIBRARIES} - CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${UUID_INCLUDE_DIR}") + LINK_LIBRARIES PkgConfig::libuuid) if(normal_uuid) add_definitions(-DUSE_OSSP_UUID=0) elseif(ossp_uuid) @@ -189,13 +157,11 @@ endif(NOT WIN32) if(BUILD_ORM) # find postgres - find_package(PostgreSQL) - if(PostgreSQL_FOUND) - message(STATUS "libpq inc path:" ${PostgreSQL_INCLUDE_DIR}) - message(STATUS "libpq lib:" ${PostgreSQL_LIBRARIES}) - target_include_directories(${PROJECT_NAME} - PRIVATE ${PostgreSQL_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${PostgreSQL_LIBRARIES}) + find_package(pg) + if(pg_FOUND) + message(STATUS "libpq inc path:" ${PG_INCLUDE_DIRS}) + message(STATUS "libpq lib:" ${PG_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} PRIVATE pg_lib) set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/postgresql_impl/PostgreSQLResultImpl.cc) if(LIBPQ_BATCH_MODE) @@ -214,51 +180,41 @@ if(BUILD_ORM) set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/postgresql_impl/PgConnection.cc) endif(libpq_supports_batch) - endif(PostgreSQL_FOUND) + endif(pg_FOUND) # Find mysql, only mariadb client liberary is supported find_package(MySQL) - if(MYSQL_FOUND) - message(STATUS "inc:" ${MYSQL_INCLUDE_DIR}) - message(STATUS "libs:" ${MYSQL_CLIENT_LIBS}) - message(STATUS "version:" ${MYSQL_VERSION_STRING}) + if(MySQL_FOUND) message(STATUS "Ok! We find the mariadb!") - target_include_directories(${PROJECT_NAME} PRIVATE ${MYSQL_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${MYSQL_CLIENT_LIBS}) + target_link_libraries(${PROJECT_NAME} PRIVATE MySQL_lib) set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/mysql_impl/MysqlConnection.cc orm_lib/src/mysql_impl/MysqlResultImpl.cc) - else(MYSQL_FOUND) + else(MySQL_FOUND) if(MSVC) find_package(ZLIB REQUIRED) - target_include_directories(${PROJECT_NAME} PRIVATE ${ZLIB_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${ZLIB_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} PRIVATE ZLIB::ZLIB) endif(MSVC) - endif(MYSQL_FOUND) + endif(MySQL_FOUND) # Find sqlite3. find_package(SQLite3) - if(SQLITE3_FOUND) - message(STATUS "SQLite3 inc:" ${SQLITE3_INCLUDE_DIRS}) - target_include_directories(${PROJECT_NAME} PRIVATE ${SQLITE3_INCLUDE_DIRS}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${SQLITE3_LIBRARIES}) + if(SQLite3_FOUND) + target_link_libraries(${PROJECT_NAME} PRIVATE SQLite3_lib) set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/sqlite3_impl/Sqlite3Connection.cc orm_lib/src/sqlite3_impl/Sqlite3ResultImpl.cc) - endif(SQLITE3_FOUND) + endif(SQLite3_FOUND) endif(BUILD_ORM) if((NOT MSVC) OR (NOT BUILD_ORM)) find_package(ZLIB REQUIRED) - target_include_directories(${PROJECT_NAME} PRIVATE ${ZLIB_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${ZLIB_LIBRARIES}) - message(STATUS "zlib:" ${ZLIB_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} PRIVATE ZLIB::ZLIB) endif((NOT MSVC) OR (NOT BUILD_ORM)) find_package(OpenSSL) if(OpenSSL_FOUND) - target_include_directories(${PROJECT_NAME} PRIVATE ${OPENSSL_INCLUDE_DIR}) - target_link_libraries(${PROJECT_NAME} PRIVATE ${OPENSSL_LIBRARIES}) + target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::SSL OpenSSL::Crypto) else(OpenSSL_FOUND) set(DROGON_SOURCES ${DROGON_SOURCES} lib/src/ssl_funcs/Md5.cc lib/src/ssl_funcs/Sha1.cc) @@ -279,7 +235,7 @@ if(BUILD_CTL) add_subdirectory(drogon_ctl) endif(BUILD_CTL) -if(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) +if(pg_FOUND OR MySQL_FOUND OR SQLite3_FOUND) set(DROGON_SOURCES ${DROGON_SOURCES} orm_lib/src/ArrayParser.cc @@ -295,9 +251,9 @@ if(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) orm_lib/src/SqlBinder.cc orm_lib/src/TransactionImpl.cc orm_lib/src/RestfulController.cc) -else(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) +else(pg_FOUND OR MySQL_FOUND OR SQLite3_FOUND) set(DROGON_SOURCES ${DROGON_SOURCES} lib/src/DbClientManagerSkipped.cc) -endif(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) +endif(pg_FOUND OR MySQL_FOUND OR SQLite3_FOUND) target_sources(${PROJECT_NAME} PRIVATE ${DROGON_SOURCES}) @@ -307,25 +263,25 @@ set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD_REQUIRED ON) set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF) set_target_properties(${PROJECT_NAME} PROPERTIES EXPORT_NAME Drogon) -if(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) - if(PostgreSQL_FOUND) +if(pg_FOUND OR MySQL_FOUND OR SQLite3_FOUND) + if(pg_FOUND) option(USE_POSTGRESQL "Enable PostgreSQL" ON) - else(PostgreSQL_FOUND) + else(pg_FOUND) option(USE_POSTGRESQL "Disable PostgreSQL" OFF) - endif(PostgreSQL_FOUND) + endif(pg_FOUND) - if(MYSQL_FOUND) + if(MySQL_FOUND) option(USE_MYSQL "Enable Mysql" ON) - else(MYSQL_FOUND) + else(MySQL_FOUND) option(USE_MYSQL "DisableMysql" OFF) - endif(MYSQL_FOUND) + endif(MySQL_FOUND) - if(SQLITE3_FOUND) + if(SQLite3_FOUND) option(USE_SQLITE3 "Enable Sqlite3" ON) - else(SQLITE3_FOUND) + else(SQLite3_FOUND) option(USE_SQLITE3 "Disable Sqlite3" OFF) - endif(SQLITE3_FOUND) -endif(PostgreSQL_FOUND OR MYSQL_FOUND OR SQLITE3_FOUND) + endif(SQLite3_FOUND) +endif(pg_FOUND OR MySQL_FOUND OR SQLite3_FOUND) set(COMPILER_COMMAND ${CMAKE_CXX_COMPILER}) set(COMPILER_ID ${CMAKE_CXX_COMPILER_ID}) @@ -343,7 +299,7 @@ else(CMAKE_BUILD_TYPE) set(COMPILATION_FLAGS "-std=c++") endif(CMAKE_BUILD_TYPE) -list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW "${INSTALL_INCLUDE_DIR}") +list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW "${CMAKE_INSTALL_PREFIX}/${INSTALL_INCLUDE_DIR}") list(REMOVE_DUPLICATES INCLUDE_DIRS_FOR_DYNAMIC_VIEW) set(INS_STRING "") foreach(loop_var ${INCLUDE_DIRS_FOR_DYNAMIC_VIEW}) @@ -357,16 +313,16 @@ configure_file(${PROJECT_SOURCE_DIR}/cmake/templates/config.h.in if(BUILD_TESTING) add_subdirectory(lib/tests) - if(PostgreSQL_FOUND) + if(pg_FOUND) add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/postgresql_impl/test) add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/tests) - endif(PostgreSQL_FOUND) - if(MYSQL_FOUND) + endif(pg_FOUND) + if(MySQL_FOUND) add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/mysql_impl/test) - endif(MYSQL_FOUND) - if(SQLITE3_FOUND) + endif(MySQL_FOUND) + if(SQLite3_FOUND) add_subdirectory(${PROJECT_SOURCE_DIR}/orm_lib/src/sqlite3_impl/test) - endif(SQLITE3_FOUND) + endif(SQLite3_FOUND) find_package(GTest) if(GTest_FOUND) message(STATUS "gtest found") @@ -474,6 +430,11 @@ write_basic_package_version_file( install( FILES "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DrogonConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/DrogonConfigVersion.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindUUID.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindJsoncpp.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindSQLite3.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindMySQL.cmake" + "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/Findpg.cmake" DESTINATION "${INSTALL_DROGON_CMAKE_DIR}" COMPONENT dev) diff --git a/cmake/templates/DrogonConfig.cmake.in b/cmake/templates/DrogonConfig.cmake.in index 9cf0d1a9..92dbf787 100644 --- a/cmake/templates/DrogonConfig.cmake.in +++ b/cmake/templates/DrogonConfig.cmake.in @@ -10,8 +10,24 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) -find_dependency(Trantor) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) +find_dependency(Jsoncpp REQUIRED) +find_dependency(Trantor REQUIRED) +find_dependency(UUID REQUIRED) +find_dependency(ZLIB REQUIRED) +if(@pg_FOUND@) +find_dependency(pg) +endif() +if(@SQLite3_FOUND@) +find_dependency(SQLite3) +endif() +if(@MySQL_FOUND@) +find_dependency(MySQL) +endif() +if(@Boost_FOUND@) +find_dependency(Boost) +endif() # Our library dependencies (contains definitions for IMPORTED targets) diff --git a/cmake_modules/FindJsoncpp.cmake b/cmake_modules/FindJsoncpp.cmake index 37866539..6c10eb28 100755 --- a/cmake_modules/FindJsoncpp.cmake +++ b/cmake_modules/FindJsoncpp.cmake @@ -1,53 +1,68 @@ # Find jsoncpp # # Find the jsoncpp includes and library -# -# if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH -# -# This module defines -# JSONCPP_INCLUDE_DIRS, where to find header, etc. -# JSONCPP_LIBRARIES, the libraries needed to use jsoncpp. -# JSONCPP_FOUND, If false, do not try to use jsoncpp. -# JSONCPP_INCLUDE_PREFIX, include prefix for jsoncpp +# +# if you nee to add a custom library search path, do it via via +# CMAKE_PREFIX_PATH +# +# This module defines JSONCPP_INCLUDE_DIRS, where to find header, etc. +# JSONCPP_LIBRARIES, the libraries needed to use jsoncpp. JSONCPP_FOUND, If +# false, do not try to use jsoncpp. +# Jsoncpp_lib - The imported target library. # only look in default directories -find_path( - JSONCPP_INCLUDE_DIR - NAMES json/json.h - DOC "jsoncpp include dir" - PATH_SUFFIXES jsoncpp -) +find_path(JSONCPP_INCLUDE_DIRS + NAMES json/json.h + DOC "jsoncpp include dir" + PATH_SUFFIXES jsoncpp) -find_library( - JSONCPP_LIBRARY - NAMES jsoncpp - DOC "jsoncpp library" -) +find_library(JSONCPP_LIBRARIES NAMES jsoncpp DOC "jsoncpp library") -set(JSONCPP_INCLUDE_DIRS ${JSONCPP_INCLUDE_DIR}) -set(JSONCPP_LIBRARIES ${JSONCPP_LIBRARY}) +# debug library on windows same naming convention as in qt (appending debug +# library with d) boost is using the same "hack" as us with "optimized" and +# "debug" if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") +# find_library(JSONCPP_LIBRARIES_DEBUG NAMES jsoncppd DOC "jsoncpp debug +# library") if("${JSONCPP_LIBRARIES_DEBUG}" STREQUAL "JSONCPP_LIBRARIES_DEBUG- +# NOTFOUND") set(JSONCPP_LIBRARIES_DEBUG ${JSONCPP_LIBRARIES}) endif() -# debug library on windows -# same naming convention as in qt (appending debug library with d) -# boost is using the same "hack" as us with "optimized" and "debug" -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - find_library( - JSONCPP_LIBRARY_DEBUG - NAMES jsoncppd - DOC "jsoncpp debug library" - ) - if("${JSONCPP_LIBRARY_DEBUG}" STREQUAL "JSONCPP_LIBRARY_DEBUG-NOTFOUND") - set(JSONCPP_LIBRARY_DEBUG ${JSONCPP_LIBRARIES}) - endif() - - set(JSONCPP_LIBRARIES optimized ${JSONCPP_LIBRARIES} debug ${JSONCPP_LIBRARY_DEBUG}) +# set(JSONCPP_LIBRARIES optimized ${JSONCPP_LIBRARIES} debug +# ${JSONCPP_LIBRARIES_DEBUG}) -endif() +# endif() - -# handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE -# if all listed variables are TRUE, hide their existence from configuration view +# handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE if all +# listed variables are TRUE, hide their existence from configuration view include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(jsoncpp DEFAULT_MSG - JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) -mark_as_advanced (JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) +find_package_handle_standard_args(Jsoncpp + DEFAULT_MSG + JSONCPP_INCLUDE_DIRS + JSONCPP_LIBRARIES) +mark_as_advanced(JSONCPP_INCLUDE_DIRS JSONCPP_LIBRARIES) + +if(Jsoncpp_FOUND) + if(NOT EXISTS ${JSONCPP_INCLUDE_DIRS}/json/version.h) + message(FATAL_ERROR "Error: jsoncpp lib is too old.....stop") + endif() + if(NOT WIN32) + exec_program( + cat + ARGS + "${JSONCPP_INCLUDE_DIRS}/json/version.h |grep JSONCPP_VERSION_STRING|sed s'/.*define/define/'|awk '{printf $3}'|sed s'/\"//g'" + OUTPUT_VARIABLE + jsoncpp_ver) + message(STATUS "jsoncpp verson:" ${jsoncpp_ver}) + if(jsoncpp_ver LESS 1.7) + message( + FATAL_ERROR + "jsoncpp lib is too old, please get new version from https://github.com/open-source-parsers/jsoncpp" + ) + endif(jsoncpp_ver LESS 1.7) + endif() + add_library(Jsoncpp_lib INTERFACE IMPORTED) + set_target_properties(Jsoncpp_lib + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${JSONCPP_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES + "${JSONCPP_LIBRARIES}") + +endif(Jsoncpp_FOUND) diff --git a/cmake_modules/FindMySQL.cmake b/cmake_modules/FindMySQL.cmake index dee53ba2..5d8bbb1c 100644 --- a/cmake_modules/FindMySQL.cmake +++ b/cmake_modules/FindMySQL.cmake @@ -22,11 +22,12 @@ # MySQL Connectors. There are special exceptions to the terms and conditions of # the GPL as it is applied to this software, see the FLOSS License Exception # available on mysql.com. +# MySQL_lib - The imported target library. # ############################################################################## -# -------------- FIND MYSQL_INCLUDE_DIR ------------------ -find_path(MYSQL_INCLUDE_DIR +# -------------- FIND MYSQL_INCLUDE_DIRS ------------------ +find_path(MYSQL_INCLUDE_DIRS NAMES mysql.h PATH_SUFFIXES mysql PATHS /usr/include/mysql @@ -40,13 +41,13 @@ find_path(MYSQL_INCLUDE_DIR $ENV{ProgramFiles}/MySQL/*/include $ENV{SystemDrive}/MySQL/*/include) -if(EXISTS "${MYSQL_INCLUDE_DIR}/mysql.h") +if(EXISTS "${MYSQL_INCLUDE_DIRS}/mysql.h") -elseif(EXISTS "${MYSQL_INCLUDE_DIR}/mysql/mysql.h") - set(MYSQL_INCLUDE_DIR ${MYSQL_INCLUDE_DIR}/mysql) +elseif(EXISTS "${MYSQL_INCLUDE_DIRS}/mysql/mysql.h") + set(MYSQL_INCLUDE_DIRS ${MYSQL_INCLUDE_DIRS}/mysql) endif() -# ----------------- FIND MYSQL_LIB_DIR ------------------- +# ----------------- FIND MYSQL_LIBRARIES_DIR ------------------- if(WIN32) # Set lib path suffixes dist = for mysql binary distributions build = for # custom built tree @@ -59,7 +60,7 @@ if(WIN32) add_definitions(-DDBUG_OFF) endif(CMAKE_BUILD_TYPE STREQUAL Debug) - find_library(MYSQL_LIB + find_library(MYSQL_LIBRARIES NAMES mariadbclient PATHS $ENV{MYSQL_DIR}/lib/${libsuffixDist} $ENV{MYSQL_DIR}/libmysql @@ -69,7 +70,7 @@ if(WIN32) $ENV{ProgramFiles}/MySQL/*/lib/${libsuffixDist} $ENV{SystemDrive}/MySQL/*/lib/${libsuffixDist}) else(WIN32) - find_library(MYSQL_LIB + find_library(MYSQL_LIBRARIES NAMES mysqlclient_r mariadbclient PATHS /usr/lib/mysql /usr/local/lib/mysql @@ -81,34 +82,32 @@ else(WIN32) /opt/mysql/lib/mysql) endif(WIN32) -if(MYSQL_LIB) - get_filename_component(MYSQL_LIB_DIR ${MYSQL_LIB} PATH) -endif(MYSQL_LIB) - -if(MYSQL_INCLUDE_DIR AND MYSQL_LIB_DIR) - set(MYSQL_FOUND TRUE) - - # FIND_LIBRARY(MYSQL_ZLIB zlib PATHS ${MYSQL_LIB_DIR}) - # FIND_LIBRARY(MYSQL_TAOCRYPT taocrypt PATHS ${MYSQL_LIB_DIR}) - set(MYSQL_CLIENT_LIBS ${MYSQL_LIB}) - # IF (MYSQL_ZLIB) SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} zlib) ENDIF - # (MYSQL_ZLIB) IF (MYSQL_TAOCRYPT) SET(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} - # taocrypt) ENDIF (MYSQL_TAOCRYPT) Added needed mysqlclient dependencies on - # Windows - if(MSVC) - set(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} shlwapi) - endif(MSVC) - if(WIN32) - set(MYSQL_CLIENT_LIBS ${MYSQL_CLIENT_LIBS} ws2_32) - endif(WIN32) - - message( - STATUS - "MySQL Include dir: ${MYSQL_INCLUDE_DIR} library dir: ${MYSQL_LIB_DIR}") - message(STATUS "MySQL client libraries: ${MYSQL_CLIENT_LIBS}") +if(MYSQL_INCLUDE_DIRS AND MYSQL_LIBRARIES) + message(STATUS "MySQL Include dir: ${MYSQL_INCLUDE_DIRS}") + message(STATUS "MySQL client libraries: ${MYSQL_LIBRARIES}") elseif(MySQL_FIND_REQUIRED) message( FATAL_ERROR - "Cannot find MySQL. Include dir: ${MYSQL_INCLUDE_DIR} library dir: ${MYSQL_LIB_DIR}" + "Cannot find MySQL. Include dir: ${MYSQL_INCLUDE_DIRS} library dir: ${MYSQL_LIBRARIES_DIR}" ) -endif(MYSQL_INCLUDE_DIR AND MYSQL_LIB_DIR) +endif(MYSQL_INCLUDE_DIRS AND MYSQL_LIBRARIES) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(MySQL + DEFAULT_MSG + MYSQL_LIBRARIES + MYSQL_INCLUDE_DIRS) +# Copy the results to the output variables. +if(MySQL_FOUND) + add_library(MySQL_lib INTERFACE IMPORTED) + set_target_properties(MySQL_lib + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${MYSQL_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES + "${MYSQL_LIBRARIES}") +else(MySQL_FOUND) + set(MYSQL_LIBRARIES) + set(MYSQL_INCLUDE_DIRS) +endif(MySQL_FOUND) + +mark_as_advanced(MYSQL_INCLUDE_DIRS MYSQL_LIBRARIES) diff --git a/cmake_modules/FindSQLite3.cmake b/cmake_modules/FindSQLite3.cmake index 9c99ae5c..552439ff 100644 --- a/cmake_modules/FindSQLite3.cmake +++ b/cmake_modules/FindSQLite3.cmake @@ -1,37 +1,43 @@ -# Copyright (C) 2007-2009 LuaDist. -# Created by Peter Kapec -# Redistribution and use of this file is allowed according to the terms of the MIT license. -# For details see the COPYRIGHT file distributed with LuaDist. -# Note: -# Searching headers and libraries is very simple and is NOT as powerful as scripts -# distributed with CMake, because LuaDist defines directories to search for. -# Everyone is encouraged to contact the author with improvements. Maybe this file -# becomes part of CMake distribution sometimes. +# Copyright (C) 2007-2009 LuaDist. Created by Peter Kapec +# Redistribution and use of this file is allowed according to the terms of the +# MIT license. For details see the COPYRIGHT file distributed with LuaDist. +# Note: Searching headers and libraries is very simple and is NOT as powerful as +# scripts distributed with CMake, because LuaDist defines directories to search +# for. Everyone is encouraged to contact the author with improvements. Maybe +# this file becomes part of CMake distribution sometimes. -# - Find sqlite3 -# Find the native SQLITE3 headers and libraries. +# * Find sqlite3 Find the native SQLITE3 headers and libraries. # -# SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc. -# SQLITE3_LIBRARIES - List of libraries when using sqlite. -# SQLITE3_FOUND - True if sqlite found. +# SQLITE3_INCLUDE_DIRS - where to find sqlite3.h, etc. +# SQLITE3_LIBRARIES - List of libraries when using sqlite. +# SQLite3_FOUND - True if sqlite3 found. +# SQLite3_lib - The imported target library. # Look for the header file. -FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) +find_path(SQLITE3_INCLUDE_DIRS NAMES sqlite3.h) # Look for the library. -FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3) +find_library(SQLITE3_LIBRARIES NAMES sqlite3) -# Handle the QUIETLY and REQUIRED arguments and set SQLITE3_FOUND to TRUE if all listed variables are TRUE. -INCLUDE(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR) +# Handle the QUIETLY and REQUIRED arguments and set SQLite3_FOUND to TRUE if all +# listed variables are TRUE. +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(SQLite3 + DEFAULT_MSG + SQLITE3_LIBRARIES + SQLITE3_INCLUDE_DIRS) # Copy the results to the output variables. -IF(SQLITE3_FOUND) - SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY}) - SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR}) -ELSE(SQLITE3_FOUND) - SET(SQLITE3_LIBRARIES) - SET(SQLITE3_INCLUDE_DIRS) -ENDIF(SQLITE3_FOUND) +if(SQLite3_FOUND) + add_library(SQLite3_lib INTERFACE IMPORTED) + set_target_properties(SQLite3_lib + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${SQLITE3_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES + "${SQLITE3_LIBRARIES}") +else(SQLite3_FOUND) + set(SQLITE3_LIBRARIES) + set(SQLITE3_INCLUDE_DIRS) +endif(SQLite3_FOUND) -MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES) +mark_as_advanced(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES) diff --git a/cmake_modules/FindUUID.cmake b/cmake_modules/FindUUID.cmake index f41d2ed2..1a6e20d2 100755 --- a/cmake_modules/FindUUID.cmake +++ b/cmake_modules/FindUUID.cmake @@ -13,107 +13,12 @@ # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # +find_package(PkgConfig REQUIRED) -if (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) - # in cache already - set(UUID_FOUND TRUE) -else (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) - find_path(UUID_INCLUDE_DIR - NAMES - uuid.h - PATH_SUFFIXES - uuid - HINTS - ${UUID_DIR}/include - $ENV{UUID_DIR}/include - $ENV{UUID_DIR} - ${DELTA3D_EXT_DIR}/inc - $ENV{DELTA_ROOT}/ext/inc - $ENV{DELTA_ROOT} - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/include - /usr/include - /usr/include/gdal - /sw/include # Fink - /opt/local/include # DarwinPorts - /opt/csw/include # Blastwave - /opt/include - [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;OSG_ROOT]/include - /usr/freeware/include - ) +pkg_check_modules(libuuid + REQUIRED + IMPORTED_TARGET + uuid +) - find_library(UUID_LIBRARY - NAMES - uuid ossp-uuid - HINTS - ${UUID_DIR}/lib - $ENV{UUID_DIR}/lib - $ENV{UUID_DIR} - ${DELTA3D_EXT_DIR}/lib - $ENV{DELTA_ROOT}/ext/lib - $ENV{DELTA_ROOT} - $ENV{OSG_ROOT}/lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/lib - /usr/lib - /sw/lib - /opt/local/lib - /opt/csw/lib - /opt/lib - /usr/freeware/lib64 - ) - - find_library(UUID_LIBRARY_DEBUG - NAMES - uuidd - HINTS - ${UUID_DIR}/lib - $ENV{UUID_DIR}/lib - $ENV{UUID_DIR} - ${DELTA3D_EXT_DIR}/lib - $ENV{DELTA_ROOT}/ext/lib - $ENV{DELTA_ROOT} - $ENV{OSG_ROOT}/lib - PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local/lib - /usr/lib - /sw/lib - /opt/local/lib - /opt/csw/lib - /opt/lib - /usr/freeware/lib64 - ) - - if (NOT UUID_LIBRARY AND BSD) - set(UUID_LIBRARY "") - endif(NOT UUID_LIBRARY AND BSD) - - set(UUID_INCLUDE_DIRS ${UUID_INCLUDE_DIR}) - set(UUID_LIBRARIES ${UUID_LIBRARY}) - - if (UUID_INCLUDE_DIRS) - if (BSD OR UUID_LIBRARIES) - set(UUID_FOUND TRUE) - endif (BSD OR UUID_LIBRARIES) - endif (UUID_INCLUDE_DIRS) - - if (UUID_FOUND) - if (NOT UUID_FIND_QUIETLY) - message(STATUS "Found UUID: ${UUID_LIBRARIES}") - endif (NOT UUID_FIND_QUIETLY) - else (UUID_FOUND) - if (UUID_FIND_REQUIRED) - message(FATAL_ERROR "Could not find UUID") - endif (UUID_FIND_REQUIRED) - endif (UUID_FOUND) - - # show the UUID_INCLUDE_DIRS and UUID_LIBRARIES variables only in the advanced view - mark_as_advanced(UUID_INCLUDE_DIRS UUID_LIBRARIES) - -endif (UUID_LIBRARIES AND UUID_INCLUDE_DIRS) +set(UUID_FOUND TRUE) diff --git a/cmake_modules/Findpg.cmake b/cmake_modules/Findpg.cmake new file mode 100644 index 00000000..88a6eb73 --- /dev/null +++ b/cmake_modules/Findpg.cmake @@ -0,0 +1,23 @@ +# Find PostgreSQL +# +# Find the PostgreSQL includes and library +# +# This module defines PG_INCLUDE_DIRS, where to find header, etc. PG_LIBRARIES, +# the libraries needed to use PostgreSQL. pg_FOUND, If false, do not try to use +# PostgreSQL. +# pg_lib - The imported target library. + +find_package(PostgreSQL) +if(PostgreSQL_FOUND) + set(PG_LIBRARIES ${PostgreSQL_LIBRARIES}) + set(PG_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIRS}) + message(STATUS "pg inc: " ${PostgreSQL_INCLUDE_DIRS}) + add_library(pg_lib INTERFACE IMPORTED) + set_target_properties(pg_lib + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES + "${PostgreSQL_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES + "${PostgreSQL_LIBRARIES}") + mark_as_advanced(PG_INCLUDE_DIRS PG_LIBRARIES) + set(pg_FOUND TRUE) +endif() diff --git a/drogon_ctl/CMakeLists.txt b/drogon_ctl/CMakeLists.txt index 83564157..7ce6f548 100755 --- a/drogon_ctl/CMakeLists.txt +++ b/drogon_ctl/CMakeLists.txt @@ -35,9 +35,7 @@ endforeach() add_executable(drogon_ctl ${ctl_sources} ${TEMPL_SRC}) target_link_libraries(drogon_ctl PRIVATE ${PROJECT_NAME}) target_include_directories(drogon_ctl PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) -add_dependencies(drogon_ctl - trantor - _drogon_ctl) +add_dependencies(drogon_ctl trantor _drogon_ctl) if(WIN32) target_link_libraries(drogon_ctl PRIVATE ws2_32 Rpcrt4) endif(WIN32) @@ -54,9 +52,11 @@ if(WIN32) else(WIN32) install(CODE "execute_process( \ COMMAND ${CMAKE_COMMAND} -E create_symlink \ - ${INSTALL_BIN_DIR}/drogon_ctl \ - ${INSTALL_BIN_DIR}/dg_ctl \ - )") + ./drogon_ctl \ + ./dg_ctl \ + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})") + install(FILES "${CMAKE_CURRENT_BINARY_DIR}/dg_ctl" + DESTINATION ${INSTALL_BIN_DIR}) endif(WIN32) set(ctl_targets _drogon_ctl drogon_ctl) set_property(TARGET ${ctl_targets} PROPERTY CXX_STANDARD ${DROGON_CXX_STANDARD}) diff --git a/trantor b/trantor index ec56d474..f38eba77 160000 --- a/trantor +++ b/trantor @@ -1 +1 @@ -Subproject commit ec56d4748d0e29f2369b6d1e9e2b8a4c7bed8892 +Subproject commit f38eba777fa91d3bc2443efe853fcb8b64afa459