diff --git a/CMakeLists.txt b/CMakeLists.txt index 958beb633..13e240178 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,7 +112,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES) # Allow the user to enable/disable all system utility library options by # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}. - set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA ZLIB) + set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA LIBUV ZLIB) foreach(util ${UTILITIES}) if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util} AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES) @@ -152,6 +152,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES) "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON) option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}") option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}") + option(CMAKE_USE_SYSTEM_LIBUV "Use system-installed libuv" "${CMAKE_USE_SYSTEM_LIBRARY_LIBUV}") # For now use system KWIML only if explicitly requested rather # than activating via the general system libs options. @@ -469,9 +470,22 @@ macro (CMAKE_BUILD_UTILITIES) set(CMAKE_USE_LIBUV 1) endif() if(CMAKE_USE_LIBUV) - set(CMAKE_LIBUV_LIBRARIES cmlibuv) - add_subdirectory(Utilities/cmlibuv) - CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty") + if(CMAKE_USE_SYSTEM_LIBUV) + if(NOT CMAKE_VERSION VERSION_LESS 3.0) + include(${CMake_SOURCE_DIR}/Source/Modules/FindLibUV.cmake) + else() + message(FATAL_ERROR "CMAKE_USE_SYSTEM_LIBUV requires CMake >= 3.0") + endif() + if(NOT LIBUV_FOUND) + message(FATAL_ERROR + "CMAKE_USE_SYSTEM_LIBUV is ON but a libuv is not found!") + endif() + set(CMAKE_LIBUV_LIBRARIES LibUV::LibUV) + else() + set(CMAKE_LIBUV_LIBRARIES cmlibuv) + add_subdirectory(Utilities/cmlibuv) + CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty") + endif() else() set(CMAKE_LIBUV_LIBRARIES) endif() diff --git a/Utilities/cmThirdParty.h.in b/Utilities/cmThirdParty.h.in index 4c1177ca8..cb8f0d545 100644 --- a/Utilities/cmThirdParty.h.in +++ b/Utilities/cmThirdParty.h.in @@ -22,6 +22,7 @@ #cmakedefine CMAKE_USE_SYSTEM_LIBLZMA #cmakedefine CMAKE_USE_SYSTEM_FORM #cmakedefine CMAKE_USE_SYSTEM_JSONCPP +#cmakedefine CMAKE_USE_SYSTEM_LIBUV #cmakedefine CTEST_USE_XMLRPC #endif diff --git a/Utilities/cm_uv.h b/Utilities/cm_uv.h index 63ff59715..baa9bfc95 100644 --- a/Utilities/cm_uv.h +++ b/Utilities/cm_uv.h @@ -12,6 +12,12 @@ #ifndef cm_uv_h #define cm_uv_h +/* Use the libuv library configured for CMake. */ +#include "cmThirdParty.h" +#ifdef CMAKE_USE_SYSTEM_LIBUV +#include +#else #include +#endif #endif