1 | #***************************************************************************
|
---|
2 | # _ _ ____ _
|
---|
3 | # Project ___| | | | _ \| |
|
---|
4 | # / __| | | | |_) | |
|
---|
5 | # | (__| |_| | _ <| |___
|
---|
6 | # \___|\___/|_| \_\_____|
|
---|
7 | #
|
---|
8 | # Copyright (C) 1998 - 2021, Daniel Stenberg, <[email protected]>, et al.
|
---|
9 | #
|
---|
10 | # This software is licensed as described in the file COPYING, which
|
---|
11 | # you should have received as part of this distribution. The terms
|
---|
12 | # are also available at https://curl.se/docs/copyright.html.
|
---|
13 | #
|
---|
14 | # You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
---|
15 | # copies of the Software, and permit persons to whom the Software is
|
---|
16 | # furnished to do so, under the terms of the COPYING file.
|
---|
17 | #
|
---|
18 | # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
---|
19 | # KIND, either express or implied.
|
---|
20 | #
|
---|
21 | ###########################################################################
|
---|
22 | set(LIB_NAME libcurl)
|
---|
23 | set(LIBCURL_OUTPUT_NAME libcurl CACHE STRING "Basename of the curl library")
|
---|
24 |
|
---|
25 | if(BUILD_SHARED_LIBS)
|
---|
26 | set(CURL_STATICLIB NO)
|
---|
27 | else()
|
---|
28 | set(CURL_STATICLIB YES)
|
---|
29 | endif()
|
---|
30 |
|
---|
31 | # Use:
|
---|
32 | # * CURL_STATICLIB
|
---|
33 | configure_file(curl_config.h.cmake
|
---|
34 | ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
|
---|
35 |
|
---|
36 | transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
|
---|
37 | include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
|
---|
38 |
|
---|
39 | list(APPEND HHEADERS
|
---|
40 | ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
|
---|
41 | )
|
---|
42 |
|
---|
43 | if(WIN32)
|
---|
44 | list(APPEND CSOURCES libcurl.rc)
|
---|
45 | endif()
|
---|
46 |
|
---|
47 | # SET(CSOURCES
|
---|
48 | # # memdebug.c -not used
|
---|
49 | # # nwlib.c - Not used
|
---|
50 | # # strtok.c - specify later
|
---|
51 | # # strtoofft.c - specify later
|
---|
52 | # )
|
---|
53 |
|
---|
54 | # #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
|
---|
55 | # MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
|
---|
56 | # IF(CURL_MALLOC_DEBUG)
|
---|
57 | # SET(CSOURCES ${CSOURCES}
|
---|
58 | # memdebug.c
|
---|
59 | # )
|
---|
60 | # ENDIF(CURL_MALLOC_DEBUG)
|
---|
61 |
|
---|
62 | # # only build compat strtoofft if we need to
|
---|
63 | # IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
|
---|
64 | # SET(CSOURCES ${CSOURCES}
|
---|
65 | # strtoofft.c
|
---|
66 | # )
|
---|
67 | # ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
|
---|
68 |
|
---|
69 |
|
---|
70 | # The rest of the build
|
---|
71 |
|
---|
72 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
|
---|
73 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
|
---|
74 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
---|
75 | include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
|
---|
76 | include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
---|
77 | include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
---|
78 | if(USE_ARES)
|
---|
79 | include_directories(${CARES_INCLUDE_DIR})
|
---|
80 | endif()
|
---|
81 |
|
---|
82 | add_library(
|
---|
83 | ${LIB_NAME}
|
---|
84 | ${HHEADERS} ${CSOURCES}
|
---|
85 | )
|
---|
86 |
|
---|
87 | add_library(
|
---|
88 | ${PROJECT_NAME}::${LIB_NAME}
|
---|
89 | ALIAS ${LIB_NAME}
|
---|
90 | )
|
---|
91 |
|
---|
92 | if(NOT BUILD_SHARED_LIBS)
|
---|
93 | set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
|
---|
94 | endif()
|
---|
95 |
|
---|
96 | target_link_libraries(${LIB_NAME} ${CURL_LIBS})
|
---|
97 |
|
---|
98 | set_target_properties(${LIB_NAME} PROPERTIES
|
---|
99 | COMPILE_DEFINITIONS BUILDING_LIBCURL
|
---|
100 | OUTPUT_NAME ${LIBCURL_OUTPUT_NAME}
|
---|
101 | )
|
---|
102 |
|
---|
103 | if(HIDES_CURL_PRIVATE_SYMBOLS)
|
---|
104 | set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
|
---|
105 | set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
|
---|
106 | endif()
|
---|
107 |
|
---|
108 | # Remove the "lib" prefix since the library is already named "libcurl".
|
---|
109 | set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
|
---|
110 | set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
|
---|
111 |
|
---|
112 | if(CURL_HAS_LTO)
|
---|
113 | set_target_properties(${LIB_NAME} PROPERTIES
|
---|
114 | INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
|
---|
115 | INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
|
---|
116 | endif()
|
---|
117 |
|
---|
118 | if(WIN32)
|
---|
119 | if(BUILD_SHARED_LIBS)
|
---|
120 | set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "_USRDLL")
|
---|
121 | if(MSVC)
|
---|
122 | # Add "_imp" as a suffix before the extension to avoid conflicting with
|
---|
123 | # the statically linked "libcurl.lib"
|
---|
124 | set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
|
---|
125 | endif()
|
---|
126 | endif()
|
---|
127 | endif()
|
---|
128 |
|
---|
129 | target_include_directories(${LIB_NAME} INTERFACE
|
---|
130 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
---|
131 | $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
|
---|
132 |
|
---|
133 | install(TARGETS ${LIB_NAME}
|
---|
134 | EXPORT ${TARGETS_EXPORT_NAME}
|
---|
135 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
136 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
---|
137 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
---|
138 | )
|
---|
139 |
|
---|
140 | export(TARGETS ${LIB_NAME}
|
---|
141 | APPEND FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
|
---|
142 | NAMESPACE ${PROJECT_NAME}::
|
---|
143 | )
|
---|