11cmake_minimum_required (VERSION 3.20 )
22
3- # TODO: Can this be replaced with a toolchain file?
4- set (CMAKE_LINK_DEPENDS_NO_SHARED TRUE )
5- # Workaround for getting the build to work on Windows
6- # This should be replaced with a iOS system at some point,
7- # but there is still much left to do for that to happen.
8- set (CMAKE_SYSTEM_NAME Linux )
9- set (CMAKE_C_COMPILER clang)
10-
11- set (SDK_PATH ${CMAKE_SOURCE_DIR} /common-3.0.sdk)
12- set (CMAKE_LINKER ${SDK_PATH} /usr/bin/ld)
13- set (LIPO ${SDK_PATH} /usr/bin/lipo)
14-
15- set (CMAKE_OSX_SYSROOT ${SDK_PATH} ) # Does not seem to work
16- set (CMAKE_OSX_ARCHITECTURES armv6 armv7)
17- set (CMAKE_OSX_DEPLOYMENT_TARGET 3.0)
18- set (CMAKE_C_COMPILER_TARGET arm-apple -ios3.0)
19-
20- set (CMAKE_C_CREATE_SHARED_LIBRARY
21- "<CMAKE_LINKER> <LINK_FLAGS> -o <TARGET> <OBJECTS>"
22- ) # Force CMake to use
23- # custom linker
24-
25- # Setting OSX Flags breaks the test on Ubuntu. Claim it works as a workaround
26- # (since it does)
27- set (CMAKE_C_COMPILER_WORKS TRUE )
28- #
3+ set (CMAKE_ARCHITECTURES "armv6;armv7" )
294
305project (zlib VERSION 1.2.3 LANGUAGES C )
316
32- set (LIB_NAME "libz.1.dylib" )
7+ set (LIB_NAME "libz.1.2.3. dylib" )
338set (INSTALL_PATH /usr/lib)
349set (VERSION 1.2.3)
3510set (COMPAT_VERSION 1.0.0)
3611
12+ set (IMAGE_BASE 0x301f6000)
13+
3714if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /zlib-src" )
3815 message (
3916 FATAL_ERROR
@@ -58,80 +35,43 @@ set(ZLIB_SOURCES
5835 ${zlib_SOURCE_DIR} /zlib/zutil.c
5936)
6037
61- add_compile_options (
62- -Wno-deprecated-non-prototype
63- -Wno-incompatible-sysroot
64- -Wno-expansion-to-defined
65- -fno-stack-protector
66- -isysroot
67- ${SDK_PATH} # Workardound for missing
68- # __stack_chk_*
69- )
70-
71- add_compile_definitions (USE_MMAP NDEBUG )
38+ add_library (${LIB_NAME} SHARED ${ZLIB_SOURCES} )
7239
73- # There are more idiomatic ways of setting some of these but stuff like
74- # target_link_libraries was not working for some reason
75- add_link_options (
76- ${SDK_PATH} /usr/lib/dylib1.o
77- -L${SDK_PATH}/usr/lib
78- -lSystem.B
79- -lgcc_s.1
80- -ios_version_min
81- ${CMAKE_OSX_DEPLOYMENT_TARGET}
82- -exported_symbols_list
83- ${zlib_SOURCE_DIR} /libz.exp
84- -dead_strip
85- -dead_strip_dylibs
86- -dylib
87- -single_module
88- -prebind
89- -dynamic
90- -twolevel_namespace
91- -twolevel_namespace_hints
92- -image_base
93- 0x301f6000
94- -install_name
95- ${INSTALL_PATH} /${LIB_NAME}
40+ set_target_properties (${LIB_NAME} PROPERTIES
41+ OUTPUT_NAME "z.${VERSION} "
42+ VERSION ${VERSION}
43+ INSTALL_NAME_DIR "${INSTALL_PATH} "
44+ POSITION_INDEPENDENT_CODE OFF
45+ C_STANDARD 99
9646)
9747
98- set (arch_targets "" )
99- # Create a target for each architecture
100- foreach (ARCH IN LISTS CMAKE_OSX_ARCHITECTURES)
101- set (target_name libz_${ARCH} )
102- list (APPEND arch_targets ${target_name} )
103- add_library (${target_name} SHARED ${ZLIB_SOURCES} )
104-
105- set_target_properties (
106- ${target_name}
107- PROPERTIES
108- OUTPUT_NAME "${LIB_NAME} .${ARCH} "
109- INSTALL_NAME_DIR "${INSTALL_PATH} "
110- PREFIX ""
111- SUFFIX ""
112- POSITION_INDEPENDENTCODE OFF
113- C_STANDARD 99
114- )
115-
116- target_include_directories (
117- ${target_name}
118- PRIVATE ${CMAKE_SOURCE_DIR} /zlib ${SDK_PATH} /usr/include
119- )
120-
121- target_compile_options (${target_name} PRIVATE -arch ${ARCH} )
122-
123- target_link_options (${target_name} PRIVATE -arch ${ARCH} -dylib )
124- endforeach ()
125-
126- set (lipo_inputs "" )
127- foreach (ARCH IN LISTS CMAKE_OSX_ARCHITECTURES)
128- list (APPEND lipo_inputs "${CMAKE_BINARY_DIR} /${LIB_NAME} .${ARCH} " )
129- endforeach ()
48+ target_compile_options (${LIB_NAME}
49+ PRIVATE
50+ -Wno-deprecated-non-prototype
51+ -Wno-expansion-to-defined
52+ -fno-stack-protector
53+ )
13054
131- add_custom_target (
132- ${LIB_NAME}
133- ALL
134- COMMAND
135- ${LIPO} -create ${lipo_inputs} -output ${CMAKE_BINARY_DIR} /${LIB_NAME}
136- DEPENDS ${arch_targets}
55+ target_compile_definitions (${LIB_NAME}
56+ PRIVATE
57+ USE_MMAP
58+ NDEBUG
13759)
60+
61+ target_link_options (${LIB_NAME}
62+ PRIVATE
63+ -exported_symbols_list
64+ ${zlib_SOURCE_DIR} /libz.exp
65+ -dead_strip
66+ -dead_strip_dylibs
67+ -dylib
68+ -single_module
69+ -prebind
70+ -dynamic
71+ -twolevel_namespace
72+ -twolevel_namespace_hints
73+ -image_base
74+ ${IMAGE_BASE}
75+ -install_name
76+ ${INSTALL_PATH} /${LIB_NAME}
77+ )
0 commit comments