diff --git a/CMakeLists.txt b/CMakeLists.txt index b0adc7af..661c0efc 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,22 @@ cmake_minimum_required(VERSION 3.5) project(drogon CXX) -add_library(${PROJECT_NAME} STATIC) +option(BUILD_CTL "Build drogon_ctl" ON) +option(BUILD_EXAMPLES "Build examples" ON) +option(BUILD_ORM "Build orm" ON) +option(LIBPQ_BATCH_MODE "Use batch mode for libpq" ON) +option(BUILD_DROGON_SHARED "Build drogon as a shared lib" OFF) + +if(BUILD_DROGON_SHARED) + set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) + if("${isSystemDir}" STREQUAL "-1") + set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") + endif("${isSystemDir}" STREQUAL "-1") + add_library(${PROJECT_NAME} SHARED) +else() + add_library(${PROJECT_NAME} STATIC) +endif() set(DROGON_MAJOR_VERSION 1) set(DROGON_MINOR_VERSION 0) @@ -80,7 +95,7 @@ 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} PRIVATE ${JSONCPP_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} PUBLIC ${JSONCPP_LIBRARIES}) list(APPEND INCLUDE_DIRS_FOR_DYNAMIC_VIEW ${JSONCPP_INCLUDE_DIRS}) message(STATUS "jsoncpp inc path:" ${JSONCPP_INCLUDE_DIRS}) @@ -171,14 +186,6 @@ else() lib/src/ssl_funcs/Sha1.cc) endif() -if(NOT BUILD_ORM) - set(BUILD_ORM TRUE CACHE BOOL INTERNAL) -endif() - -if(NOT LIBPQ_BATCH_MODE) - set(LIBPQ_BATCH_MODE TRUE CACHE BOOL INTERNAL) -endif() - if(BUILD_ORM) # find postgres find_package(PostgreSQL) @@ -254,18 +261,10 @@ add_custom_command(TARGET makeVersion WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} VERBATIM) -if(NOT BUILD_EXAMPLES) - set(BUILD_EXAMPLES TRUE CACHE BOOL INTERNAL) -endif() - if(BUILD_EXAMPLES) add_subdirectory(examples) endif() -if(NOT BUILD_CTL) - set(BUILD_CTL TRUE CACHE BOOL INTERNAL) -endif() - if(BUILD_CTL) add_subdirectory(drogon_ctl) endif() @@ -369,7 +368,8 @@ endif() install(TARGETS ${PROJECT_NAME} EXPORT DrogonTargets - ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib) + ARCHIVE DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib + LIBRARY DESTINATION "${INSTALL_LIB_DIR}" COMPONENT lib) set(DROGON_HEADERS lib/inc/drogon/Attribute.h