Merge pull request #25883 from CrystalP/fix-slowscan
[xbmc.git] / cmake / modules / FindEffects11.cmake
blobc6af7593ee9b83af75851238c0227f5c56dd96ea
1 # FindEffects11
2 # -------
3 # Finds the Effects11 library
5 # This will define the following target:
7 #   ${APP_NAME_LC}::Effects11   - The Effects11 library
9 if(NOT TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME})
10   include(cmake/scripts/common/ModuleHelpers.cmake)
12   macro(buildEffects11)
14     set(patches "${CMAKE_SOURCE_DIR}/tools/depends/target/${MODULE_LC}/01-win-debugpostfix.patch")
15     generate_patchcommand("${patches}")
17     # Effects 11 cant be built using /permissive-
18     # strip and manually set the rest of the build flags
19     string(REPLACE "/permissive-" "" EFFECTS_CXX_FLAGS ${CMAKE_CXX_FLAGS} )
21     set(CMAKE_ARGS 
22     "-DCMAKE_CXX_FLAGS=${EFFECTS_CXX_FLAGS} $<$<CONFIG:Debug>:${CMAKE_CXX_FLAGS_DEBUG}> $<$<CONFIG:Release>:${CMAKE_CXX_FLAGS_RELEASE}>"
23     "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_EXE_LINKER_FLAGS} $<$<CONFIG:Debug>:${CMAKE_EXE_LINKER_FLAGS_DEBUG}> $<$<CONFIG:Release>:${CMAKE_EXE_LINKER_FLAGS_RELEASE}>")
25     set(EFFECTS11_DEBUG_POSTFIX d)
26     set(WIN_DISABLE_PROJECT_FLAGS ON)
28     BUILD_DEP_TARGET()
30     set(EFFECTS11_VERSION ${${MODULE}_VER})
32     # Make INCLUDE_DIR match cmake config output
33     string(APPEND EFFECTS11_INCLUDE_DIR "/Effects11")
34     file(MAKE_DIRECTORY ${EFFECTS11_INCLUDE_DIR})
35   endmacro()
37   set(MODULE_LC effects11)
39   SETUP_BUILD_VARS()
41   find_package(effects11 CONFIG QUIET
42                                 HINTS ${DEPENDS_PATH}/share
43                                 ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG})
45   if(effects11_VERSION VERSION_LESS ${${MODULE}_VER})
46     buildEffects11()
47   else()
48     get_target_property(_EFFECTS_CONFIGURATIONS Microsoft::Effects11 IMPORTED_CONFIGURATIONS)
49     foreach(_effects_config IN LISTS _EFFECTS_CONFIGURATIONS)
50       # Some non standard config (eg None on Debian)
51       # Just set to RELEASE var so select_library_configurations can continue to work its magic
52       string(TOUPPER ${_effects_config} _effects_config_UPPER)
53       if((NOT ${_effects_config_UPPER} STREQUAL "RELEASE") AND
54          (NOT ${_effects_config_UPPER} STREQUAL "DEBUG"))
55         get_target_property(EFFECTS11_LIBRARY_RELEASE Microsoft::Effects11 IMPORTED_LOCATION_${_effects_config_UPPER})
56       else()
57         get_target_property(EFFECTS11_LIBRARY_${_effects_config_UPPER} Microsoft::Effects11 IMPORTED_LOCATION_${_effects_config_UPPER})
58       endif()
59     endforeach()
61     get_target_property(EFFECTS11_INCLUDE_DIR Microsoft::Effects11 INTERFACE_INCLUDE_DIRECTORIES)
62     set(EFFECTS11_VERSION ${effects11_VERSION})
63   endif()
65   include(SelectLibraryConfigurations)
66   select_library_configurations(EFFECTS11)
67   unset(EFFECTS11_LIBRARIES)
69   include(FindPackageHandleStandardArgs)
70   find_package_handle_standard_args(Effects11
71                                     REQUIRED_VARS EFFECTS11_LIBRARY EFFECTS11_INCLUDE_DIR
72                                     VERSION_VAR EFFECTS11_VERSION)
74   if(Effects11_FOUND)
75     
76     if(TARGET Microsoft::Effects11 AND NOT TARGET effects11)
77       add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS Microsoft::Effects11)
78     else()
79       add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
80       set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
81                                                                        INTERFACE_INCLUDE_DIRECTORIES "${EFFECTS11_INCLUDE_DIR}")
83       if(EFFECTS11_LIBRARY_RELEASE)
84         set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
85                                                                          IMPORTED_CONFIGURATIONS RELEASE
86                                                                          IMPORTED_LOCATION_RELEASE "${EFFECTS11_LIBRARY_RELEASE}")
87       endif()
88       if(EFFECTS11_LIBRARY_DEBUG)
89         set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
90                                                                          IMPORTED_LOCATION_DEBUG "${EFFECTS11_LIBRARY_DEBUG}")
91         set_property(TARGET ${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} APPEND PROPERTY
92                                                                               IMPORTED_CONFIGURATIONS DEBUG)
93       endif()
94     endif()
96     if(TARGET effects11)
97       add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} effects11)
98     endif()
100     # Add internal build target when a Multi Config Generator is used
101     # We cant add a dependency based off a generator expression for targeted build types,
102     # https://gitlab.kitware.com/cmake/cmake/-/issues/19467
103     # therefore if the find heuristics only find the library, we add the internal build
104     # target to the project to allow user to manually trigger for any build type they need
105     # in case only a specific build type is actually available (eg Release found, Debug Required)
106     # This is mainly targeted for windows who required different runtime libs for different
107     # types, and they arent compatible
108     if(_multiconfig_generator)
109       if(NOT TARGET effects11)
110         buildEffects11()
111         set_target_properties(effects11 PROPERTIES EXCLUDE_FROM_ALL TRUE)
112       endif()
113       add_dependencies(build_internal_depends effects11)
114     endif()
115   else()
116     if(Effects11_FIND_REQUIRED)
117       message(FATAL_ERROR "Could NOT find or build Effects11 library.")
118     endif()
119   endif()
120 endif()