1cmake_minimum_required(VERSION 3.15) 2 3set(tinyxml2_known_comps static shared) 4set(tinyxml2_comp_static NO) 5set(tinyxml2_comp_shared NO) 6foreach (tinyxml2_comp IN LISTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS) 7 if (tinyxml2_comp IN_LIST tinyxml2_known_comps) 8 set(tinyxml2_comp_${tinyxml2_comp} YES) 9 else () 10 set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE 11 "tinyxml2 does not recognize component `${tinyxml2_comp}`.") 12 set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) 13 return() 14 endif () 15endforeach () 16 17if (tinyxml2_comp_static AND tinyxml2_comp_shared) 18 set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE 19 "tinyxml2 `static` and `shared` components are mutually exclusive.") 20 set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) 21 return() 22endif () 23 24set(tinyxml2_static_targets "${CMAKE_CURRENT_LIST_DIR}/tinyxml2-static-targets.cmake") 25set(tinyxml2_shared_targets "${CMAKE_CURRENT_LIST_DIR}/tinyxml2-shared-targets.cmake") 26 27macro(tinyxml2_load_targets type) 28 if (NOT EXISTS "${tinyxml2_${type}_targets}") 29 set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE 30 "tinyxml2 `${type}` libraries were requested but not found.") 31 set(${CMAKE_FIND_PACKAGE_NAME}_FOUND FALSE) 32 return() 33 endif () 34 include("${tinyxml2_${type}_targets}") 35endmacro() 36 37if (tinyxml2_comp_static) 38 tinyxml2_load_targets(static) 39elseif (tinyxml2_comp_shared) 40 tinyxml2_load_targets(shared) 41elseif (DEFINED tinyxml2_SHARED_LIBS AND tinyxml2_SHARED_LIBS) 42 tinyxml2_load_targets(shared) 43elseif (DEFINED tinyxml2_SHARED_LIBS AND NOT tinyxml2_SHARED_LIBS) 44 tinyxml2_load_targets(static) 45elseif (BUILD_SHARED_LIBS) 46 if (EXISTS "${tinyxml2_shared_targets}") 47 tinyxml2_load_targets(shared) 48 else () 49 tinyxml2_load_targets(static) 50 endif () 51else () 52 if (EXISTS "${tinyxml2_static_targets}") 53 tinyxml2_load_targets(static) 54 else () 55 tinyxml2_load_targets(shared) 56 endif () 57endif () 58