]> git.lyx.org Git - features.git/blob - 3rdparty/zlib/CMakeLists.txt
Add 3rdparty to source package
[features.git] / 3rdparty / zlib / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.4.4)
2 set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3
4 project(zlib C)
5
6 set(VERSION "1.2.8")
7 set(SRCDIR ${CMAKE_CURRENT_SOURCE_DIR}/1.2.8)
8
9 option(ASM686 "Enable building i686 assembly implementation")
10 option(AMD64 "Enable building amd64 assembly implementation")
11
12 include(CheckTypeSize)
13 include(CheckFunctionExists)
14 include(CheckIncludeFile)
15 include(CheckCSourceCompiles)
16 enable_testing()
17
18 check_include_file(sys/types.h HAVE_SYS_TYPES_H)
19 check_include_file(stdint.h    HAVE_STDINT_H)
20 check_include_file(stddef.h    HAVE_STDDEF_H)
21
22 #
23 # Check to see if we have large file support
24 #
25 set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
26 # We add these other definitions here because CheckTypeSize.cmake
27 # in CMake 2.4.x does not automatically do so and we want
28 # compatibility with CMake 2.4.x.
29 if(HAVE_SYS_TYPES_H)
30     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
31 endif()
32 if(HAVE_STDINT_H)
33     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
34 endif()
35 if(HAVE_STDDEF_H)
36     list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
37 endif()
38 check_type_size(off64_t OFF64_T)
39 if(HAVE_OFF64_T)
40    add_definitions(-D_LARGEFILE64_SOURCE=1)
41 endif()
42 set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
43
44 #
45 # Check for fseeko
46 #
47 check_function_exists(fseeko HAVE_FSEEKO)
48 if(NOT HAVE_FSEEKO)
49     add_definitions(-DNO_FSEEKO)
50 endif()
51
52 #
53 # Check for unistd.h
54 #
55 check_include_file(unistd.h Z_HAVE_UNISTD_H)
56
57 if(MSVC)
58     set(CMAKE_DEBUG_POSTFIX "d")
59     add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
60     add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
61     include_directories(${CMAKE_CURRENT_SOURCE_DIR})
62 endif()
63
64 if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
65     # If we're doing an out of source build and the user has a zconf.h
66     # in their source tree...
67     if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
68         message(STATUS "Renaming")
69         message(STATUS "    ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
70         message(STATUS "to 'zconf.h.included' because this file is included with zlib")
71         message(STATUS "but CMake generates it automatically in the build directory.")
72         file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
73   endif()
74 endif()
75
76 #set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
77 #configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein ${ZLIB_PC} @ONLY)
78 configure_file(${SRCDIR}/zconf.h.cmakein ${CMAKE_BINARY_DIR}/zconf.h @ONLY)
79 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
80
81
82 #============================================================================
83 # zlib
84 #============================================================================
85
86 set(ZLIB_PUBLIC_HDRS
87     ${CMAKE_BINARY_DIR}/zconf.h
88     ${SRCDIR}/zlib.h
89 )
90 set(ZLIB_PRIVATE_HDRS
91     ${SRCDIR}/crc32.h
92     ${SRCDIR}/deflate.h
93     ${SRCDIR}/gzguts.h
94     ${SRCDIR}/inffast.h
95     ${SRCDIR}/inffixed.h
96     ${SRCDIR}/inflate.h
97     ${SRCDIR}/inftrees.h
98     ${SRCDIR}/trees.h
99     ${SRCDIR}/zutil.h
100 )
101 set(ZLIB_SRCS
102     ${SRCDIR}/adler32.c
103     ${SRCDIR}/compress.c
104     ${SRCDIR}/crc32.c
105     ${SRCDIR}/deflate.c
106     ${SRCDIR}/gzclose.c
107     ${SRCDIR}/gzlib.c
108     ${SRCDIR}/gzread.c
109     ${SRCDIR}/gzwrite.c
110     ${SRCDIR}/inflate.c
111     ${SRCDIR}/infback.c
112     ${SRCDIR}/inftrees.c
113     ${SRCDIR}/inffast.c
114     ${SRCDIR}/trees.c
115     ${SRCDIR}/uncompr.c
116     ${SRCDIR}/zutil.c
117 )
118
119
120 if(CMAKE_COMPILER_IS_GNUCC)
121     if(ASM686)
122         set(ZLIB_ASMS contrib/asm686/match.S)
123     elseif (AMD64)
124         set(ZLIB_ASMS contrib/amd64/amd64-match.S)
125     endif ()
126
127         if(ZLIB_ASMS)
128                 add_definitions(-DASMV)
129                 set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
130         endif()
131 endif()
132
133 if(MSVC)
134     if(ASM686)
135                 ENABLE_LANGUAGE(ASM_MASM)
136         set(ZLIB_ASMS
137                         contrib/masmx86/inffas32.asm
138                         contrib/masmx86/match686.asm
139                 )
140     elseif (AMD64)
141                 ENABLE_LANGUAGE(ASM_MASM)
142         set(ZLIB_ASMS
143                         contrib/masmx64/gvmat64.asm
144                         contrib/masmx64/inffasx64.asm
145                 )
146     endif()
147
148         if(ZLIB_ASMS)
149                 add_definitions(-DASMV -DASMINF)
150         endif()
151 endif()
152
153 add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
154
155
156 set(ZLIB_LIBRARY zlibstatic CACHE STRING "Zlib library" FORCE)
157 set(ZLIB_INCLUDE_DIR  ${SRCDIR} CACHE STRING "Zlib include dir" FORCE)
158 set(ZLIB_FOUND CACHE STRING "Zlib found" FORCE )
159
160 set_target_properties(zlibstatic PROPERTIES FOLDER "3rd_party")