Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Utilities / cmcurl / lib / CMakeLists.txt
1 #***************************************************************************
2 #                                  _   _ ____  _
3 #  Project                     ___| | | |  _ \| |
4 #                             / __| | | | |_) | |
5 #                            | (__| |_| |  _ <| |___
6 #                             \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) 1998 - 2022, Daniel Stenberg, <daniel@haxx.se>, 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 # SPDX-License-Identifier: curl
22 #
23 ###########################################################################
24 set(LIB_NAME cmcurl)
25 set(LIBCURL_OUTPUT_NAME cmcurl)
26 add_definitions(-DBUILDING_LIBCURL)
27
28 if(BUILD_SHARED_LIBS)
29   set(CURL_STATICLIB NO)
30 else()
31   set(CURL_STATICLIB YES)
32 endif()
33
34 # Use:
35 # * CURL_STATICLIB
36 configure_file(curl_config.h.cmake
37   ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h)
38
39 transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
40 include(${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake)
41
42 list(APPEND HHEADERS
43   ${CMAKE_CURRENT_BINARY_DIR}/curl_config.h
44   )
45
46 if(WIN32 AND NOT CURL_STATICLIB)
47   list(APPEND CSOURCES libcurl.rc)
48 endif()
49
50 # SET(CSOURCES
51 # #  memdebug.c -not used
52 # # nwlib.c - Not used
53 # # strtok.c - specify later
54 # # strtoofft.c - specify later
55 # )
56
57 # #OPTION(CURL_MALLOC_DEBUG "Debug mallocs in Curl" OFF)
58 # MARK_AS_ADVANCED(CURL_MALLOC_DEBUG)
59 # IF(CURL_MALLOC_DEBUG)
60 # SET(CSOURCES ${CSOURCES}
61 # memdebug.c
62 # )
63 # ENDIF(CURL_MALLOC_DEBUG)
64
65 # # only build compat strtoofft if we need to
66 # IF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
67 # SET(CSOURCES ${CSOURCES}
68 # strtoofft.c
69 # )
70 # ENDIF(NOT HAVE_STRTOLL AND NOT HAVE__STRTOI64)
71
72
73 # The rest of the build
74
75 include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include)
76 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..)
77 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
78 include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
79 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
80 include_directories(${CMAKE_CURRENT_BINARY_DIR})
81 if(USE_ARES)
82   include_directories(${CARES_INCLUDE_DIR})
83 endif()
84
85 # For windows we want to install OPENSSL_LIBRARIES dlls
86 # and also copy them into the build tree so that testing
87 # can find them.
88 if(CURL_USE_OPENSSL AND OPENSSL_FOUND AND WIN32)
89   find_file(CMAKE_EAY_DLL NAME libeay32.dll HINTS ${OPENSSL_INCLUDE_DIR}/..)
90   find_file(CMAKE_SSL_DLL NAME ssleay32.dll HINTS ${OPENSSL_INCLUDE_DIR}/..)
91   mark_as_advanced(CMAKE_EAY_DLL CMAKE_SSL_DLL)
92   if(CMAKE_SSL_DLL AND CMAKE_EAY_DLL)
93     set(CMAKE_CURL_SSL_DLLS ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll
94       ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll)
95     add_custom_command(OUTPUT
96       ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll
97       DEPENDS ${CMAKE_EAY_DLL}
98       COMMAND ${CMAKE_COMMAND} -E copy  ${CMAKE_EAY_DLL}
99       ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/libeay32.dll)
100     add_custom_command(OUTPUT
101       ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll
102       DEPENDS ${CMAKE_SSL_DLL}
103       COMMAND ${CMAKE_COMMAND} -E copy  ${CMAKE_SSL_DLL}
104       ${CMake_BIN_DIR}/${CMAKE_CFG_INTDIR}/ssleay32.dll)
105     install(PROGRAMS ${CMAKE_EAY_DLL} ${CMAKE_SSL_DLL} DESTINATION bin)
106   endif()
107 endif()
108
109 add_library(
110   ${LIB_NAME}
111   ${HHEADERS} ${CSOURCES}
112   ${CMAKE_CURL_SSL_DLLS}
113   )
114
115 add_library(
116   ${PROJECT_NAME}::${LIB_NAME}
117   ALIAS ${LIB_NAME}
118   )
119
120 if(NOT BUILD_SHARED_LIBS)
121     set_target_properties(${LIB_NAME} PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB)
122 endif()
123
124 target_link_libraries(${LIB_NAME} PRIVATE ${CURL_LIBS})
125
126 set_target_properties(${LIB_NAME} PROPERTIES
127   COMPILE_DEFINITIONS BUILDING_LIBCURL
128   OUTPUT_NAME ${LIBCURL_OUTPUT_NAME}
129   )
130
131 if(0) # This code not needed for building within CMake.
132 if(HIDES_CURL_PRIVATE_SYMBOLS)
133   set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_HIDDEN_SYMBOLS")
134   set_property(TARGET ${LIB_NAME} APPEND PROPERTY COMPILE_FLAGS ${CURL_CFLAG_SYMBOLS_HIDE})
135 endif()
136
137 # Remove the "lib" prefix since the library is already named "libcurl".
138 set_target_properties(${LIB_NAME} PROPERTIES PREFIX "")
139 set_target_properties(${LIB_NAME} PROPERTIES IMPORT_PREFIX "")
140
141 if(CURL_HAS_LTO)
142   set_target_properties(${LIB_NAME} PROPERTIES
143     INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE
144     INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE)
145 endif()
146
147 if(WIN32)
148   if(BUILD_SHARED_LIBS)
149     if(MSVC)
150       # Add "_imp" as a suffix before the extension to avoid conflicting with
151       # the statically linked "libcurl.lib"
152       set_target_properties(${LIB_NAME} PROPERTIES IMPORT_SUFFIX "_imp.lib")
153     endif()
154   endif()
155 endif()
156
157 target_include_directories(${LIB_NAME} INTERFACE
158   $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
159   $<BUILD_INTERFACE:${CURL_SOURCE_DIR}/include>)
160
161 if(CURL_ENABLE_EXPORT_TARGET)
162   install(TARGETS ${LIB_NAME}
163     EXPORT ${TARGETS_EXPORT_NAME}
164     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
165     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
166     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
167   )
168
169   export(TARGETS ${LIB_NAME}
170          FILE ${PROJECT_BINARY_DIR}/libcurl-target.cmake
171          NAMESPACE ${PROJECT_NAME}::
172   )
173 endif()
174
175 endif()