Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ set(MINIZIP_INC)
set(MINIZIP_LIB)
set(MINIZIP_LBD)
set(MINIZIP_DEP)
set(MINIZIP_LINK_DEP)
set(MINIZIP_ZLIB_DEP)
set(MINIZIP_DEP_PKG)
set(MINIZIP_LFG)

Expand Down Expand Up @@ -233,9 +235,9 @@ if(MZ_ZLIB)

# Have to add zlib to install targets
if(ZLIB_COMPAT AND (NOT DEFINED BUILD_SHARED_LIBS OR NOT BUILD_SHARED_LIBS))
list(APPEND MINIZIP_DEP zlibstatic)
set(MINIZIP_ZLIB_DEP zlibstatic)
else()
list(APPEND MINIZIP_DEP zlib)
set(MINIZIP_ZLIB_DEP zlib)
endif()

if(EXISTS "${ZLIB_BINARY_DIR}/zlib-ng.h")
Expand Down Expand Up @@ -721,7 +723,17 @@ if(MZ_LZMA)
set_target_properties(${MINIZIP_TARGET} PROPERTIES C_STANDARD 99)
endif()

target_link_libraries(${MINIZIP_TARGET} PUBLIC ${MINIZIP_LIB} ${MINIZIP_DEP})
set(MINIZIP_LINK_DEP ${MINIZIP_DEP})

if(MINIZIP_ZLIB_DEP)
list(INSERT MINIZIP_DEP 0 ${MINIZIP_ZLIB_DEP})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why get the first item from MINIZIP_DEP? I wonder if there a better way to do this without doing this.

if(NOT ZLIB_COMPAT AND (NOT DEFINED BUILD_SHARED_LIBS OR NOT BUILD_SHARED_LIBS))
set(MINIZIP_ZLIB_DEP zlibstatic)
endif()
list(INSERT MINIZIP_LINK_DEP 0 ${MINIZIP_ZLIB_DEP})
endif()

target_link_libraries(${MINIZIP_TARGET} PUBLIC ${MINIZIP_LIB} ${MINIZIP_LINK_DEP})
target_link_directories(${MINIZIP_TARGET} PUBLIC ${MINIZIP_LBD})
target_compile_definitions(${MINIZIP_TARGET} PRIVATE ${STDLIB_DEF} ${MINIZIP_DEF})
target_include_directories(${MINIZIP_TARGET} PRIVATE ${MINIZIP_INC})
Expand Down
95 changes: 95 additions & 0 deletions test/print_vcxproj_linkage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import sys
import xml.etree.ElementTree as ET
from pathlib import Path

# ---------------------------------------------------------
# Generic Search Function
# ---------------------------------------------------------
def find_element_by_predicate(root, xpath, ns, predicate):
for element in root.findall(xpath, ns):
if predicate(element):
return element
return None

# ---------------------------------------------------------
# Matcher Factories (Closures)
# ---------------------------------------------------------
def make_label_matcher(label_val):
def matcher(element):
return (element.get('Label') == label_val)
return matcher

def make_condition_matcher(label_val, condition_val):
def matcher(element):
return (element.get('Label') == label_val and
element.get('Condition') == condition_val)
return matcher

def make_include_matcher(include_val):
def matcher(element):
return include_val in element.get('Include')
return matcher

def print_globals(root, ns):
found_globals = find_element_by_predicate(root,
'm:PropertyGroup',
ns,
make_label_matcher('Globals'))

print(f"\tProject GUID: {found_globals.find('m:ProjectGuid', ns).text}")

found_conf = find_element_by_predicate(root,
'm:PropertyGroup',
ns,
make_condition_matcher("Configuration", "'$(Configuration)|$(Platform)'=='Release|x64'"))

print(f"\tConfigurationType: {found_conf.find('m:ConfigurationType', ns).text}")

def print_reference(root, ns):
found_ref = find_element_by_predicate(root,
'm:ItemGroup/m:ProjectReference',
ns,
make_include_matcher(r"build\_deps\zlib-build\zlib"))

print(f"\tReference Name: {found_ref.find('m:Name', ns).text}")
print(f"\tReference Project: {found_ref.find('m:Project', ns).text}")

def print_parent(file, ns):
try:
print(f"{file}:")
if not Path(file).exists():
print("\t(file not found)")
else:
tree = ET.parse(file)
root = tree.getroot()
print_globals(root, ns)
print_reference(root, ns)
print()
except Exception as e:
sys.stderr.write(f"Error: {e}\n")

def print_child(file, ns):
try:
print(f"{file}:")
if not Path(file).exists():
print("\t(file not found)")
else:
tree = ET.parse(file)
root = tree.getroot()
print_globals(root, ns)
print()
except Exception as e:
sys.stderr.write(f"Error: {e}\n")

# ---------------------------------------------------------
# Main Execution
# ---------------------------------------------------------
def main():
ns = {'m': 'http://schemas.microsoft.com/developer/msbuild/2003'}

print_parent('../build/minizip.vcxproj', ns)
print_child('../build/_deps/zlib-build/zlib.vcxproj', ns)
print_child('../build/_deps/zlib-build/zlibstatic.vcxproj', ns)

if __name__ == "__main__":
main()