Skip to content

Commit 7fcb284

Browse files
committed
Merge branch 'main' of https://github.com/ssh4net/OpenMeta
2 parents 46bc9e3 + 4423b85 commit 7fcb284

3 files changed

Lines changed: 96 additions & 14 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,7 @@ foreach(_tgt IN ITEMS openmeta_static openmeta_shared)
313313
target_compile_definitions(${_tgt} PUBLIC OPENMETA_HAS_BROTLI=1)
314314
endif()
315315
if(OPENMETA_EXPAT_FOUND)
316-
if(TARGET EXPAT::EXPAT)
317-
target_link_libraries(${_tgt} PUBLIC EXPAT::EXPAT)
318-
else()
319-
target_include_directories(${_tgt} PUBLIC "${EXPAT_INCLUDE_DIRS}")
320-
target_link_libraries(${_tgt} PUBLIC "${EXPAT_LIBRARIES}")
321-
endif()
322-
target_compile_definitions(${_tgt} PUBLIC OPENMETA_HAS_EXPAT=1)
316+
openmeta_apply_expat_dep(${_tgt} PUBLIC)
323317
endif()
324318
if(OPENMETA_DNG_SDK_FOUND)
325319
target_link_libraries(${_tgt} PUBLIC dng_sdk::dng_sdk)

cmake/OpenMetaDependencies.cmake

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,95 @@
11
include_guard(GLOBAL)
22

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+
393
function(openmeta_add_googletest)
494
if(TARGET gtest_main)
595
set(OPENMETA_GTEST_PROVIDER "already-present" PARENT_SCOPE)
@@ -105,13 +195,7 @@ function(openmeta_apply_core_deps target_name)
105195
endif()
106196

107197
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)
115199
endif()
116200

117201
if(OPENMETA_ENABLE_C2PA_VERIFY)

cmake/OpenMetaTargetSettings.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ function(openmeta_apply_target_settings target_name)
1313
)
1414
set_target_properties(${target_name} PROPERTIES CXX_EXTENSIONS OFF)
1515

16+
if(WIN32)
17+
target_compile_definitions(${target_name} PRIVATE NOMINMAX)
18+
endif()
19+
1620
if(MSVC)
1721
target_compile_options(${target_name} PRIVATE /W4 /EHs-c- /GR-)
1822
target_compile_definitions(${target_name} PRIVATE _HAS_EXCEPTIONS=0)

0 commit comments

Comments
 (0)