]> git.lyx.org Git - lyx.git/blob - 3rdparty/zlib/CMakeLists.txt
Cmake build: Adapt handling of mytheslib to automek behaviour
[lyx.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 set(Z_PREFIX 1)
79 configure_file(${SRCDIR}/zconf.h.cmakein ${CMAKE_BINARY_DIR}/zconf.h @ONLY)
80 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR})
81
82
83 #============================================================================
84 # zlib
85 #============================================================================
86
87 set(ZLIB_PUBLIC_HDRS
88     ${CMAKE_BINARY_DIR}/zconf.h
89     ${SRCDIR}/zlib.h
90 )
91 set(ZLIB_PRIVATE_HDRS
92     ${SRCDIR}/crc32.h
93     ${SRCDIR}/deflate.h
94     ${SRCDIR}/gzguts.h
95     ${SRCDIR}/inffast.h
96     ${SRCDIR}/inffixed.h
97     ${SRCDIR}/inflate.h
98     ${SRCDIR}/inftrees.h
99     ${SRCDIR}/trees.h
100     ${SRCDIR}/zutil.h
101 )
102 set(ZLIB_SRCS
103     ${SRCDIR}/adler32.c
104     ${SRCDIR}/compress.c
105     ${SRCDIR}/crc32.c
106     ${SRCDIR}/deflate.c
107     ${SRCDIR}/gzclose.c
108     ${SRCDIR}/gzlib.c
109     ${SRCDIR}/gzread.c
110     ${SRCDIR}/gzwrite.c
111     ${SRCDIR}/inflate.c
112     ${SRCDIR}/infback.c
113     ${SRCDIR}/inftrees.c
114     ${SRCDIR}/inffast.c
115     ${SRCDIR}/trees.c
116     ${SRCDIR}/uncompr.c
117     ${SRCDIR}/zutil.c
118 )
119
120
121 if(CMAKE_COMPILER_IS_GNUCC)
122     if(ASM686)
123         set(ZLIB_ASMS contrib/asm686/match.S)
124     elseif (AMD64)
125         set(ZLIB_ASMS contrib/amd64/amd64-match.S)
126     endif ()
127
128         if(ZLIB_ASMS)
129                 add_definitions(-DASMV)
130                 set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
131         endif()
132 endif()
133
134 if(MSVC)
135     if(ASM686)
136                 ENABLE_LANGUAGE(ASM_MASM)
137         set(ZLIB_ASMS
138                         contrib/masmx86/inffas32.asm
139                         contrib/masmx86/match686.asm
140                 )
141     elseif (AMD64)
142                 ENABLE_LANGUAGE(ASM_MASM)
143         set(ZLIB_ASMS
144                         contrib/masmx64/gvmat64.asm
145                         contrib/masmx64/inffasx64.asm
146                 )
147     endif()
148
149         if(ZLIB_ASMS)
150                 add_definitions(-DASMV -DASMINF)
151         endif()
152 endif()
153
154 add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
155
156
157 set(ZLIB_LIBRARY zlibstatic CACHE STRING "Zlib library" FORCE)
158 set(ZLIB_INCLUDE_DIR  ${SRCDIR} CACHE STRING "Zlib include dir" FORCE)
159 set(ZLIB_FOUND CACHE STRING "Zlib found" FORCE )
160
161 set_target_properties(zlibstatic PROPERTIES FOLDER "3rd_party")