1#*************************************************************************** 2# _ _ ____ _ 3# Project ___| | | | _ \| | 4# / __| | | | |_) | | 5# | (__| |_| | _ <| |___ 6# \___|\___/|_| \_\_____| 7# 8# Copyright (C) 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########################################################################### 24set(EXE_NAME curl) 25add_definitions("-DBUILDING_CURL") 26 27if(ENABLE_CURL_MANUAL AND HAVE_MANUAL_TOOLS) 28 add_definitions("-DUSE_MANUAL") 29 add_custom_command( 30 OUTPUT "tool_hugehelp.c" 31 COMMAND ${CMAKE_COMMAND} -E echo "#include \"tool_setup.h\"" > "tool_hugehelp.c" 32 COMMAND ${CMAKE_COMMAND} -E echo "#ifndef HAVE_LIBZ" >> "tool_hugehelp.c" 33 COMMAND "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl" < "${CURL_ASCIIPAGE}" >> "tool_hugehelp.c" 34 COMMAND ${CMAKE_COMMAND} -E echo "#else" >> "tool_hugehelp.c" 35 COMMAND "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl" -c < "${CURL_ASCIIPAGE}" >> "tool_hugehelp.c" 36 COMMAND ${CMAKE_COMMAND} -E echo "#endif /* HAVE_LIBZ */" >> "tool_hugehelp.c" 37 DEPENDS 38 generate-curl.1 39 "${CMAKE_CURRENT_SOURCE_DIR}/mkhelp.pl" 40 "${CMAKE_CURRENT_SOURCE_DIR}/tool_hugehelp.h" 41 "${CURL_ASCIIPAGE}" 42 VERBATIM) 43else() 44 add_custom_command( 45 OUTPUT "tool_hugehelp.c" 46 COMMAND ${CMAKE_COMMAND} -E echo "#include \"tool_hugehelp.h\"" > "tool_hugehelp.c" 47 DEPENDS 48 "${CMAKE_CURRENT_SOURCE_DIR}/tool_hugehelp.h" 49 VERBATIM) 50endif() 51 52# Get 'CURL_CFILES', 'CURLX_CFILES', 'CURL_HFILES', 'CURLTOOL_LIBCURL_CFILES' variables 53transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") 54include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake") 55 56if(CURL_CA_EMBED_SET) 57 if(PERL_FOUND) 58 add_definitions("-DCURL_CA_EMBED") 59 add_custom_command( 60 OUTPUT "tool_ca_embed.c" 61 COMMAND "${PERL_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/mk-file-embed.pl" --var curl_ca_embed 62 < "${CURL_CA_EMBED}" > "tool_ca_embed.c" 63 DEPENDS 64 "${CMAKE_CURRENT_SOURCE_DIR}/mk-file-embed.pl" 65 "${CURL_CA_EMBED}" 66 VERBATIM) 67 list(APPEND CURL_CFILES "tool_ca_embed.c") 68 else() 69 message(WARNING "Perl not found. Will not embed the CA bundle.") 70 endif() 71endif() 72 73if(WIN32) 74 list(APPEND CURL_CFILES "curl.rc") 75endif() 76 77if(BUILD_STATIC_CURL) 78 set(CURLX_CFILES ${CURLTOOL_LIBCURL_CFILES}) 79endif() 80 81if(ENABLE_CURLDEBUG) 82 # We must compile this source separately to avoid memdebug.h redefinitions 83 # applying to them. 84 set_source_files_properties("../lib/curl_multibyte.c" PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) 85endif() 86 87add_executable( 88 ${EXE_NAME} 89 ${CURL_CFILES} ${CURLX_CFILES} ${CURL_HFILES} 90) 91 92add_executable( 93 ${PROJECT_NAME}::${EXE_NAME} 94 ALIAS ${EXE_NAME} 95) 96 97add_library( 98 curltool # special libcurltool library just for unittests 99 STATIC 100 EXCLUDE_FROM_ALL 101 ${CURL_CFILES} ${CURLTOOL_LIBCURL_CFILES} ${CURL_HFILES} 102) 103target_compile_definitions(curltool PUBLIC "UNITTESTS" "CURL_STATICLIB") 104target_link_libraries(curltool PRIVATE ${CURL_LIBS}) 105 106if(CURL_HAS_LTO) 107 set_target_properties(${EXE_NAME} PROPERTIES 108 INTERPROCEDURAL_OPTIMIZATION_RELEASE TRUE 109 INTERPROCEDURAL_OPTIMIZATION_RELWITHDEBINFO TRUE) 110endif() 111 112if(ENABLE_UNICODE AND MINGW) 113 target_link_libraries(${EXE_NAME} "-municode") 114endif() 115 116source_group("curlX source files" FILES ${CURLX_CFILES}) 117source_group("curl source files" FILES ${CURL_CFILES}) 118source_group("curl header files" FILES ${CURL_HFILES}) 119 120include_directories( 121 "${PROJECT_BINARY_DIR}/lib" # for "curl_config.h" 122 "${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h" 123 # This is needed as tool_hugehelp.c is generated in the binary dir 124 "${PROJECT_SOURCE_DIR}/src" # for "tool_hugehelp.h" 125) 126 127# Build curl executable 128target_link_libraries(${EXE_NAME} ${LIB_SELECTED_FOR_EXE} ${CURL_LIBS}) 129 130################################################################################ 131 132install(TARGETS ${EXE_NAME} EXPORT ${TARGETS_EXPORT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) 133export(TARGETS ${EXE_NAME} 134 FILE "${PROJECT_BINARY_DIR}/curl-target.cmake" 135 NAMESPACE ${PROJECT_NAME}:: 136) 137