3 # Finds the CrossGUID library
5 # This will define the following target:
7 # ${APP_NAME_LC}::CrossGUID - The CrossGUID library
10 include(cmake/scripts/common/ModuleHelpers.cmake)
12 set(MODULE_LC crossguid)
16 set(CROSSGUID_VERSION ${${MODULE}_VER})
17 set(CROSSGUID_DEBUG_POSTFIX "-dgb")
19 set(_crossguid_definitions HAVE_NEW_CROSSGUID)
22 list(APPEND _crossguid_definitions GUID_ANDROID)
25 set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/001-fix-unused-function.patch"
26 "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/002-disable-Wall-error.patch"
27 "${CMAKE_SOURCE_DIR}/tools/depends/target/crossguid/003-add-cstdint-include.patch")
29 generate_patchcommand("${patches}")
31 set(CMAKE_ARGS -DCROSSGUID_TESTS=OFF
37 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
38 if(ENABLE_INTERNAL_CROSSGUID)
41 find_package(PkgConfig)
42 # Do not use pkgconfig on windows
43 if(PKG_CONFIG_FOUND AND NOT WIN32)
44 pkg_check_modules(PC_CROSSGUID crossguid QUIET)
45 set(CROSSGUID_VERSION ${PC_CROSSGUID_VERSION})
48 find_path(CROSSGUID_INCLUDE_DIR NAMES crossguid/guid.hpp guid.h
49 HINTS ${DEPENDS_PATH}/include ${PC_CROSSGUID_INCLUDEDIR}
50 ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
51 find_library(CROSSGUID_LIBRARY_RELEASE NAMES crossguid
52 HINTS ${DEPENDS_PATH}/lib ${PC_CROSSGUID_LIBDIR}
53 ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
54 find_library(CROSSGUID_LIBRARY_DEBUG NAMES crossguidd crossguid-dgb
55 HINTS ${DEPENDS_PATH}/lib ${PC_CROSSGUID_LIBDIR}
56 ${${CORE_PLATFORM_LC}_SEARCH_CONFIG})
58 # NEW_CROSSGUID >= 0.2.0 release
59 if(EXISTS "${CROSSGUID_INCLUDE_DIR}/crossguid/guid.hpp")
60 list(APPEND _crossguid_definitions HAVE_NEW_CROSSGUID)
64 # Select relevant lib build type (ie CROSSGUID_LIBRARY_RELEASE or CROSSGUID_LIBRARY_DEBUG)
65 include(SelectLibraryConfigurations)
66 select_library_configurations(CROSSGUID)
67 unset(CROSSGUID_LIBRARIES)
69 include(FindPackageHandleStandardArgs)
70 find_package_handle_standard_args(CrossGUID
71 REQUIRED_VARS CROSSGUID_LIBRARY CROSSGUID_INCLUDE_DIR
72 VERSION_VAR CROSSGUID_VERSION)
75 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
76 if(CROSSGUID_LIBRARY_RELEASE)
77 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
78 IMPORTED_CONFIGURATIONS RELEASE
79 IMPORTED_LOCATION_RELEASE "${CROSSGUID_LIBRARY_RELEASE}")
81 if(CROSSGUID_LIBRARY_DEBUG)
82 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
83 IMPORTED_LOCATION_DEBUG "${CROSSGUID_LIBRARY_DEBUG}")
84 set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
85 IMPORTED_CONFIGURATIONS DEBUG)
87 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
88 INTERFACE_INCLUDE_DIRECTORIES "${CROSSGUID_INCLUDE_DIRS}"
89 INTERFACE_COMPILE_DEFINITIONS "${_crossguid_definitions}")
91 if(UNIX AND NOT (APPLE OR ANDROID))
92 # Suppress mismatch warning, see https://cmake.org/cmake/help/latest/module/FindPackageHandleStandardArgs.html
93 set(FPHSA_NAME_MISMATCHED 1)
94 find_package(UUID REQUIRED)
95 unset(FPHSA_NAME_MISMATCHED)
98 add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UUID::UUID)
99 target_link_libraries(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} INTERFACE UUID::UUID)
104 add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} crossguid)
107 # Add internal build target when a Multi Config Generator is used
108 # We cant add a dependency based off a generator expression for targeted build types,
109 # https://gitlab.kitware.com/cmake/cmake/-/issues/19467
110 # therefore if the find heuristics only find the library, we add the internal build
111 # target to the project to allow user to manually trigger for any build type they need
112 # in case only a specific build type is actually available (eg Release found, Debug Required)
113 # This is mainly targeted for windows who required different runtime libs for different
114 # types, and they arent compatible
115 if(_multiconfig_generator)
116 if(NOT TARGET crossguid)
118 set_target_properties(crossguid PROPERTIES EXCLUDE_FROM_ALL TRUE)
120 add_dependencies(build_internal_depends crossguid)
123 if(CrossGUID_FIND_REQUIRED)
124 message(FATAL_ERROR "CrossGUID libraries were not found. You may want to use -DENABLE_INTERNAL_CROSSGUID=ON")