Skip to content

Commit

Permalink
extract hunter dependencies into separate file remove implicit depend…
Browse files Browse the repository at this point in the history
…ency, make caching easier and enable usage of other package manager
  • Loading branch information
zerotacg committed Jul 12, 2024
1 parent 6491460 commit 929e15f
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 188 deletions.
140 changes: 49 additions & 91 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion CMakeModules/FindHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion CMakeModules/FindLuabind.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions CMakeModules/HunterDependencies.cmake
Original file line number Diff line number Diff line change
@@ -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)
43 changes: 1 addition & 42 deletions CMakeModules/nel.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -211,7 +175,6 @@ ELSE()
ENDIF()

ENDIF()
ENDIF() #hunter
ENDMACRO(NL_ADD_STATIC_SND_DRIVERS)

###
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 2 additions & 8 deletions nel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 0 additions & 15 deletions nel/src/misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions nel/src/sound/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
11 changes: 2 additions & 9 deletions nel/src/sound/driver/openal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading

0 comments on commit 929e15f

Please sign in to comment.