VirtualBox

source: vbox/trunk/src/libs/zlib-1.2.6/CMakeLists.txt@ 40934

Last change on this file since 40934 was 40354, checked in by vboxsync, 13 years ago

libs/zlib-1.2.6: fix OSE

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1cmake_minimum_required(VERSION 2.4.4)
2set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3
4project(zlib C)
5
6if(NOT DEFINED BUILD_SHARED_LIBS)
7 option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON)
8endif()
9
10include(CheckTypeSize)
11include(CheckFunctionExists)
12include(CheckIncludeFile)
13include(CheckCSourceCompiles)
14enable_testing()
15
16check_include_file(sys/types.h HAVE_SYS_TYPES_H)
17check_include_file(stdint.h HAVE_STDINT_H)
18check_include_file(stddef.h HAVE_STDDEF_H)
19
20#
21# Check to see if we have large file support
22#
23set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
24# We add these other definitions here because CheckTypeSize.cmake
25# in CMake 2.4.x does not automatically do so and we want
26# compatibility with CMake 2.4.x.
27if(HAVE_SYS_TYPES_H)
28 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
29endif()
30if(HAVE_STDINT_H)
31 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
32endif()
33if(HAVE_STDDEF_H)
34 list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
35endif()
36check_type_size(off64_t OFF64_T)
37if(HAVE_OFF64_T)
38 add_definitions(-D_LARGEFILE64_SOURCE=1)
39endif()
40set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
41
42#
43# Check for fseeko
44#
45check_function_exists(fseeko HAVE_FSEEKO)
46if(NOT HAVE_FSEEKO)
47 add_definitions(-DNO_FSEEKO)
48endif()
49
50#
51# Check for unistd.h
52#
53check_include_file(unistd.h Z_HAVE_UNISTD_H)
54
55if(MSVC)
56 set(CMAKE_DEBUG_POSTFIX "d")
57 add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
58 add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
59endif()
60
61if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
62 # If we're doing an out of source build and the user has a zconf.h
63 # in their source tree...
64 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
65 message(FATAL_ERROR
66 "You must remove ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h "
67 "from the source tree. This file is included with zlib "
68 "but CMake generates this file for you automatically "
69 "in the build directory.")
70 endif()
71endif()
72
73configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
74 ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
75include_directories(${CMAKE_CURRENT_BINARY_DIR})
76
77
78#============================================================================
79# zlib
80#============================================================================
81
82set(ZLIB_PUBLIC_HDRS
83 ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
84 zlib.h
85)
86set(ZLIB_PRIVATE_HDRS
87 crc32.h
88 deflate.h
89 gzguts.h
90 inffast.h
91 inffixed.h
92 inflate.h
93 inftrees.h
94 trees.h
95 zutil.h
96)
97set(ZLIB_SRCS
98 adler32.c
99 compress.c
100 crc32.c
101 deflate.c
102 gzclose.c
103 gzlib.c
104 gzread.c
105 gzwrite.c
106 inflate.c
107 infback.c
108 inftrees.c
109 inffast.c
110 trees.c
111 uncompr.c
112 zutil.c
113)
114
115if(NOT MINGW)
116 set(ZLIB_SRCS ${ZLIB_SRCS}
117 win32/zlib1.rc # If present will override custom build rule below.
118 )
119endif()
120
121# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
122file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
123string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9A-Za-z.]+)\".*"
124 "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
125
126if(MINGW)
127 # This gets us DLL resource information when compiling on MinGW.
128 if(NOT CMAKE_RC_COMPILER)
129 SET(CMAKE_RC_COMPILER windres.exe)
130 endif()
131
132 add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
133 COMMAND ${CMAKE_RC_COMPILER}
134 -D GCC_WINDRES
135 -I ${CMAKE_CURRENT_SOURCE_DIR}
136 -I ${CMAKE_CURRENT_BINARY_DIR}
137 -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
138 -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
139 set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
140endif(MINGW)
141
142add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
143set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
144
145set_target_properties(zlib PROPERTIES SOVERSION 1)
146
147if(NOT CYGWIN)
148 # This property causes shared libraries on Linux to have the full version
149 # encoded into their final filename. We disable this on Cygwin because
150 # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
151 # seems to be the default.
152 #
153 # This has no effect with MSVC, on that platform the version info for
154 # the DLL comes from the resource file win32/zlib1.rc
155 set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
156endif()
157
158if(UNIX)
159 # On unix-like platforms the library is almost always called libz
160 set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
161elseif(BUILD_SHARED_LIBS AND WIN32)
162 # Creates zlib1.dll when building shared library version
163 set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
164endif()
165
166if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
167 install(TARGETS zlib
168 RUNTIME DESTINATION bin
169 ARCHIVE DESTINATION lib
170 LIBRARY DESTINATION lib )
171endif()
172if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
173 install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
174endif()
175if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
176 install(FILES zlib.3 DESTINATION share/man/man3)
177endif()
178
179#============================================================================
180# Example binaries
181#============================================================================
182
183add_executable(example test/example.c)
184target_link_libraries(example zlib)
185add_test(example example)
186
187add_executable(minigzip test/minigzip.c)
188target_link_libraries(minigzip zlib)
189
190if(HAVE_OFF64_T)
191 add_executable(example64 test/example.c)
192 target_link_libraries(example64 zlib)
193 set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
194 add_test(example64 example64)
195
196 add_executable(minigzip64 test/minigzip.c)
197 target_link_libraries(minigzip64 zlib)
198 set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
199endif()
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette