Bump to lzop 1.04.01
[platform/upstream/lzop.git] / CMakeLists.txt
1 #
2 # CMakeLists.txt --- a "CMake" file for building lzop
3 #
4 # This file is part of the lzop file compressor.
5 #   http://www.oberhumer.com/opensource/lzop/
6 #
7 # Copyright (C) 1996-2017 Markus Franz Xaver Johannes Oberhumer
8 # All Rights Reserved.
9 #
10
11 cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
12
13 #
14 # simple usage example (Unix):
15 #     mkdir -p build && cd build && cmake .. && make
16 #
17 # simple usage example (Windows MSVC):
18 #     md build
19 #     cd build
20 #     cmake .. -G "NMake Makefiles"
21 #     nmake
22 #
23 # another usage example (Unix):
24 #     mkdir -p build/release-i686
25 #     cd       build/release-i686
26 #     cmake ../.. \
27 #         -DCMAKE_C_COMPILER=gcc -DCMAKE_C_FLAGS="-m32 -march=i686" \
28 #         -DCMAKE_INSTALL_PREFIX=/opt/local/prefix-i686
29 #     make VERBOSE=1
30 #     make install
31 #
32 # see http://www.cmake.org/ for more info
33 #
34
35 # /***********************************************************************
36 # // init
37 # ************************************************************************/
38
39 # Disallow in-source builds. Note that you will still have to manually
40 # clean up a few files if you accidentally try an in-source build.
41 set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
42 set(CMAKE_DISABLE_SOURCE_CHANGES  ON)
43 if(",${CMAKE_SOURCE_DIR}," STREQUAL ",${CMAKE_BINARY_DIR},")
44     message(FATAL_ERROR "ERROR: In-source builds are not allowed.")
45 endif()
46
47 if(NOT CMAKE_BUILD_TYPE)
48     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
49 endif()
50
51 project(lzop VERSION 1.04 LANGUAGES C)
52
53 # install directories
54 if(NOT CMAKE_INSTALL_PREFIX)
55     message(FATAL_ERROR "ERROR: CMAKE_INSTALL_PREFIX is not defined.")
56 endif()
57 include(GNUInstallDirs)
58
59 # FindLZO
60 include(FindPkgConfig QUIET)
61 pkg_check_modules(LZO lzo2)
62 if(NOT LZO_INCLUDE_DIRS)
63     #set(LZO_INCLUDE_DIRS /usr/local/include)
64 endif()
65 if(NOT LZO_LIBRARIES)
66     set(LZO_LIBRARIES lzo2)
67 endif()
68
69 # /***********************************************************************
70 # // targets
71 # ************************************************************************/
72
73 file(GLOB lzop_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")
74 list(SORT lzop_SOURCES)
75
76 add_executable(lzop ${lzop_SOURCES})
77 target_include_directories(lzop PRIVATE ${LZO_INCLUDE_DIRS})
78 target_link_libraries(lzop ${LZO_LIBRARIES})
79
80 # /***********************************************************************
81 # // compilation flags
82 # // this section currently mostly matches the Autoconf version
83 # ************************************************************************/
84
85 include(CheckFunctionExists)
86 include(CheckIncludeFile)
87 include(CheckLibraryExists)
88 include(CheckSymbolExists)
89 include(CheckTypeSize)
90 include(TestBigEndian)
91
92 if(MSVC)
93     # disable silly warnings about using "deprecated" POSIX functions like fopen()
94     add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
95     add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
96     add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
97     add_definitions(-D_CRT_SECURE_NO_WARNINGS)
98 endif()
99
100 # Checks for header files
101 macro(mfx_check_include_file f var)
102     check_include_file("${f}" "mfx_${var}")
103     if(NOT ",${mfx_${var}}," STREQUAL ",,")
104         add_definitions(-D${var}=1)
105         set(mfx_${var} 1)
106     else()
107         set(mfx_${var} 0)
108     endif()
109 endmacro()
110 # mfx_ACC_CHECK_HEADERS
111 set(l assert.h ctype.h dirent.h errno.h fcntl.h float.h limits.h malloc.h memory.h setjmp.h signal.h stdarg.h stddef.h stdint.h stdio.h stdlib.h string.h strings.h time.h unistd.h utime.h sys/mman.h sys/resource.h sys/stat.h sys/time.h sys/types.h sys/wait.h)
112 foreach(f ${l})
113     string(TOUPPER "${f}" var)
114     string(REGEX REPLACE "[^0-9A-Z_]" "_" var "${var}")
115     mfx_check_include_file("${f}" "HAVE_${var}")
116 endforeach()
117
118 # Checks for typedefs and structures
119 macro(mfx_check_type_size type var)
120     check_type_size("${type}" "mfx_${var}")
121     if("${mfx_${var}}" MATCHES "^[1-9][0-9]*$")
122         add_definitions(-D${var}=${mfx_${var}})
123     else()
124         set(mfx_${var} 0)
125     endif()
126 endmacro()
127 # mfx_ACC_CHECK_SIZEOF + mfx_CHECK_SIZEOF
128 set(l short int long "long long" __int16 __int32 __int64 "void *" size_t ptrdiff_t intmax_t uintmax_t intptr_t uintptr_t float double "long double" dev_t fpos_t mode_t off_t ssize_t time_t)
129 foreach(f ${l})
130     string(TOUPPER "${f}" var)
131     string(REGEX REPLACE " \\*" "_P" var "${var}")
132     string(REGEX REPLACE "[^0-9A-Z_]" "_" var "${var}")
133     mfx_check_type_size("${f}" "SIZEOF_${var}")
134 endforeach()
135
136 # Checks for library functions
137 macro(mfx_check_function_exists func var)
138     check_function_exists("${func}" "mfx_${var}")
139     if(NOT ",${mfx_${var}}," STREQUAL ",,")
140         add_definitions(-D${var}=1)
141         set(mfx_${var} 1)
142     else()
143         set(mfx_${var} 0)
144     endif()
145 endmacro()
146 # mfx_ACC_CHECK_FUNCS
147 set(l access alloca atexit atoi atol chmod chown clock_getcpuclockid clock_getres clock_gettime ctime difftime fstat getenv getpagesize getrusage gettimeofday gmtime isatty localtime longjmp lstat memcmp memcpy memmove memset mkdir mktime mmap mprotect munmap qsort raise rmdir setjmp signal snprintf strcasecmp strchr strdup strerror strftime stricmp strncasecmp strnicmp strrchr strstr time umask utime vsnprintf)
148 foreach(f ${l})
149     string(TOUPPER "${f}" var)
150     string(REGEX REPLACE "[^0-9A-Z_]" "_" var "${var}")
151     mfx_check_function_exists("${f}" "HAVE_${var}")
152 endforeach()
153
154 # mfx_ACC_CHECK_ENDIAN
155 TEST_BIG_ENDIAN(big_endian)
156 if ("${big_endian}" MATCHES "^1$")
157     add_definitions(-DACC_ABI_BIG_ENDIAN=1)
158 elseif ("${big_endian}" MATCHES "^0$")
159     add_definitions(-DACC_ABI_LITTLE_ENDIAN=1)
160 else()
161     message(FATAL_ERROR "ERROR: TEST_BIG_ENDIAN failed with result '${big_endian}'.")
162 endif()
163
164 # LZOP_HAVE_CONFIG_H
165 add_definitions(-DACC_CFG_NO_CONFIG_HEADER=1)
166
167 # warnings
168 foreach(t lzop)
169     if(CMAKE_C_COMPILER_ID MATCHES "^(Clang|GNU)$")
170         target_compile_options(${t} PRIVATE -Wall -W -Wcast-qual)
171     endif()
172 endforeach()
173
174 # /***********************************************************************
175 # // "make test"
176 # ************************************************************************/
177
178 include(CTest)
179 add_test(NAME lzoptest-01 COMMAND lzop "${CMAKE_CURRENT_SOURCE_DIR}/COPYING" -o "COPYING.lzo")
180
181 # /***********************************************************************
182 # // "make install"
183 # ************************************************************************/
184
185 if(DEFINED CMAKE_INSTALL_FULL_LIBDIR)
186
187 install(TARGETS lzop DESTINATION "${CMAKE_INSTALL_FULL_BINDIR}")
188
189 set(f AUTHORS COPYING NEWS README THANKS doc/lzop.html doc/lzop.man doc/lzop.pod doc/lzop.ps doc/lzop.tex doc/lzop.txt)
190 install(FILES ${f} DESTINATION "${CMAKE_INSTALL_FULL_DOCDIR}")
191 install(FILES doc/lzop.1 DESTINATION "${CMAKE_INSTALL_FULL_MANDIR}/man1")
192
193 endif() # CMAKE_INSTALL_FULL_LIBDIR
194
195 if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.maint.txt")
196 include("${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.maint.txt")
197 endif()
198
199 # finally print some info about the build-type
200 if(CMAKE_CONFIGURATION_TYPES)
201 message(STATUS "CMAKE_CONFIGURATION_TYPES = ${CMAKE_CONFIGURATION_TYPES}")
202 endif()
203 if(CMAKE_BUILD_TYPE)
204 message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
205 endif()
206
207 # vim:set ft=cmake ts=4 sw=4 tw=0 et: