From 929e15faa7f6a0c27f72d3829b7dd4d7bd6a94cf Mon Sep 17 00:00:00 2001 From: Tobias Peters Date: Fri, 12 Jul 2024 08:56:13 +0000 Subject: [PATCH] extract hunter dependencies into separate file remove implicit dependency, make caching easier and enable usage of other package manager --- CMakeLists.txt | 140 ++++++++------------- CMakeModules/FindHelpers.cmake | 2 +- CMakeModules/FindLuabind.cmake | 1 - CMakeModules/HunterDependencies.cmake | 30 +++++ CMakeModules/nel.cmake | 43 +------ nel/CMakeLists.txt | 10 +- nel/src/misc/CMakeLists.txt | 15 --- nel/src/sound/CMakeLists.txt | 18 --- nel/src/sound/driver/openal/CMakeLists.txt | 11 +- ryzom/tools/CMakeLists.txt | 4 +- 10 files changed, 86 insertions(+), 188 deletions(-) create mode 100644 CMakeModules/HunterDependencies.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 937faa4b0e..d0f128c772 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,10 @@ SET(NL_VERSION_BUILD ${RyzomCore_VERSION_TWEAK} CACHE STRING "Build number") SET(YEAR "2001-${CURRENT_YEAR}") SET(AUTHOR "Winch Gate and The Ryzom Core Community") +IF(HUNTER_ENABLED) + include(CMakeModules/HunterDependencies.cmake) +ENDIF() + #----------------------------------------------------------------------------- # Redirect output files SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) @@ -168,39 +172,6 @@ IF(WIN32) ENDIF() ENDIF() -IF(HUNTER_ENABLED) - # This fix is for compiling OpenSSL in Azure Pipeline linux agent where ENV{SYSTEM} == "build" - IF(DEFINED ENV{SYSTEM} AND UNIX AND NOT APPLE) - STRING(TOUPPER "$ENV{SYSTEM}" _tmp) - IF (_tmp STREQUAL "BUILD") - UNSET(ENV{SYSTEM}) - ENDIF() - UNSET(_tmp) - ENDIF() - ## TODO: hack for freetype hunter package - SET(ON 1) - ## - HUNTER_ADD_PACKAGE(ZLIB) - - FIND_PACKAGE(ZLIB CONFIG REQUIRED) - SET(ZLIB_LIBRARY ZLIB::zlib) - - HUNTER_ADD_PACKAGE(libxml2) - FIND_PACKAGE(libxml2 CONFIG REQUIRED) - SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} libxml2::libxml2) - - # cross compiling doesn't quite work on the hunter openssl package therefor compile it separately and use it - IF(NOT CMAKE_CROSSCOMPILING) - HUNTER_ADD_PACKAGE(OpenSSL) - ENDIF() - FIND_PACKAGE(OpenSSL REQUIRED) - # TODO: is OpenSSL::Crypto only needed for WIN32? - SET(OPENSSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) - - # for precompiled headers, not needed if using TARGET_PRECOMPILE_HEADERS() from cmake 3.16+ - SET(ZLIB_INCLUDE_DIR ZLIB_ROOT/include) - SET(LIBXML2_INCLUDE_DIR ${LIBXML2_ROOT}/include/libxml2) -ELSE() FIND_PACKAGE(ZLIB REQUIRED) FIND_PACKAGE(LibXml2 REQUIRED) FIND_PACKAGE(PNG REQUIRED) @@ -211,7 +182,6 @@ FIND_PACKAGE(Jpeg) IF(WIN32) SET(OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES} Crypt32.lib) ENDIF() -ENDIF() #hunter IF(WITH_LIBOVR) FIND_PACKAGE(LibOVR) @@ -239,7 +209,7 @@ IF(WITH_STATIC) SET(LIBXML2_LIBRARIES ${LIBXML2_LIBRARIES} ${WINSOCK2_LIB}) ENDIF() - IF(UNIX AND NOT HUNTER_ENABLED) + IF(UNIX) # under Linux and OS X, recent libxml2 versions are linked against liblzma FIND_PACKAGE(LibLZMA) IF(LIBLZMA_LIBRARIES) @@ -341,75 +311,63 @@ IF(WITH_NEL_TESTS) ENDIF() IF(WITH_NEL) - IF(HUNTER_ENABLED) - IF(WITH_GUI) - HUNTER_ADD_PACKAGE(luabind) - FIND_PACKAGE(Luabind REQUIRED) - ENDIF() + IF(WITH_GUI) + FIND_PACKAGE(Luabind REQUIRED) + ENDIF() + + FIND_PACKAGE(CURL REQUIRED) + # if cmake finds config-file package, ie FIND_PACKAGE(CURL CONFIG), then CURL_LIBRARIES is not defined + IF(TARGET CURL::libcurl) + SET(CURL_LIBRARIES CURL::libcurl) + ENDIF() - HUNTER_ADD_PACKAGE(CURL) - FIND_PACKAGE(CURL CONFIG REQUIRED) - # TODO: for nelgui - SET(CURL_LIBRARIES CURL::libcurl libxml2::libxml2) + IF((WIN32 OR CURL_LIBRARIES MATCHES "\\.a") AND WITH_STATIC_CURL) + SET(CURL_STATIC ON) ELSE() - IF(WITH_GUI) - FIND_PACKAGE(Luabind REQUIRED) - ENDIF() + SET(CURL_STATIC OFF) + ENDIF() - FIND_PACKAGE(CURL REQUIRED) - # if cmake finds config-file package, ie FIND_PACKAGE(CURL CONFIG), then CURL_LIBRARIES is not defined - IF(TARGET CURL::libcurl) - SET(CURL_LIBRARIES CURL::libcurl) - ENDIF() + IF(CURL_STATIC) + SET(CURL_DEFINITIONS -DCURL_STATICLIB) + + LIST(APPEND CURL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) + LIST(APPEND CURL_LIBRARIES ${OPENSSL_LIBRARIES}) - IF((WIN32 OR CURL_LIBRARIES MATCHES "\\.a") AND WITH_STATIC_CURL) - SET(CURL_STATIC ON) + IF(WIN32) + LIST(APPEND CURL_LIBRARIES Crypt32 Cryptui) ELSE() - SET(CURL_STATIC OFF) - ENDIF() + # CURL depends on libidn + FIND_LIBRARY(IDN_LIBRARY idn) + IF(IDN_LIBRARY) + LIST(APPEND CURL_LIBRARIES ${IDN_LIBRARY}) + ENDIF() - IF(CURL_STATIC) - SET(CURL_DEFINITIONS -DCURL_STATICLIB) + # CURL Macports version can depend on libidn, libidn2, libintl, libpsl and libiconv too + IF(APPLE) + FIND_LIBRARY(INTL_LIBRARY intl) + IF(INTL_LIBRARY) + LIST(APPEND CURL_LIBRARIES ${INTL_LIBRARY}) + ENDIF() - LIST(APPEND CURL_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR}) - LIST(APPEND CURL_LIBRARIES ${OPENSSL_LIBRARIES}) + FIND_LIBRARY(IDN2_LIBRARY idn2) + IF(IDN2_LIBRARY) + LIST(APPEND CURL_LIBRARIES ${IDN2_LIBRARY}) + ENDIF() - IF(WIN32) - LIST(APPEND CURL_LIBRARIES Crypt32 Cryptui) - ELSE() - # CURL depends on libidn - FIND_LIBRARY(IDN_LIBRARY idn) - IF(IDN_LIBRARY) - LIST(APPEND CURL_LIBRARIES ${IDN_LIBRARY}) + FIND_LIBRARY(PSL_LIBRARY psl) + IF(PSL_LIBRARY) + LIST(APPEND CURL_LIBRARIES ${PSL_LIBRARY}) ENDIF() - # CURL Macports version can depend on libidn, libidn2, libintl, libpsl and libiconv too - IF(APPLE) - FIND_LIBRARY(INTL_LIBRARY intl) - IF(INTL_LIBRARY) - LIST(APPEND CURL_LIBRARIES ${INTL_LIBRARY}) - ENDIF() - - FIND_LIBRARY(IDN2_LIBRARY idn2) - IF(IDN2_LIBRARY) - LIST(APPEND CURL_LIBRARIES ${IDN2_LIBRARY}) - ENDIF() - - FIND_LIBRARY(PSL_LIBRARY psl) - IF(PSL_LIBRARY) - LIST(APPEND CURL_LIBRARIES ${PSL_LIBRARY}) - ENDIF() - - FIND_LIBRARY(UNISTRING_LIBRARY unistring) - IF(UNISTRING_LIBRARY) - LIST(APPEND CURL_LIBRARIES ${UNISTRING_LIBRARY}) - ENDIF() - - LIST(APPEND CURL_LIBRARIES ${SECURITY_FRAMEWORK}) + FIND_LIBRARY(UNISTRING_LIBRARY unistring) + IF(UNISTRING_LIBRARY) + LIST(APPEND CURL_LIBRARIES ${UNISTRING_LIBRARY}) ENDIF() + + LIST(APPEND CURL_LIBRARIES ${SECURITY_FRAMEWORK}) ENDIF() ENDIF() - ENDIF() #hunter + ENDIF() INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/nel/include) ADD_SUBDIRECTORY(nel) diff --git a/CMakeModules/FindHelpers.cmake b/CMakeModules/FindHelpers.cmake index 71e13b0b01..bc4d82bc94 100644 --- a/CMakeModules/FindHelpers.cmake +++ b/CMakeModules/FindHelpers.cmake @@ -731,7 +731,7 @@ MACRO(FIND_LIBXML2) IF(CRYPT32_LIB) LIST(APPEND LIBXML2_LIBRARIES ${CRYPT32_LIB}) ENDIF() - ELSEIF(NOT HUNTER_ENABLED) + ELSE() # under Linux and OS X, recent libxml2 versions are linked against liblzma FIND_PACKAGE(LibLZMA) diff --git a/CMakeModules/FindLuabind.cmake b/CMakeModules/FindLuabind.cmake index 000c63bb25..62dfc56052 100644 --- a/CMakeModules/FindLuabind.cmake +++ b/CMakeModules/FindLuabind.cmake @@ -84,7 +84,6 @@ MACRO(FIND_CORRECT_LUA_VERSION) ELSE() # TODO: find a way to detect Lua version IF(HUNTER_ENABLED) - HUNTER_ADD_PACKAGE(Lua) FIND_PACKAGE(Lua CONFIG REQUIRED) SET(LUA_LIBRARIES Lua::lua_lib) ELSEIF(WITH_LUA54) diff --git a/CMakeModules/HunterDependencies.cmake b/CMakeModules/HunterDependencies.cmake new file mode 100644 index 0000000000..bc2010e921 --- /dev/null +++ b/CMakeModules/HunterDependencies.cmake @@ -0,0 +1,30 @@ +# This fix is for compiling OpenSSL in Azure Pipeline linux agent where ENV{SYSTEM} == "build" +IF (DEFINED ENV{SYSTEM} AND UNIX AND NOT APPLE) + STRING(TOUPPER "$ENV{SYSTEM}" _tmp) + IF (_tmp STREQUAL "BUILD") + UNSET(ENV{SYSTEM}) + ENDIF () + UNSET(_tmp) +ENDIF () +## TODO: hack for freetype hunter package +SET(ON 1) +## +HUNTER_ADD_PACKAGE(ZLIB) +HUNTER_ADD_PACKAGE(libxml2) + +# cross compiling doesn't quite work on the hunter openssl package therefor compile it separately and use it +IF (NOT CMAKE_CROSSCOMPILING) + HUNTER_ADD_PACKAGE(OpenSSL) +ENDIF () + +HUNTER_ADD_PACKAGE(luabind) +HUNTER_ADD_PACKAGE(CURL) +HUNTER_ADD_PACKAGE(Lua) +HUNTER_ADD_PACKAGE(freetype) +HUNTER_ADD_PACKAGE(Jpeg) +HUNTER_ADD_PACKAGE(giflib) +HUNTER_ADD_PACKAGE(PNG) +HUNTER_ADD_PACKAGE(libogg) +HUNTER_ADD_PACKAGE(vorbis) +HUNTER_ADD_PACKAGE(ffmpeg) +HUNTER_ADD_PACKAGE(OpenAL) diff --git a/CMakeModules/nel.cmake b/CMakeModules/nel.cmake index f0af98fac6..eee3da152e 100644 --- a/CMakeModules/nel.cmake +++ b/CMakeModules/nel.cmake @@ -121,22 +121,6 @@ MACRO(NL_ADD_RUNTIME_FLAGS name) ENDMACRO(NL_ADD_RUNTIME_FLAGS) MACRO(NL_ADD_STATIC_VID_DRIVERS name) -IF(HUNTER_ENABLED) - IF(WIN32) - SET(drv_suffix "_win") - ELSE() - SET(drv_suffix "") - ENDIF() - IF(WIN32 AND WITH_DRIVER_DIRECT3D) - TARGET_LINK_LIBRARIES(${name} nel_drv_direct3d${drv_suffix}) - ENDIF() - IF(WITH_DRIVER_OPENGL) - TARGET_LINK_LIBRARIES(${name} nel_drv_opengl${drv_suffix}) - ENDIF() - IF(WITH_DRIVER_OPENGLES) - TARGET_LINK_LIBRARIES(${name} nel_drv_opengles${drv_suffix}) - ENDIF() -ELSE() IF(WITH_STATIC_DRIVERS) IF(WIN32) IF(WITH_DRIVER_DIRECT3D) @@ -160,29 +144,9 @@ ELSE() ENDIF() ENDIF() ENDIF() -ENDIF()#hunter ENDMACRO(NL_ADD_STATIC_VID_DRIVERS) MACRO(NL_ADD_STATIC_SND_DRIVERS name) -IF(HUNTER_ENABLED) - IF(WIN32) - SET(drv_suffix "_win") - ELSE() - SET(drv_suffix "") - ENDIF() - IF(WIN32 AND WITH_DRIVER_DSOUND) - TARGET_LINK_LIBRARIES(${name} nel_drv_dsound${drv_suffix}) - ENDIF() - IF(WIN32 AND WITH_DRIVER_XAUDIO2) - TARGET_LINK_LIBRARIES(${name} nel_drv_xaudio2${drv_suffix}) - ENDIF() - IF(WITH_DRIVER_FMOD) - TARGET_LINK_LIBRARIES(${name} nel_drv_fmod${drv_suffix}) - ENDIF() - IF(WITH_DRIVER_OPENAL) - TARGET_LINK_LIBRARIES(${name} nel_drv_openal${drv_suffix}) - ENDIF() -ELSE() IF(WITH_STATIC_DRIVERS) IF(WIN32) IF(WITH_DRIVER_DSOUND) @@ -211,7 +175,6 @@ ELSE() ENDIF() ENDIF() -ENDIF() #hunter ENDMACRO(NL_ADD_STATIC_SND_DRIVERS) ### @@ -1264,11 +1227,7 @@ MACRO(SETUP_EXTERNAL) ENDIF() IF(WIN32) - IF (HUNTER_ENABLED) - FIND_PACKAGE(External QUIET) - ELSE() - FIND_PACKAGE(External REQUIRED) - ENDIF() + FIND_PACKAGE(External REQUIRED) # If using custom boost, we need to define the right variables used by official boost CMake module IF(DEFINED BOOST_DIR) diff --git a/nel/CMakeLists.txt b/nel/CMakeLists.txt index 1392c6dbd2..c755a28510 100644 --- a/nel/CMakeLists.txt +++ b/nel/CMakeLists.txt @@ -18,20 +18,14 @@ IF(WIN32) ENDIF() IF(WITH_3D) - IF(HUNTER_ENABLED) - HUNTER_ADD_PACKAGE(freetype) - FIND_PACKAGE(freetype CONFIG REQUIRED) - SET(FREETYPE_LIBRARIES freetype::freetype) - ELSE() - FIND_PACKAGE(FreeType) - ENDIF() #hunter + FIND_PACKAGE(FreeType) IF(WITH_NEL_CEGUI) FIND_PACKAGE(CEGUI) ENDIF() ENDIF() -IF(WITH_SOUND AND NOT HUNTER_ENABLED) +IF(WITH_SOUND) FIND_PACKAGE(Ogg) FIND_PACKAGE(Vorbis) IF(WITH_FFMPEG) diff --git a/nel/src/misc/CMakeLists.txt b/nel/src/misc/CMakeLists.txt index b08278f213..9e1694a639 100644 --- a/nel/src/misc/CMakeLists.txt +++ b/nel/src/misc/CMakeLists.txt @@ -183,21 +183,6 @@ IF(WITH_GTK) ENDIF() ENDIF() -IF(HUNTER_ENABLED) - HUNTER_ADD_PACKAGE(Jpeg) - FIND_PACKAGE(JPEG CONFIG REQUIRED) - SET(JPEG_LIBRARY JPEG::jpeg) - - HUNTER_ADD_PACKAGE(giflib) - FIND_PACKAGE(giflib CONFIG REQUIRED) - SET(GIF_LIBRARY giflib::giflib) - - HUNTER_ADD_PACKAGE(PNG) - FIND_PACKAGE(PNG CONFIG REQUIRED) - SET(PNG_LIBRARY PNG::png) - SET(PNG_LIBRARIES PNG::png) -ENDIF() - IF(JPEG_FOUND) INCLUDE_DIRECTORIES(${JPEG_INCLUDE_DIR}) ADD_DEFINITIONS(-DUSE_JPEG) diff --git a/nel/src/sound/CMakeLists.txt b/nel/src/sound/CMakeLists.txt index 8ee2277c21..01c3e03267 100644 --- a/nel/src/sound/CMakeLists.txt +++ b/nel/src/sound/CMakeLists.txt @@ -90,24 +90,6 @@ SOURCE_GROUP("user_classes" FILES ${USER_CLASSES}) NL_TARGET_LIB(nelsound ${HEADERS} ${SRC}) -IF(HUNTER_ENABLED) - HUNTER_ADD_PACKAGE(libogg) - FIND_PACKAGE(libogg CONFIG REQUIRED) - SET(OGG_LIBRARY libogg::ogg) - SET(OGG_LIBRARIES libogg::ogg) - - HUNTER_ADD_PACKAGE(vorbis) - FIND_PACKAGE(vorbis CONFIG REQUIRED) - SET(VORBIS_LIBRARY vorbis::vorbis) - SET(VORBISFILE_LIBRARY vorbis::vorbisfile) - - IF(WITH_FFMPEG) - HUNTER_ADD_PACKAGE(ffmpeg) - FIND_PACKAGE(ffmpeg CONFIG REQUIRED) - SET(FFMPEG_LIBRARIES ffmpeg::avcodec ffmpeg::avformat ffmpeg::avutil ffmpeg::swresample) - ENDIF() -ENDIF() - INCLUDE_DIRECTORIES(${VORBIS_INCLUDE_DIR}) INCLUDE_DIRECTORIES(${VORBIS_INCLUDE_DIR}/vorbis) INCLUDE_DIRECTORIES(${OGG_INCLUDE_DIR}) diff --git a/nel/src/sound/driver/openal/CMakeLists.txt b/nel/src/sound/driver/openal/CMakeLists.txt index 626168ea8c..44ace8a16c 100644 --- a/nel/src/sound/driver/openal/CMakeLists.txt +++ b/nel/src/sound/driver/openal/CMakeLists.txt @@ -26,15 +26,8 @@ SOURCE_GROUP(util FILES NL_TARGET_DRIVER(${NLDRV_AL_LIB} ${SRC}) -IF(HUNTER_ENABLED) - HUNTER_ADD_PACKAGE(OpenAL) - FIND_PACKAGE(OpenAL CONFIG REQUIRED) - SET(OPENAL_LIBRARY OpenAL::OpenAL) - ADD_DEFINITIONS(-DAL_LIBTYPE_STATIC) -ELSE() - INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) - INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}/AL) -ENDIF()# hunter +INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}/AL) TARGET_LINK_LIBRARIES(${NLDRV_AL_LIB} nelmisc nelsnd_lowlevel ${OPENAL_LIBRARY}) NL_DEFAULT_PROPS(${NLDRV_AL_LIB} "NeL, Driver, Sound: OpenAL") diff --git a/ryzom/tools/CMakeLists.txt b/ryzom/tools/CMakeLists.txt index 76f824621a..b97c9be8ed 100644 --- a/ryzom/tools/CMakeLists.txt +++ b/ryzom/tools/CMakeLists.txt @@ -1,7 +1,5 @@ -IF(NOT HUNTER_ENABLED) - FIND_PACKAGE(MySQL) -ENDIF() +FIND_PACKAGE(MySQL) IF(WITH_RYZOM_TOOLS) ADD_SUBDIRECTORY(skill_extractor)