aboutsummaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt57
1 files changed, 28 insertions, 29 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9c8630e..4a1b621 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,9 +1,9 @@
1cmake_minimum_required(VERSION 3.5) 1cmake_minimum_required(VERSION 3.5)
2set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON) 2set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3 3
4project(zlib C) 4project(zlib
5 5 LANGUAGES C
6set(VERSION "1.3.1.1") 6 VERSION 1.3.1.1)
7 7
8option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON) 8option(ZLIB_BUILD_EXAMPLES "Enable Zlib Examples" ON)
9option(ZLIB_BUILD_SHARED "Enable building zlib shared library" ON) 9option(ZLIB_BUILD_SHARED "Enable building zlib shared library" ON)
@@ -62,28 +62,28 @@ check_include_file(unistd.h Z_HAVE_UNISTD_H)
62if(MSVC) 62if(MSVC)
63 add_definitions(-D_CRT_SECURE_NO_DEPRECATE) 63 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
64 add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE) 64 add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
65 include_directories(${CMAKE_CURRENT_SOURCE_DIR}) 65 include_directories(${zlib_SOURCE_DIR})
66endif() 66endif()
67 67
68option(RENAME_ZCONF "Rename the zconf when building out of source" ON) 68option(RENAME_ZCONF "Rename the zconf when building out of source" ON)
69if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR AND RENAME_ZCONF) 69if(NOT zlib_SOURCE_DIR STREQUAL zlib_BINARY_DIR AND RENAME_ZCONF)
70 # If we're doing an out of source build and the user has a zconf.h 70 # If we're doing an out of source build and the user has a zconf.h
71 # in their source tree... 71 # in their source tree...
72 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h) 72 if(EXISTS ${zlib_SOURCE_DIR}/zconf.h)
73 message(STATUS "Renaming") 73 message(STATUS "Renaming")
74 message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h") 74 message(STATUS " ${zlib_SOURCE_DIR}/zconf.h")
75 message(STATUS "to 'zconf.h.included' because this file is included with zlib") 75 message(STATUS "to 'zconf.h.included' because this file is included with zlib")
76 message(STATUS "but CMake generates it automatically in the build directory.") 76 message(STATUS "but CMake generates it automatically in the build directory.")
77 file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included) 77 file(RENAME ${zlib_SOURCE_DIR}/zconf.h ${zlib_SOURCE_DIR}/zconf.h.included)
78 endif() 78 endif()
79endif() 79endif()
80 80
81set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc) 81set(ZLIB_PC ${zlib_BINARY_DIR}/zlib.pc)
82configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein 82configure_file( ${zlib_SOURCE_DIR}/zlib.pc.cmakein
83 ${ZLIB_PC} @ONLY) 83 ${ZLIB_PC} @ONLY)
84configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein 84configure_file( ${zlib_SOURCE_DIR}/zconf.h.cmakein
85 ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY) 85 ${zlib_BINARY_DIR}/zconf.h @ONLY)
86include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR}) 86include_directories(${zlib_BINARY_DIR} ${zlib_SOURCE_DIR})
87 87
88 88
89#============================================================================ 89#============================================================================
@@ -91,7 +91,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
91#============================================================================ 91#============================================================================
92 92
93set(ZLIB_PUBLIC_HDRS 93set(ZLIB_PUBLIC_HDRS
94 ${CMAKE_CURRENT_BINARY_DIR}/zconf.h 94 ${zlib_BINARY_DIR}/zconf.h
95 zlib.h 95 zlib.h
96) 96)
97set(ZLIB_PRIVATE_HDRS 97set(ZLIB_PRIVATE_HDRS
@@ -130,24 +130,23 @@ if(NOT MINGW)
130endif() 130endif()
131 131
132# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION 132# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
133file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents) 133file(READ ${zlib_SOURCE_DIR}/zlib.h _zlib_h_contents)
134string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*" 134string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
135 "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents}) 135 "\\1" ZLIB_VERSION ${_zlib_h_contents})
136
137if(MINGW) 136if(MINGW)
138 # This gets us DLL resource information when compiling on MinGW. 137 # This gets us DLL resource information when compiling on MinGW.
139 if(NOT CMAKE_RC_COMPILER) 138 if(NOT CMAKE_RC_COMPILER)
140 set(CMAKE_RC_COMPILER windres.exe) 139 set(CMAKE_RC_COMPILER windres.exe)
141 endif() 140 endif()
142 141
143 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj 142 add_custom_command(OUTPUT ${zlib_BINARY_DIR}/zlib1rc.obj
144 COMMAND ${CMAKE_RC_COMPILER} 143 COMMAND ${CMAKE_RC_COMPILER}
145 -D GCC_WINDRES 144 -D GCC_WINDRES
146 -I ${CMAKE_CURRENT_SOURCE_DIR} 145 -I ${zlib_SOURCE_DIR}
147 -I ${CMAKE_CURRENT_BINARY_DIR} 146 -I ${zlib_BINARY_DIR}
148 -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj 147 -o ${zlib_BINARY_DIR}/zlib1rc.obj
149 -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc) 148 -i ${zlib_SOURCE_DIR}/win32/zlib1.rc)
150 set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj) 149 set(ZLIB_DLL_SRCS ${zlib_BINARY_DIR}/zlib1rc.obj)
151endif(MINGW) 150endif(MINGW)
152 151
153if(WIN32) 152if(WIN32)
@@ -158,8 +157,8 @@ endif(WIN32)
158if(ZLIB_BUILD_SHARED) 157if(ZLIB_BUILD_SHARED)
159 add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) 158 add_library(zlib SHARED ${ZLIB_SRCS} ${ZLIB_DLL_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
160 target_include_directories(zlib PUBLIC 159 target_include_directories(zlib PUBLIC
161 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> 160 $<BUILD_INTERFACE:${zlib_BINARY_DIR}>
162 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) 161 $<BUILD_INTERFACE:${zlib_SOURCE_DIR}>)
163 set_target_properties(zlib PROPERTIES 162 set_target_properties(zlib PROPERTIES
164 DEFINE_SYMBOL ZLIB_DLL 163 DEFINE_SYMBOL ZLIB_DLL
165 SOVERSION 1 164 SOVERSION 1
@@ -168,15 +167,15 @@ if(ZLIB_BUILD_SHARED)
168 if(UNIX AND NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX)) 167 if(UNIX AND NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX))
169 # On unix-like platforms the library is almost always called libz 168 # On unix-like platforms the library is almost always called libz
170 set_target_properties(zlib PROPERTIES 169 set_target_properties(zlib PROPERTIES
171 LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") 170 LINK_FLAGS "-Wl,--version-script,\"${zlib_SOURCE_DIR}/zlib.map\"")
172 endif(UNIX AND NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX)) 171 endif(UNIX AND NOT APPLE AND NOT(CMAKE_SYSTEM_NAME STREQUAL AIX))
173endif(ZLIB_BUILD_SHARED) 172endif(ZLIB_BUILD_SHARED)
174 173
175if(ZLIB_BUILD_STATIC) 174if(ZLIB_BUILD_STATIC)
176 add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS}) 175 add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
177 target_include_directories(zlibstatic PUBLIC 176 target_include_directories(zlibstatic PUBLIC
178 $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> 177 $<BUILD_INTERFACE:${zlib_BINARY_DIR}>
179 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) 178 $<BUILD_INTERFACE:${zlib_SOURCE_DIR}>)
180 set_target_properties(zlibstatic PROPERTIES 179 set_target_properties(zlibstatic PROPERTIES
181 PROPERTIES OUTPUT_NAME z${zlib_static_suffix} 180 PROPERTIES OUTPUT_NAME z${zlib_static_suffix}
182 PROPERTIES OUTPUT_NAME_DEBUG z${zlib_static_suffix}${zlib_debug_suffix}) 181 PROPERTIES OUTPUT_NAME_DEBUG z${zlib_static_suffix}${zlib_debug_suffix})
@@ -190,7 +189,7 @@ if(NOT CYGWIN AND ZLIB_BUILD_SHARED)
190 # 189 #
191 # This has no effect with MSVC, on that platform the version info for 190 # This has no effect with MSVC, on that platform the version info for
192 # the DLL comes from the resource file win32/zlib1.rc 191 # the DLL comes from the resource file win32/zlib1.rc
193 set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION}) 192 set_target_properties(zlib PROPERTIES VERSION ${zlib_VERSION})
194endif() 193endif()
195 194
196if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL ) 195if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )