source: rtems/cpukit/zlib/CMakeLists.txt @ a2c6802e

4.104.11
Last change on this file since a2c6802e was a2c6802e, checked in by Ralf Corsepius <ralf.corsepius@…>, on Feb 23, 2010 at 3:53:58 PM

Import from zlib-1.2.4

  • Property mode set to 100644
File size: 5.8 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)
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)
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
55#
56# Check for errno.h
57check_include_file(errno.h HAVE_ERRNO_H)
58if(NOT HAVE_ERRNO_H)
59   add_definitions(-DNO_ERRNO_H)
60endif()
61
62if(MSVC)
63    set(CMAKE_DEBUG_POSTFIX "d")
64    add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
65    add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
66endif()
67
68if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
69    # If we're doing an out of source build and the user has a zconf.h
70    # in their source tree...
71    if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
72        message(FATAL_ERROR
73            "You must remove ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h "
74            "from the source tree.  This file is included with zlib "
75            "but CMake generates this file for you automatically "
76            "in the build directory.")
77  endif()
78endif()
79
80configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
81               ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
82include_directories(${CMAKE_CURRENT_BINARY_DIR})
83
84
85#============================================================================
86# zlib
87#============================================================================
88
89set(ZLIB_PUBLIC_HDRS
90    ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
91    zlib.h
92)
93set(ZLIB_PRIVATE_HDRS
94    crc32.h
95    deflate.h
96    gzguts.h
97    inffast.h
98    inffixed.h
99    inflate.h
100    inftrees.h
101    trees.h
102    zutil.h
103)
104set(ZLIB_SRCS
105    adler32.c
106    compress.c
107    crc32.c
108    deflate.c
109    gzclose.c
110    gzlib.c
111    gzread.c
112    gzwrite.c
113    inflate.c
114    infback.c
115    inftrees.c
116    inffast.c
117    trees.c
118    uncompr.c
119    zutil.c
120    win32/zlib1.rc
121)
122
123# parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
124file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
125string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9A-Za-z.]+)\".*"
126    "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
127
128if(MINGW)
129    # This gets us DLL resource information when compiling on MinGW.
130    add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
131                       COMMAND windres.exe
132                            -D GCC_WINDRES
133                            -I ${CMAKE_CURRENT_SOURCE_DIR}
134                            -I ${CMAKE_CURRENT_BINARY_DIR}
135                            -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
136                            -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
137    set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
138endif(MINGW)
139
140add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
141set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
142
143set_target_properties(zlib PROPERTIES SOVERSION 1)
144
145if(NOT CYGWIN)
146    # This property causes shared libraries on Linux to have the full version
147    # encoded into their final filename.  We disable this on Cygwin because
148    # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
149    # seems to be the default.
150    #
151    # This has no effect with MSVC, on that platform the version info for
152    # the DLL comes from the resource file win32/zlib1.rc
153    set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
154endif()
155
156if(UNIX)
157    # On unix-like platforms the library is almost always called libz
158   set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
159elseif(BUILD_SHARED_LIBS AND WIN32)
160    # Creates zlib1.dll when building shared library version
161    set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
162endif()
163
164if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
165    install(TARGETS zlib
166        RUNTIME DESTINATION bin
167        ARCHIVE DESTINATION lib
168        LIBRARY DESTINATION lib )
169endif()
170if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
171    install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
172endif()
173if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
174    install(FILES zlib.3 DESTINATION share/man/man3)
175endif()
176
177#============================================================================
178# Example binaries
179#============================================================================
180
181add_executable(example example.c)
182target_link_libraries(example zlib)
183add_test(example example)
184
185add_executable(minigzip minigzip.c)
186target_link_libraries(minigzip zlib)
187
188if(HAVE_OFF64_T)
189    add_executable(example64 example.c)
190    target_link_libraries(example64 zlib)
191    set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
192    add_test(example64 example64)
193
194    add_executable(minigzip64 minigzip.c)
195    target_link_libraries(minigzip64 zlib)
196    set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
197endif()
Note: See TracBrowser for help on using the repository browser.