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