Skip to content

Commit

Permalink
Merge pull request xbmc#23750 from fuzzard/cmake_multi_internaltarget
Browse files Browse the repository at this point in the history
[cmake] Add build targets always for multi config generators
  • Loading branch information
fuzzard authored Sep 20, 2023
2 parents c488104 + 1e232b4 commit 34bab8b
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 186 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
51 changes: 33 additions & 18 deletions cmake/modules/FindCrossGUID.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
57 changes: 37 additions & 20 deletions cmake/modules/FindFmt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

Expand Down
109 changes: 63 additions & 46 deletions cmake/modules/FindPCRE.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Loading

0 comments on commit 34bab8b

Please sign in to comment.