miniupnpd 1.9 (20160113)
[tomato.git] / release / src / router / lzo / CMakeLists.txt
blobbf79f63764b97b10f4f2c61536b38ad351818e65
2 # CMakeLists.txt --- a simple "CMake" file for building LZO
4 # This file is part of the LZO data compression library.
6 # Copyright (C) 1996-2015 Markus Franz Xaver Johannes Oberhumer
7 # All Rights Reserved.
11 # simple usage:
12 #     mkdir -p build && cd build && cmake .. && make
14 # another usage example:
15 #     mkdir -p build/release-i686
16 #     cd       build/release-i686
17 #     cmake ../.. -DENABLE_STATIC=0 -DENABLE_SHARED=1 \
18 #         -DCMAKE_C_COMPILER=gcc -DCMAKE_C_FLAGS="-m32 -march=i686" \
19 #         -DCMAKE_INSTALL_PREFIX=/opt/local/prefix-i686
20 #     make VERBOSE=1
21 #     make install
23 # see http://www.cmake.org/ for more info
27 # init
30 cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
32 # Disallow in-source builds. Note that you will still have to manually
33 # clean up a few files if you accidentally try an in-source build.
34 set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
35 set(CMAKE_DISABLE_SOURCE_CHANGES  ON)
36 if(",${CMAKE_SOURCE_DIR}," STREQUAL ",${CMAKE_BINARY_DIR},")
37     message(FATAL_ERROR "ERROR: In-source builds are not allowed.")
38 endif()
40 project(lzo C)
43 # configuration options
46 option(ENABLE_STATIC "Build static LZO library." ON)
47 option(ENABLE_SHARED "Build shared LZO library." OFF)
49 if(NOT CMAKE_BUILD_TYPE)
50     set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
51 endif()
52 if(NOT CMAKE_INSTALL_PREFIX)
53     set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "" FORCE)
54 endif()
57 # targets
60 file(GLOB lzo_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.c")
61 list(SORT lzo_SOURCES)
63 # LZO library
64 if(NOT ENABLE_STATIC AND NOT ENABLE_SHARED)
65     set(ENABLE_STATIC ON)
66 endif()
67 if(ENABLE_STATIC)
68     add_library(lzo_static STATIC ${lzo_SOURCES})
69     set_target_properties(lzo_static PROPERTIES OUTPUT_NAME lzo2)
70 endif()
71 if(ENABLE_SHARED)
72     add_library(lzo_shared SHARED ${lzo_SOURCES})
73     set_target_properties(lzo_shared PROPERTIES OUTPUT_NAME lzo2)
74     set_target_properties(lzo_shared PROPERTIES SOVERSION 2 VERSION 2.0.0)
75 endif()
77 # tests & examples
78 macro(lzo_add_executable t)
79     add_executable(${t} ${ARGN})
80     if(ENABLE_STATIC)
81         target_link_libraries(${t} lzo_static)
82     else()
83         target_link_libraries(${t} lzo_shared)
84     endif()
85 endmacro()
86 # main test driver
87 lzo_add_executable(lzotest  lzotest/lzotest.c)
88 # examples
89 lzo_add_executable(dict     examples/dict.c)
90 lzo_add_executable(lzopack  examples/lzopack.c)
91 lzo_add_executable(overlap  examples/overlap.c)
92 lzo_add_executable(precomp  examples/precomp.c)
93 lzo_add_executable(precomp2 examples/precomp2.c)
94 lzo_add_executable(simple   examples/simple.c)
95 # some boring internal test programs
96 if(0)
97     lzo_add_executable(align    tests/align.c)
98     lzo_add_executable(chksum   tests/chksum.c)
99     lzo_add_executable(promote  tests/promote.c)
100     lzo_add_executable(sizes    tests/sizes.c)
101 endif()
103 # miniLZO
104 if(1)
105     add_executable(testmini minilzo/testmini.c minilzo/minilzo.c)
106     include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/lzo) # needed for "lzoconf.h"
107 endif()
110 # compilation flags
113 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
114 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
116 include(CheckFunctionExists)
117 include(CheckIncludeFile)
118 include(CheckLibraryExists)
119 include(CheckSymbolExists)
120 include(CheckTypeSize)
121 include(TestBigEndian)
123 # Checks for header files
124 macro(mfx_check_include_file f var)
125     check_include_file("${f}" "mfx_${var}")
126     if(NOT ",${mfx_${var}}," STREQUAL ",,")
127         add_definitions(-D${var}=1)
128         set(mfx_${var} 1)
129     else()
130         set(mfx_${var} 0)
131     endif()
132 endmacro()
133 # mfx_ACC_CHECK_HEADERS
134 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)
135 foreach(f ${l})
136     string(TOUPPER "${f}" var)
137     string(REGEX REPLACE "[^0-9A-Z_]" "_" var "${var}")
138     mfx_check_include_file("${f}" "HAVE_${var}")
139 endforeach()
141 # Checks for typedefs and structures
142 macro(mfx_check_type_size type var)
143     check_type_size("${type}" "mfx_${var}")
144     if("${mfx_${var}}" MATCHES "^[1-9][0-9]*$")
145         add_definitions(-D${var}=${mfx_${var}})
146     else()
147         set(mfx_${var} 0)
148     endif()
149 endmacro()
150 # mfx_ACC_CHECK_SIZEOF + mfx_CHECK_SIZEOF
151 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)
152 foreach(f ${l})
153     string(TOUPPER "${f}" var)
154     string(REGEX REPLACE " \\*" "_P" var "${var}")
155     string(REGEX REPLACE "[^0-9A-Z_]" "_" var "${var}")
156     mfx_check_type_size("${f}" "SIZEOF_${var}")
157 endforeach()
159 # Checks for library functions
160 macro(mfx_check_function_exists func var)
161     check_function_exists("${func}" "mfx_${var}")
162     if(NOT ",${mfx_${var}}," STREQUAL ",,")
163         add_definitions(-D${var}=1)
164         set(mfx_${var} 1)
165     else()
166         set(mfx_${var} 0)
167     endif()
168 endmacro()
169 # mfx_ACC_CHECK_FUNCS
170 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)
171 foreach(f ${l})
172     string(TOUPPER "${f}" var)
173     string(REGEX REPLACE "[^0-9A-Z_]" "_" var "${var}")
174     mfx_check_function_exists("${f}" "HAVE_${var}")
175 endforeach()
177 # mfx_LZO_CHECK_ENDIAN
178 TEST_BIG_ENDIAN(big_endian)
179 if ("${big_endian}" MATCHES "^1$")
180     add_definitions(-DLZO_ABI_BIG_ENDIAN=1)
181 elseif ("${big_endian}" MATCHES "^0$")
182     add_definitions(-DLZO_ABI_LITTLE_ENDIAN=1)
183 else()
184     message(FATAL_ERROR "ERROR: TEST_BIG_ENDIAN failed with result '${big_endian}'.")
185 endif()
187 # LZO_HAVE_CONFIG_H
188 add_definitions(-DLZO_CFG_NO_CONFIG_HEADER=1)
191 # "make install"
194 # these subdirs are relative to CMAKE_INSTALL_PREFIX
195 if(NOT DEFINED install_doc_subdir)
196     set(install_doc_subdir "share/doc/lzo")
197 endif()
198 if(NOT DEFINED install_include_subdir)
199     set(install_include_subdir "include/lzo")
200 endif()
201 if(NOT DEFINED install_lib_subdir)
202     set(install_lib_subdir "lib")
203 endif()
204 if(NOT DEFINED install_examples_subdir)
205     set(install_examples_subdir "libexec/lzo/examples")
206 endif()
208 set(doc_DATA AUTHORS COPYING NEWS THANKS doc/LZO.FAQ doc/LZO.TXT doc/LZOAPI.TXT)
209 set(pkginclude_HEADERS
210     include/lzo/lzo1.h include/lzo/lzo1a.h include/lzo/lzo1b.h
211     include/lzo/lzo1c.h include/lzo/lzo1f.h include/lzo/lzo1x.h
212     include/lzo/lzo1y.h include/lzo/lzo1z.h include/lzo/lzo2a.h
213     include/lzo/lzo_asm.h include/lzo/lzoconf.h include/lzo/lzodefs.h
214     include/lzo/lzoutil.h
217 install(FILES ${doc_DATA} DESTINATION "${install_doc_subdir}")
218 install(FILES ${pkginclude_HEADERS} DESTINATION "${install_include_subdir}")
219 if(ENABLE_STATIC)
220     install(TARGETS lzo_static DESTINATION "${install_lib_subdir}")
221 endif()
222 if(ENABLE_SHARED)
223     install(TARGETS lzo_shared DESTINATION "${install_lib_subdir}")
224 endif()
225 if(0)
226     set(lzo_EXAMPLES lzopack lzotest simple)
227     if(NOT ENABLE_STATIC)
228         set(d "${CMAKE_INSTALL_PREFIX}/${install_lib_subdir}")
229         set_target_properties(${lzo_EXAMPLES} PROPERTIES INSTALL_RPATH "${d}")
230     endif()
231     install(TARGETS ${lzo_EXAMPLES} DESTINATION "${install_examples_subdir}")
232 endif()
234 # vim:set ft=cmake ts=4 sw=4 tw=0 et: