|
1 | 1 | include_guard(GLOBAL) |
2 | 2 |
|
| 3 | +function(openmeta_expat_library_is_static out_var library_path) |
| 4 | + set(_openmeta_is_static OFF) |
| 5 | + |
| 6 | + if(NOT library_path |
| 7 | + OR library_path STREQUAL "optimized" |
| 8 | + OR library_path STREQUAL "debug" |
| 9 | + OR library_path STREQUAL "general") |
| 10 | + set(${out_var} "${_openmeta_is_static}" PARENT_SCOPE) |
| 11 | + return() |
| 12 | + endif() |
| 13 | + |
| 14 | + get_filename_component(_openmeta_library_name "${library_path}" NAME) |
| 15 | + string(TOLOWER "${_openmeta_library_name}" _openmeta_library_name_lower) |
| 16 | + |
| 17 | + if(_openmeta_library_name_lower MATCHES "\\.a$") |
| 18 | + set(_openmeta_is_static ON) |
| 19 | + elseif(WIN32 |
| 20 | + AND _openmeta_library_name_lower MATCHES "^(lib)?expat(w)?d?mt\\.lib$") |
| 21 | + set(_openmeta_is_static ON) |
| 22 | + endif() |
| 23 | + |
| 24 | + set(${out_var} "${_openmeta_is_static}" PARENT_SCOPE) |
| 25 | +endfunction() |
| 26 | + |
| 27 | +function(openmeta_expat_needs_xml_static out_var) |
| 28 | + set(_openmeta_needs_xml_static OFF) |
| 29 | + |
| 30 | + if(NOT OPENMETA_EXPAT_FOUND) |
| 31 | + set(${out_var} "${_openmeta_needs_xml_static}" PARENT_SCOPE) |
| 32 | + return() |
| 33 | + endif() |
| 34 | + |
| 35 | + if(TARGET EXPAT::EXPAT) |
| 36 | + get_target_property(_openmeta_expat_defs EXPAT::EXPAT |
| 37 | + INTERFACE_COMPILE_DEFINITIONS) |
| 38 | + if(_openmeta_expat_defs) |
| 39 | + list(FIND _openmeta_expat_defs "XML_STATIC" |
| 40 | + _openmeta_xml_static_index) |
| 41 | + if(NOT _openmeta_xml_static_index EQUAL -1) |
| 42 | + set(_openmeta_needs_xml_static ON) |
| 43 | + endif() |
| 44 | + endif() |
| 45 | + endif() |
| 46 | + |
| 47 | + if(NOT _openmeta_needs_xml_static) |
| 48 | + set(_openmeta_expat_candidates "") |
| 49 | + foreach(_openmeta_expat_var |
| 50 | + IN ITEMS EXPAT_LIBRARY_DEBUG EXPAT_LIBRARY_RELEASE EXPAT_LIBRARY) |
| 51 | + if(DEFINED ${_openmeta_expat_var} AND NOT "${${_openmeta_expat_var}}" STREQUAL "") |
| 52 | + list(APPEND _openmeta_expat_candidates "${${_openmeta_expat_var}}") |
| 53 | + endif() |
| 54 | + endforeach() |
| 55 | + if(DEFINED EXPAT_LIBRARIES) |
| 56 | + list(APPEND _openmeta_expat_candidates ${EXPAT_LIBRARIES}) |
| 57 | + endif() |
| 58 | + |
| 59 | + foreach(_openmeta_expat_candidate IN LISTS _openmeta_expat_candidates) |
| 60 | + openmeta_expat_library_is_static(_openmeta_expat_candidate_is_static |
| 61 | + "${_openmeta_expat_candidate}") |
| 62 | + if(_openmeta_expat_candidate_is_static) |
| 63 | + set(_openmeta_needs_xml_static ON) |
| 64 | + break() |
| 65 | + endif() |
| 66 | + endforeach() |
| 67 | + endif() |
| 68 | + |
| 69 | + set(${out_var} "${_openmeta_needs_xml_static}" PARENT_SCOPE) |
| 70 | +endfunction() |
| 71 | + |
| 72 | +function(openmeta_apply_expat_dep target_name visibility) |
| 73 | + if(NOT OPENMETA_EXPAT_FOUND) |
| 74 | + return() |
| 75 | + endif() |
| 76 | + |
| 77 | + if(TARGET EXPAT::EXPAT) |
| 78 | + target_link_libraries(${target_name} ${visibility} EXPAT::EXPAT) |
| 79 | + else() |
| 80 | + target_include_directories(${target_name} ${visibility} |
| 81 | + "${EXPAT_INCLUDE_DIRS}") |
| 82 | + target_link_libraries(${target_name} ${visibility} "${EXPAT_LIBRARIES}") |
| 83 | + endif() |
| 84 | + |
| 85 | + target_compile_definitions(${target_name} ${visibility} OPENMETA_HAS_EXPAT=1) |
| 86 | + |
| 87 | + openmeta_expat_needs_xml_static(_openmeta_needs_xml_static) |
| 88 | + if(_openmeta_needs_xml_static) |
| 89 | + target_compile_definitions(${target_name} ${visibility} XML_STATIC) |
| 90 | + endif() |
| 91 | +endfunction() |
| 92 | + |
3 | 93 | function(openmeta_add_googletest) |
4 | 94 | if(TARGET gtest_main) |
5 | 95 | set(OPENMETA_GTEST_PROVIDER "already-present" PARENT_SCOPE) |
@@ -105,13 +195,7 @@ function(openmeta_apply_core_deps target_name) |
105 | 195 | endif() |
106 | 196 |
|
107 | 197 | if(OPENMETA_EXPAT_FOUND) |
108 | | - if(TARGET EXPAT::EXPAT) |
109 | | - target_link_libraries(${target_name} PRIVATE EXPAT::EXPAT) |
110 | | - else() |
111 | | - target_include_directories(${target_name} PRIVATE "${EXPAT_INCLUDE_DIRS}") |
112 | | - target_link_libraries(${target_name} PRIVATE "${EXPAT_LIBRARIES}") |
113 | | - endif() |
114 | | - target_compile_definitions(${target_name} PRIVATE OPENMETA_HAS_EXPAT=1) |
| 198 | + openmeta_apply_expat_dep(${target_name} PRIVATE) |
115 | 199 | endif() |
116 | 200 |
|
117 | 201 | if(OPENMETA_ENABLE_C2PA_VERIFY) |
|
0 commit comments