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