Added `curl` executable to Windows build. Some Mesos health checks use the `curl` executable, which is a required component on Linux, but also shipped on the system. On Windows, `curl.exe` is not normally available. However, we already build `curl` for other components which link to `libcurl`. Part of this build also builds `curl.exe`, so we renamed the `curl` target to `libcurl` (explicitly meaning the library), and added `curl` as an imported executable target on Windows.
Note that this uses `add_custom_command(... POST_BUILD)` to inject a copy step as a post-build side effect of the `ExternalProject_Add` target which builds cURL. There is no cleaner way to accomplish this as CMake does not otherwise have an easy way to copy a file as part of an _imported_ target at build time. The `add_custom_target` command does not work because it adds a target that will always be built (not what we're trying to accomplish here), and the other signature of `add_custom_command` does not produce a target dependency. While the `OUTPUT` argument would let us use file dependencies, `curl.exe` isn't a source file that another target can depend on. Review: https://reviews.apache.org/r/64102/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b464f49c Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b464f49c Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b464f49c Branch: refs/heads/master Commit: b464f49cb79c4921f83cb4bf0f12c47a5d8fa4ed Parents: f031e03 Author: John Kordich <[email protected]> Authored: Wed Dec 6 12:08:32 2017 -0800 Committer: Andrew Schwartzmeyer <[email protected]> Committed: Wed Dec 6 14:09:52 2017 -0800 ---------------------------------------------------------------------- 3rdparty/CMakeLists.txt | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/b464f49c/3rdparty/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt index c34b65d..e2370fd 100755 --- a/3rdparty/CMakeLists.txt +++ b/3rdparty/CMakeLists.txt @@ -564,8 +564,17 @@ endif () ###################################################################### if (WIN32) EXTERNAL(curl ${CURL_VERSION} ${CMAKE_CURRENT_BINARY_DIR}) - add_library(curl ${LIBRARY_LINKAGE} IMPORTED GLOBAL) - add_dependencies(curl ${CURL_TARGET}) + + # This is named `libcurl` to not conflict with the executable. + add_library(libcurl ${LIBRARY_LINKAGE} IMPORTED GLOBAL) + add_dependencies(libcurl ${CURL_TARGET}) + + # Contrary to Linux, the CMake build deploys `curl.exe` on Windows. + # + # NOTE: The dependency on `CURL_TARGET` is introduced by the generator + # expression in `add_custom_command` below. Introducing it here via + # `add_dependencies` creates a cycle. + add_executable(curl IMPORTED GLOBAL) set(CURL_CMAKE_ARGS ${CMAKE_FORWARD_ARGS} @@ -579,36 +588,48 @@ if (WIN32) list(APPEND CURL_CMAKE_ARGS -DCURL_STATICLIB=ON) set_target_properties( - curl PROPERTIES + libcurl PROPERTIES INTERFACE_COMPILE_DEFINITIONS CURL_STATICLIB) endif () set_target_properties( - curl PROPERTIES + libcurl PROPERTIES IMPORTED_LOCATION_DEBUG ${CURL_ROOT}-build/lib/Debug/libcurl${LIBRARY_SUFFIX} IMPORTED_LOCATION_RELEASE ${CURL_ROOT}-build/lib/Release/libcurl${LIBRARY_SUFFIX} IMPORTED_IMPLIB_DEBUG ${CURL_ROOT}-build/lib/Debug/libcurl_imp${CMAKE_IMPORT_LIBRARY_SUFFIX} IMPORTED_IMPLIB_RELEASE ${CURL_ROOT}-build/lib/Release/libcurl_imp${CMAKE_IMPORT_LIBRARY_SUFFIX} INTERFACE_INCLUDE_DIRECTORIES ${CURL_ROOT}/include) - MAKE_INCLUDE_DIR(curl) + set_target_properties( + curl PROPERTIES + IMPORTED_LOCATION_DEBUG ${CURL_ROOT}-build/src/Debug/curl.exe + IMPORTED_LOCATION_RELEASE ${CURL_ROOT}-build/src/Release/curl.exe) + + MAKE_INCLUDE_DIR(libcurl) + GET_BYPRODUCTS(libcurl) GET_BYPRODUCTS(curl) ExternalProject_Add( ${CURL_TARGET} PREFIX ${CURL_CMAKE_ROOT} - BUILD_BYPRODUCTS ${CURL_BYPRODUCTS} + BUILD_BYPRODUCTS ${LIBCURL_BYPRODUCTS};${CURL_BYPRODUCTS} PATCH_COMMAND ${CMAKE_NOOP} CMAKE_ARGS ${CURL_CMAKE_ARGS} INSTALL_COMMAND ${CMAKE_NOOP} URL ${CURL_URL} URL_HASH ${CURL_HASH}) + + # This copies the file `curl.exe` from the `3rdparty` build folder to + # `build/src`, next to the other produced executables. This is necessary for + # code that shells out to cURL on Windows. + add_custom_command(TARGET ${CURL_TARGET} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:curl> ${CMAKE_BINARY_DIR}/src) else () find_package(CURL REQUIRED) - add_library(curl SHARED IMPORTED) + add_library(libcurl SHARED IMPORTED) set_target_properties( - curl PROPERTIES + libcurl PROPERTIES IMPORTED_LOCATION ${CURL_LIBRARIES} INTERFACE_INCLUDE_DIRECTORIES ${CURL_INCLUDE_DIRS}) endif ()
