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