CMakeLists.txt 7.3 KB

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