-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
77 lines (61 loc) · 2.94 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
cmake_minimum_required(VERSION 3.6.0)
project(libdelphi LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Settings
# ----------------------------------------------------------------------------------------------------------------------
set(BUILD_STATIC_LIB OFF CACHE BOOL "Build a static library")
set(BUILD_SHARED_LIB OFF CACHE BOOL "Build a shared library")
set(WITH_POSTGRESQL OFF CACHE BOOL "Build with PostgreSQL")
set(WITH_SQLITE OFF CACHE BOOL "Build with Sqlite")
set(WITH_CURL ON CACHE BOOL "Build with cURL")
set(EXTRA_WARNING_MODE OFF CACHE BOOL "Add extra warnings in debug mode")
# ----------------------------------------------------------------------------------------------------------------------
if (CMAKE_BUILD_TYPE STREQUAL "Debug" AND EXTRA_WARNING_MODE)
include(contrib/cmake/enable_cxx_compiler_flag_if_supported.cmake)
enable_cxx_compiler_flag_if_supported(CMAKE_CXX_FLAGS_DEBUG "-Wall")
enable_cxx_compiler_flag_if_supported(CMAKE_CXX_FLAGS_DEBUG "-Wextra")
enable_cxx_compiler_flag_if_supported(CMAKE_CXX_FLAGS_DEBUG "-pedantic")
endif()
add_compile_options("-DDELPHI_LIB_EXPORTS")
# -Iinclude
include_directories(include)
include_directories(src)
# add library directories
add_subdirectory(include)
add_subdirectory(src)
# Delphi classes for C++
# ----------------------------------------------------------------------------------------------------------------------
set(DELPHI_LIB_NAME delphi)
if (WITH_POSTGRESQL)
message(STATUS "Using PostgreSQL.")
find_package(PostgreSQL REQUIRED)
set(PQ_LIB_NAME "pq")
add_compile_options("-DWITH_POSTGRESQL")
endif()
if (WITH_SQLITE)
message(STATUS "Using SQLite.")
set(SQLITE_LIB_NAME "sqlite3")
add_compile_options("-DWITH_SQLITE")
endif()
if (BUILD_STATIC_LIB)
# build the static library
add_library(${DELPHI_LIB_NAME}_static STATIC $<TARGET_OBJECTS:delphi>)
set_target_properties(${DELPHI_LIB_NAME}_static PROPERTIES OUTPUT_NAME "${DELPHI_LIB_NAME}")
target_link_libraries(${DELPHI_LIB_NAME}_static pthread ${SQLITE_LIB_NAME} ${PQ_LIB_NAME})
install(TARGETS ${DELPHI_LIB_NAME}_static DESTINATION lib)
endif()
if (BUILD_SHARED_LIB)
# build the static library
add_library(${DELPHI_LIB_NAME}_shared SHARED $<TARGET_OBJECTS:delphi>)
set_target_properties(${DELPHI_LIB_NAME}_shared PROPERTIES OUTPUT_NAME "${DELPHI_LIB_NAME}")
target_link_libraries(${DELPHI_LIB_NAME}_shared pthread ${SQLITE_LIB_NAME} ${PQ_LIB_NAME})
install(TARGETS ${DELPHI_LIB_NAME}_shared DESTINATION lib)
endif()
# ----------------------------------------------------------------------------------------------------------------------
if (BUILD_STATIC_LIB OR BUILD_SHARED_LIB)
# add pkg-config
configure_file("contrib/${DELPHI_LIB_NAME}.pc.in" "${DELPHI_LIB_NAME}.pc" @ONLY)
install(FILES "${CMAKE_BINARY_DIR}/${DELPHI_LIB_NAME}.pc" DESTINATION lib/pkgconfig)
endif()