diff --git a/CMakeLists.txt b/CMakeLists.txt index defd8e77692a3..2d5febb16d5c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,9 @@ if(DEPENDS_DIR) list(APPEND CMAKE_PREFIX_PATH ${DEPENDS_DIR}) endif() +# Variable to indicate if the project is targeting a Multi Config Generator (VS/Xcode primarily) +get_property(_multiconfig_generator GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + # Set CORE_BUILD_DIR set(CORE_BUILD_DIR build) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/cmake/modules/FindCrossGUID.cmake b/cmake/modules/FindCrossGUID.cmake index f7ae5aff1e044..9f98b8a2c564d 100644 --- a/cmake/modules/FindCrossGUID.cmake +++ b/cmake/modules/FindCrossGUID.cmake @@ -6,34 +6,37 @@ # # CrossGUID::CrossGUID - The CrossGUID library -if(NOT TARGET CrossGUID::CrossGUID) - if(ENABLE_INTERNAL_CROSSGUID) - include(cmake/scripts/common/ModuleHelpers.cmake) +macro(buildCrossGUID) + include(cmake/scripts/common/ModuleHelpers.cmake) - set(MODULE_LC crossguid) + set(MODULE_LC crossguid) - SETUP_BUILD_VARS() + SETUP_BUILD_VARS() - set(CROSSGUID_VERSION ${${MODULE}_VER}) - set(CROSSGUID_DEBUG_POSTFIX "-dgb") + set(CROSSGUID_VERSION ${${MODULE}_VER}) + set(CROSSGUID_DEBUG_POSTFIX "-dgb") - set(_crossguid_definitions HAVE_NEW_CROSSGUID) + set(_crossguid_definitions HAVE_NEW_CROSSGUID) - if(ANDROID) - list(APPEND _crossguid_definitions GUID_ANDROID) - endif() + if(ANDROID) + list(APPEND _crossguid_definitions GUID_ANDROID) + endif() - set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/001-fix-unused-function.patch" - "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/002-disable-Wall-error.patch" - "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/003-add-cstdint-include.patch") + set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/001-fix-unused-function.patch" + "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/002-disable-Wall-error.patch" + "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/003-add-cstdint-include.patch") - generate_patchcommand("${patches}") + generate_patchcommand("${patches}") - set(CMAKE_ARGS -DCROSSGUID_TESTS=OFF - -DDISABLE_WALL=ON) + set(CMAKE_ARGS -DCROSSGUID_TESTS=OFF + -DDISABLE_WALL=ON) - BUILD_DEP_TARGET() + BUILD_DEP_TARGET() +endmacro() +if(NOT TARGET CrossGUID::CrossGUID) + if(ENABLE_INTERNAL_CROSSGUID) + buildCrossGUID() else() if(PKG_CONFIG_FOUND) pkg_check_modules(PC_CROSSGUID crossguid QUIET) @@ -91,6 +94,18 @@ if(NOT TARGET CrossGUID::CrossGUID) if(TARGET crossguid) add_dependencies(CrossGUID::CrossGUID crossguid) + else() + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + buildCrossGUID() + endif() endif() set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP CrossGUID::CrossGUID) diff --git a/cmake/modules/FindFmt.cmake b/cmake/modules/FindFmt.cmake index a403a03ce540d..a6b844532c6e6 100644 --- a/cmake/modules/FindFmt.cmake +++ b/cmake/modules/FindFmt.cmake @@ -6,6 +6,30 @@ # # fmt::fmt - The Fmt library +macro(buildFmt) + if(APPLE) + set(EXTRA_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}") + endif() + + set(FMT_VERSION ${${MODULE}_VER}) + # fmt debug uses postfix d for all platforms + set(FMT_DEBUG_POSTFIX d) + + if(WIN32 OR WINDOWS_STORE) + set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-windows-pdb-symbol-gen.patch") + generate_patchcommand("${patches}") + endif() + + set(CMAKE_ARGS -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DFMT_DOC=OFF + -DFMT_TEST=OFF + -DFMT_INSTALL=ON + "${EXTRA_ARGS}") + + BUILD_DEP_TARGET() +endmacro() + define_property(TARGET PROPERTY LIB_BUILD BRIEF_DOCS "This target will be compiling the library" FULL_DOCS "This target will be compiling the library") @@ -45,27 +69,8 @@ if(NOT TARGET fmt::fmt OR Fmt_FIND_REQUIRED) # Set FORCE_BUILD to enable fmt::fmt property that build will occur set(FORCE_BUILD ON) - if(APPLE) - set(EXTRA_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}") - endif() - - set(FMT_VERSION ${${MODULE}_VER}) - # fmt debug uses postfix d for all platforms - set(FMT_DEBUG_POSTFIX d) - - if(WIN32 OR WINDOWS_STORE) - set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-windows-pdb-symbol-gen.patch") - generate_patchcommand("${patches}") - endif() + buildFmt() - set(CMAKE_ARGS -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DFMT_DOC=OFF - -DFMT_TEST=OFF - -DFMT_INSTALL=ON - "${EXTRA_ARGS}") - - BUILD_DEP_TARGET() else() if(NOT TARGET fmt::fmt) set(FMT_PKGCONFIG_CHECK ON) @@ -115,6 +120,18 @@ if(NOT TARGET fmt::fmt OR Fmt_FIND_REQUIRED) if(TARGET fmt) add_dependencies(fmt::fmt fmt) + else() + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + buildFmt() + endif() endif() endif() diff --git a/cmake/modules/FindPCRE.cmake b/cmake/modules/FindPCRE.cmake index 0b7e0c3203754..e650802184c5e 100644 --- a/cmake/modules/FindPCRE.cmake +++ b/cmake/modules/FindPCRE.cmake @@ -8,6 +8,55 @@ # PCRE::PCRECPP - The PCRECPP library # PCRE::PCRE - The PCRE library +macro(buildPCRE) + set(PCRE_VERSION ${${MODULE}_VER}) + set(PCRE_DEBUG_POSTFIX d) + + set(patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-all-cmakeconfig.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/002-all-enable_docs_pc.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/003-all-postfix.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/004-win-pdb.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/jit_aarch64.patch") + + if(CORE_SYSTEM_NAME STREQUAL darwin_embedded) + list(APPEND patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/tvos-bitcode-fix.patch" + "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/ios-clear_cache.patch") + endif() + + generate_patchcommand("${patches}") + + set(CMAKE_ARGS -DPCRE_NEWLINE=ANYCRLF + -DPCRE_NO_RECURSE=ON + -DPCRE_MATCH_LIMIT_RECURSION=1500 + -DPCRE_SUPPORT_JIT=ON + -DPCRE_SUPPORT_PCREGREP_JIT=ON + -DPCRE_SUPPORT_UTF=ON + -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON + -DPCRE_SUPPORT_LIBZ=OFF + -DPCRE_SUPPORT_LIBBZ2=OFF + -DPCRE_BUILD_PCREGREP=OFF + -DPCRE_BUILD_TESTS=OFF) + + if(WIN32 OR WINDOWS_STORE) + list(APPEND CMAKE_ARGS -DINSTALL_MSVC_PDB=ON) + elseif(CORE_SYSTEM_NAME STREQUAL android) + # CMake CheckFunctionExists incorrectly detects strtoq for android + list(APPEND CMAKE_ARGS -DHAVE_STRTOQ=0) + endif() + + # populate PCRECPP lib without a separate module + if(NOT CORE_SYSTEM_NAME MATCHES windows) + # Non windows platforms have a lib prefix for the lib artifact + set(_libprefix "lib") + endif() + # regex used to get platform extension (eg lib for windows, .a for unix) + string(REGEX REPLACE "^.*\\." "" _LIBEXT ${${MODULE}_BYPRODUCT}) + set(PCRECPP_LIBRARY_DEBUG ${DEP_LOCATION}/lib/${_libprefix}pcrecpp${${MODULE}_DEBUG_POSTFIX}.${_LIBEXT}) + set(PCRECPP_LIBRARY_RELEASE ${DEP_LOCATION}/lib/${_libprefix}pcrecpp.${_LIBEXT}) + + BUILD_DEP_TARGET() +endmacro() + if(NOT PCRE::pcre) include(cmake/scripts/common/ModuleHelpers.cmake) @@ -24,52 +73,7 @@ if(NOT PCRE::pcre) if((PCRE_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_PCRE) OR ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_PCRE)) - set(PCRE_VERSION ${${MODULE}_VER}) - set(PCRE_DEBUG_POSTFIX d) - - set(patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-all-cmakeconfig.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/002-all-enable_docs_pc.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/003-all-postfix.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/004-win-pdb.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/jit_aarch64.patch") - - if(CORE_SYSTEM_NAME STREQUAL darwin_embedded) - list(APPEND patches "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/tvos-bitcode-fix.patch" - "${CORE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/ios-clear_cache.patch") - endif() - - generate_patchcommand("${patches}") - - set(CMAKE_ARGS -DPCRE_NEWLINE=ANYCRLF - -DPCRE_NO_RECURSE=ON - -DPCRE_MATCH_LIMIT_RECURSION=1500 - -DPCRE_SUPPORT_JIT=ON - -DPCRE_SUPPORT_PCREGREP_JIT=ON - -DPCRE_SUPPORT_UTF=ON - -DPCRE_SUPPORT_UNICODE_PROPERTIES=ON - -DPCRE_SUPPORT_LIBZ=OFF - -DPCRE_SUPPORT_LIBBZ2=OFF - -DPCRE_BUILD_PCREGREP=OFF - -DPCRE_BUILD_TESTS=OFF) - - if(WIN32 OR WINDOWS_STORE) - list(APPEND CMAKE_ARGS -DINSTALL_MSVC_PDB=ON) - elseif(CORE_SYSTEM_NAME STREQUAL android) - # CMake CheckFunctionExists incorrectly detects strtoq for android - list(APPEND CMAKE_ARGS -DHAVE_STRTOQ=0) - endif() - - # populate PCRECPP lib without a separate module - if(NOT CORE_SYSTEM_NAME MATCHES windows) - # Non windows platforms have a lib prefix for the lib artifact - set(_libprefix "lib") - endif() - # regex used to get platform extension (eg lib for windows, .a for unix) - string(REGEX REPLACE "^.*\\." "" _LIBEXT ${${MODULE}_BYPRODUCT}) - set(PCRECPP_LIBRARY_DEBUG ${DEP_LOCATION}/lib/${_libprefix}pcrecpp${${MODULE}_DEBUG_POSTFIX}.${_LIBEXT}) - set(PCRECPP_LIBRARY_RELEASE ${DEP_LOCATION}/lib/${_libprefix}pcrecpp.${_LIBEXT}) - - BUILD_DEP_TARGET() + buildPCRE() else() if(NOT TARGET PCRE::pcre) @@ -192,9 +196,22 @@ if(NOT PCRE::pcre) if(TARGET pcre) add_dependencies(PCRE::pcre pcre) add_dependencies(PCRE::pcrecpp pcre) + else() + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + buildPCRE() + endif() endif() set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP PCRE::pcre) set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP PCRE::pcrecpp) + endif() endif() diff --git a/cmake/modules/FindSpdlog.cmake b/cmake/modules/FindSpdlog.cmake index f8e8e998b91b6..9ef855cbbe80b 100644 --- a/cmake/modules/FindSpdlog.cmake +++ b/cmake/modules/FindSpdlog.cmake @@ -6,6 +6,45 @@ # # spdlog::spdlog - The Spdlog library +macro(buildSpdlog) + if(APPLE) + set(EXTRA_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}") + endif() + + if(WIN32 OR WINDOWS_STORE) + set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-windows-pdb-symbol-gen.patch") + generate_patchcommand("${patches}") + + set(EXTRA_ARGS -DSPDLOG_WCHAR_SUPPORT=ON + -DSPDLOG_WCHAR_FILENAMES=ON) + + set(EXTRA_DEFINITIONS SPDLOG_WCHAR_FILENAMES + SPDLOG_WCHAR_TO_UTF8_SUPPORT) + endif() + + set(SPDLOG_VERSION ${${MODULE}_VER}) + # spdlog debug uses postfix d for all platforms + set(SPDLOG_DEBUG_POSTFIX d) + + set(CMAKE_ARGS -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -DSPDLOG_BUILD_EXAMPLE=OFF + -DSPDLOG_BUILD_TESTS=OFF + -DSPDLOG_BUILD_BENCH=OFF + -DSPDLOG_FMT_EXTERNAL=ON + ${EXTRA_ARGS}) + + # Set definitions that will be set in the built cmake config file + # We dont import the config file if we build internal (chicken/egg scenario) + set(_spdlog_definitions SPDLOG_COMPILED_LIB + SPDLOG_FMT_EXTERNAL + ${EXTRA_DEFINITIONS}) + + BUILD_DEP_TARGET() + + add_dependencies(${MODULE_LC} fmt::fmt) +endmacro() + if(NOT TARGET spdlog::spdlog) include(cmake/scripts/common/ModuleHelpers.cmake) @@ -33,42 +72,7 @@ if(NOT TARGET spdlog::spdlog) ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_SPDLOG) OR LIB_FORCE_REBUILD) - if(APPLE) - set(EXTRA_ARGS "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}") - endif() - - if(WIN32 OR WINDOWS_STORE) - set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-windows-pdb-symbol-gen.patch") - generate_patchcommand("${patches}") - - set(EXTRA_ARGS -DSPDLOG_WCHAR_SUPPORT=ON - -DSPDLOG_WCHAR_FILENAMES=ON) - - set(EXTRA_DEFINITIONS SPDLOG_WCHAR_FILENAMES - SPDLOG_WCHAR_TO_UTF8_SUPPORT) - endif() - - set(SPDLOG_VERSION ${${MODULE}_VER}) - # spdlog debug uses postfix d for all platforms - set(SPDLOG_DEBUG_POSTFIX d) - - set(CMAKE_ARGS -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -DSPDLOG_BUILD_EXAMPLE=OFF - -DSPDLOG_BUILD_TESTS=OFF - -DSPDLOG_BUILD_BENCH=OFF - -DSPDLOG_FMT_EXTERNAL=ON - ${EXTRA_ARGS}) - - # Set definitions that will be set in the built cmake config file - # We dont import the config file if we build internal (chicken/egg scenario) - set(_spdlog_definitions SPDLOG_COMPILED_LIB - SPDLOG_FMT_EXTERNAL - ${EXTRA_DEFINITIONS}) - - BUILD_DEP_TARGET() - - add_dependencies(${MODULE_LC} fmt::fmt) + buildSpdlog() else() if(NOT TARGET spdlog::spdlog) find_package(PkgConfig) @@ -160,6 +164,18 @@ if(NOT TARGET spdlog::spdlog) if(TARGET spdlog) add_dependencies(spdlog::spdlog spdlog) + else() + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + buildSpdlog() + endif() endif() endif() endif() diff --git a/cmake/modules/FindTagLib.cmake b/cmake/modules/FindTagLib.cmake index e455a58cb5315..311d9e7ef8d58 100644 --- a/cmake/modules/FindTagLib.cmake +++ b/cmake/modules/FindTagLib.cmake @@ -8,53 +8,55 @@ # TagLib::TagLib - The TagLib library # -if(NOT TARGET TagLib::TagLib) - if(ENABLE_INTERNAL_TAGLIB) - - # Suppress mismatch warning, see https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html - set(FPHSA_NAME_MISMATCHED 1) - - # Darwin systems use a system tbd that isnt found as a static lib - # Other platforms when using ENABLE_INTERNAL_TAGLIB, we want the static lib - if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") - # Requires cmake 3.24 for ZLIB_USE_STATIC_LIBS to actually do something - set(ZLIB_USE_STATIC_LIBS ON) - endif() - find_package(ZLIB REQUIRED) - unset(FPHSA_NAME_MISMATCHED) +macro(buildTagLib) + # Suppress mismatch warning, see https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html + set(FPHSA_NAME_MISMATCHED 1) + + # Darwin systems use a system tbd that isnt found as a static lib + # Other platforms when using ENABLE_INTERNAL_TAGLIB, we want the static lib + if(NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin") + # Requires cmake 3.24 for ZLIB_USE_STATIC_LIBS to actually do something + set(ZLIB_USE_STATIC_LIBS ON) + endif() + find_package(ZLIB REQUIRED) + unset(FPHSA_NAME_MISMATCHED) - include(cmake/scripts/common/ModuleHelpers.cmake) + include(cmake/scripts/common/ModuleHelpers.cmake) - set(MODULE_LC taglib) + set(MODULE_LC taglib) - SETUP_BUILD_VARS() + SETUP_BUILD_VARS() - set(TAGLIB_VERSION ${${MODULE}_VER}) + set(TAGLIB_VERSION ${${MODULE}_VER}) - if(WIN32 OR WINDOWS_STORE) - set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-cmake-pdb-debug.patch") - generate_patchcommand("${patches}") + if(WIN32 OR WINDOWS_STORE) + set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/001-cmake-pdb-debug.patch") + generate_patchcommand("${patches}") - if(WINDOWS_STORE) - set(EXTRA_ARGS -DPLATFORM_WINRT=ON) - endif() + if(WINDOWS_STORE) + set(EXTRA_ARGS -DPLATFORM_WINRT=ON) endif() + endif() - # Debug postfix only used for windows - if(WIN32 OR WINDOWS_STORE) - set(TAGLIB_DEBUG_POSTFIX "d") - endif() + # Debug postfix only used for windows + if(WIN32 OR WINDOWS_STORE) + set(TAGLIB_DEBUG_POSTFIX "d") + endif() - set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF - -DBUILD_EXAMPLES=OFF - -DBUILD_TESTING=OFF - -DBUILD_BINDINGS=OFF - ${EXTRA_ARGS}) + set(CMAKE_ARGS -DBUILD_SHARED_LIBS=OFF + -DBUILD_EXAMPLES=OFF + -DBUILD_TESTING=OFF + -DBUILD_BINDINGS=OFF + ${EXTRA_ARGS}) - BUILD_DEP_TARGET() + BUILD_DEP_TARGET() - add_dependencies(${MODULE_LC} ZLIB::ZLIB) + add_dependencies(${MODULE_LC} ZLIB::ZLIB) +endmacro() +if(NOT TARGET TagLib::TagLib) + if(ENABLE_INTERNAL_TAGLIB) + buildTagLib() else() if(PKG_CONFIG_FOUND) @@ -110,6 +112,18 @@ if(NOT TARGET TagLib::TagLib) if(TARGET taglib) add_dependencies(TagLib::TagLib taglib) + else() + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + buildTagLib() + endif() endif() set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP TagLib::TagLib) diff --git a/cmake/modules/FindTinyXML2.cmake b/cmake/modules/FindTinyXML2.cmake index ba11a47a3f604..709eeefabdf16 100644 --- a/cmake/modules/FindTinyXML2.cmake +++ b/cmake/modules/FindTinyXML2.cmake @@ -7,6 +7,40 @@ # # tinyxml2::tinyxml2 - The TinyXML2 library +macro(buildTinyXML2) + set(TINYXML2_VERSION ${${MODULE}_VER}) + set(TINYXML2_DEBUG_POSTFIX d) + + find_package(Patch MODULE REQUIRED) + + if(UNIX) + # ancient patch (Apple/freebsd) fails to patch tinyxml2 CMakeLists.txt file due to it being crlf encoded + # Strip crlf before applying patches. + # Freebsd fails even harder and requires both .patch and CMakeLists.txt to be crlf stripped + # possibly add requirement for freebsd on gpatch? Wouldnt need to copy/strip the patch file then + set(PATCH_COMMAND sed -ie s|\\r\$|| ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/CMakeLists.txt + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/001-debug-pdb.patch ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch + COMMAND sed -ie s|\\r\$|| ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch + COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch) + else() + set(PATCH_COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/001-debug-pdb.patch) + endif() + + if(CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR STREQUAL Xcode) + # Multiconfig generators fail due to file(GENERATE tinyxml.pc) command. + # This patch makes it generate a distinct named pc file for each build type and rename + # pc file on install + list(APPEND PATCH_COMMAND COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/002-multiconfig-gen-pkgconfig.patch) + endif() + + set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR} + -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} + -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} + -Dtinyxml2_BUILD_TESTING=OFF) + + BUILD_DEP_TARGET() +endmacro() + if(NOT TARGET tinyxml2::tinyxml2) include(cmake/scripts/common/ModuleHelpers.cmake) @@ -23,37 +57,7 @@ if(NOT TARGET tinyxml2::tinyxml2) if((TINYXML2_VERSION VERSION_LESS ${${MODULE}_VER} AND ENABLE_INTERNAL_TINYXML2) OR ((CORE_SYSTEM_NAME STREQUAL linux OR CORE_SYSTEM_NAME STREQUAL freebsd) AND ENABLE_INTERNAL_TINYXML2)) - set(TINYXML2_VERSION ${${MODULE}_VER}) - set(TINYXML2_DEBUG_POSTFIX d) - - find_package(Patch MODULE REQUIRED) - - if(UNIX) - # ancient patch (Apple/freebsd) fails to patch tinyxml2 CMakeLists.txt file due to it being crlf encoded - # Strip crlf before applying patches. - # Freebsd fails even harder and requires both .patch and CMakeLists.txt to be crlf stripped - # possibly add requirement for freebsd on gpatch? Wouldnt need to copy/strip the patch file then - set(PATCH_COMMAND sed -ie s|\\r\$|| ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/CMakeLists.txt - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/001-debug-pdb.patch ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch - COMMAND sed -ie s|\\r\$|| ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch - COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR}/${MODULE_LC}/src/${MODULE_LC}/001-debug-pdb.patch) - else() - set(PATCH_COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/001-debug-pdb.patch) - endif() - - if(CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR STREQUAL Xcode) - # Multiconfig generators fail due to file(GENERATE tinyxml.pc) command. - # This patch makes it generate a distinct named pc file for each build type and rename - # pc file on install - list(APPEND PATCH_COMMAND COMMAND ${PATCH_EXECUTABLE} -p1 -i ${CMAKE_SOURCE_DIR}/tools/depends/target/tinyxml2/002-multiconfig-gen-pkgconfig.patch) - endif() - - set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/${CORE_BUILD_DIR} - -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} - -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} - -Dtinyxml2_BUILD_TESTING=OFF) - - BUILD_DEP_TARGET() + buildTinyXML2() else() # This is the fallback case where linux distro's dont ship cmake config files # use the old find_library way. Only do this if we didnt find a cmake config @@ -130,6 +134,18 @@ if(NOT TARGET tinyxml2::tinyxml2) if(TARGET tinyxml2) add_dependencies(tinyxml2::tinyxml2 tinyxml2) + else() + # Add internal build target when a Multi Config Generator is used + # We cant add a dependency based off a generator expression for targeted build types, + # https://gitlab.kitware.com/cmake/cmake/-/issues/19467 + # therefore if the find heuristics only find the library, we add the internal build + # target to the project to allow user to manually trigger for any build type they need + # in case only a specific build type is actually available (eg Release found, Debug Required) + # This is mainly targeted for windows who required different runtime libs for different + # types, and they arent compatible + if(_multiconfig_generator) + buildTinyXML2() + endif() endif() endif()