-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
129 lines (106 loc) · 4.11 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
project(libs3)
cmake_minimum_required(VERSION 3.0)
set(CMAKE_COLOR_MAKEFILE ON)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE )
endif()
set(CMAKE_DEBUG_POSTFIX CACHE STRING "Postfix for debug library name. Usualy '_d'")
if(EXISTS ${EXT_LIBS_IMPORT})
# - curl development libraries
# - libxml2 development libraries, and the libraries that it requires (iconv, zlib)
set(EXT_LIBS_IMPORT CACHE FILEPATH "Definition for libraries 'xml' and 'curl' (import.cmake)")
include("${EXT_LIBS_IMPORT}")
if(curl_PUBLIC_INCLUDES)
include_directories("${curl_PUBLIC_INCLUDES}")
message(STATUS " Added a custom include dir: '${curl_PUBLIC_INCLUDES}'")
endif()
if(xml_PUBLIC_INCLUDES)
include_directories("${xml_PUBLIC_INCLUDES}")
message(STATUS " Added a custom include dir: '${xml_PUBLIC_INCLUDES}'")
endif()
else()
find_package(PkgConfig REQUIRED)
# copy-paste: sudo apt-get install libxml2-dev libcurl4-openssl-dev
set(LIB_DEPS_LIST
libxml-2.0 # libxml2-dev
libcurl # libcurl4-openssl-dev
)
pkg_check_modules(PKGCONFIG_DEPS REQUIRED ${LIB_DEPS_LIST})
include_directories(${PKGCONFIG_DEPS_INCLUDE_DIRS})
#include(CMakeImports/import-Linux.cmake)
endif()
################################################################################
set(LIBS3_VER_MAJOR "4")
set(LIBS3_VER_MINOR "1")
set(LIBS3_VER "${LIBS3_VER_MAJOR}.${LIBS3_VER_MINOR}")
add_definitions(
-DLIBS3_VER_MAJOR="${LIBS3_VER_MAJOR}"
-DLIBS3_VER_MINOR="${LIBS3_VER_MINOR}"
-DLIBS3_VER="${LIBS3_VER}"
)
################################################################################
include_directories(inc)
file(GLOB libs3_PUBLIC_HEADERS inc/*.h)
file(GLOB libs3_PUBLIC_PRIVATE inc/mingw/*.h)
file(GLOB libs3_SOURCES src/*.c)
file(GLOB libs3_Win_SOURCES src/mingw*.c)
file(GLOB libs3_client_SOURCES src/s3.c)
list(REMOVE_ITEM libs3_SOURCES ${libs3_client_SOURCES})
list(REMOVE_ITEM libs3_SOURCES ${libs3_Win_SOURCES})
source_group("Public Header Files" FILES ${libs3_PUBLIC_HEADERS})
source_group("Source Files" FILES ${libs3_SOURCES})
IF(MSVC)
set(libs3_SOURCES ${libs3_SOURCES} ${libs3_Win_SOURCES})
# if (MSVC_VERSION LESS 1900) # unfortunetely C99 still not work with VS 2015
message (STATUS "Enabling patch for Visual Studio 2015 and lower")
set_source_files_properties(${libs3_SOURCES} ${libs3_PUBLIC_HEADERS} PROPERTIES LANGUAGE CXX )
add_definitions(-DMSVC_NO_C99=1)
# endif()
set(libs3_SOURCES ${libs3_SOURCES} mswin/libs3.def)
add_definitions(-Ds3_EXPORTS=1)
include_directories(inc/mingw)
ENDIF()
add_library(libs3 SHARED ${libs3_SOURCES} ${libs3_PUBLIC_HEADERS} ${libs3_PUBLIC_PRIVATE})
if(EXISTS ${EXT_LIBS_IMPORT})
target_link_libraries(libs3 xml curl)
else()
target_link_libraries(libs3 ${PKGCONFIG_DEPS_LIBRARIES})
endif()
install(TARGETS libs3
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/inc/ DESTINATION include/s3)
IF(MSVC)
target_link_libraries(libs3 ws2_32)
set_target_properties(libs3 PROPERTIES
OUTPUT_NAME "libs3"
)
install(DIRECTORY "${CMAKE_BINARY_DIR}/Debug/" DESTINATION bin CONFIGURATIONS "DEBUG" FILES_MATCHING PATTERN "*.pdb")
install(DIRECTORY "${CMAKE_BINARY_DIR}/RelWithDebInfo/" DESTINATION bin CONFIGURATIONS "RELWITHDEBINFO" FILES_MATCHING PATTERN "*.pdb")
ELSE()
set_target_properties(libs3 PROPERTIES
OUTPUT_NAME "s3"
)
ENDIF()
################################################################################
# print all compile flags on terminal
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
EXT_LIBS_IMPORT
CMAKE_DEBUG_POSTFIX
)
message(STATUS "Initial build flags:")
foreach(variable ${variables})
message(STATUS " '${variable}': ${${variable}}")
endforeach()
message(STATUS "")
################################################################################