CMakeLists.txt 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. cmake_minimum_required(VERSION 3.10.0)
  2. set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
  3. # CMake 3.0 changed the project command, setting policy CMP0048 reverts to the old behaviour.
  4. # See http://www.cmake.org/cmake/help/v3.0/policy/CMP0048.html
  5. cmake_policy(PUSH)
  6. if(CMAKE_MAJOR_VERSION GREATER 2)
  7. cmake_policy(SET CMP0048 NEW)
  8. endif()
  9. project(zlib C)
  10. SET (ZLIB_VERSION_MAJOR 1)
  11. SET (ZLIB_VERSION_MINOR 2)
  12. SET (ZLIB_VERSION_PATCH 11)
  13. SET (ZLIB_VERSION ${ZLIB_VERSION_MAJOR}.${ZLIB_VERSION_MINOR}.${ZLIB_VERSION_PATCH})
  14. SET (ZLIB_SOVERSION 1)
  15. SET (PROJECT_VERSION "${ZLIB_VERSION}")
  16. cmake_policy(POP)
  17. option(ASM686 "Enable building i686 assembly implementation")
  18. option(AMD64 "Enable building amd64 assembly implementation")
  19. #set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
  20. #set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
  21. #set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
  22. #set(INSTALL_MAN_DIR "${CMAKE_INSTALL_PREFIX}/share/man" CACHE PATH "Installation directory for manual pages")
  23. #set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/share/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
  24. include(CheckTypeSize)
  25. include(CheckFunctionExists)
  26. include(CheckIncludeFile)
  27. include(CheckCSourceCompiles)
  28. enable_testing()
  29. check_include_file(sys/types.h HAVE_SYS_TYPES_H)
  30. check_include_file(stdint.h HAVE_STDINT_H)
  31. check_include_file(stddef.h HAVE_STDDEF_H)
  32. #
  33. # Check to see if we have large file support
  34. #
  35. set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
  36. # We add these other definitions here because CheckTypeSize.cmake
  37. # in CMake 2.4.x does not automatically do so and we want
  38. # compatibility with CMake 2.4.x.
  39. if(HAVE_SYS_TYPES_H)
  40. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
  41. endif()
  42. if(HAVE_STDINT_H)
  43. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
  44. endif()
  45. if(HAVE_STDDEF_H)
  46. list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
  47. endif()
  48. check_type_size(off64_t OFF64_T)
  49. if(HAVE_OFF64_T)
  50. add_definitions(-D_LARGEFILE64_SOURCE=1)
  51. endif()
  52. set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
  53. #
  54. # Check for fseeko
  55. #
  56. check_function_exists(fseeko HAVE_FSEEKO)
  57. if(NOT HAVE_FSEEKO)
  58. add_definitions(-DNO_FSEEKO)
  59. endif()
  60. #
  61. # Check for unistd.h
  62. #
  63. check_include_file(unistd.h Z_HAVE_UNISTD_H)
  64. if(MSVC)
  65. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4131 /wd4127 /wd4244")
  66. set(CMAKE_DEBUG_POSTFIX "d")
  67. add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
  68. add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
  69. include_directories(${CMAKE_CURRENT_SOURCE_DIR})
  70. endif()
  71. if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
  72. # If we're doing an out of source build and the user has a zconf.h
  73. # in their source tree...
  74. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h)
  75. message(STATUS "Renaming")
  76. message(STATUS " ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h")
  77. message(STATUS "to 'zconf.h.included' because this file is included with zlib")
  78. message(STATUS "but CMake generates it automatically in the build directory.")
  79. file(RENAME ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.included)
  80. endif()
  81. endif()
  82. set(ZLIB_PC ${CMAKE_CURRENT_BINARY_DIR}/zlib.pc)
  83. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zlib.pc.cmakein
  84. ${ZLIB_PC} @ONLY)
  85. configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h.cmakein
  86. ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
  87. include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
  88. #============================================================================
  89. # zlib
  90. #============================================================================
  91. set(ZLIB_PUBLIC_HDRS
  92. ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
  93. zlib.h
  94. )
  95. set(ZLIB_PRIVATE_HDRS
  96. crc32.h
  97. deflate.h
  98. gzguts.h
  99. inffast.h
  100. inffixed.h
  101. inflate.h
  102. inftrees.h
  103. trees.h
  104. zutil.h
  105. )
  106. set(ZLIB_SRCS
  107. adler32.c
  108. compress.c
  109. crc32.c
  110. deflate.c
  111. gzclose.c
  112. gzlib.c
  113. gzread.c
  114. gzwrite.c
  115. inflate.c
  116. infback.c
  117. inftrees.c
  118. inffast.c
  119. trees.c
  120. uncompr.c
  121. zutil.c
  122. )
  123. if(NOT MINGW)
  124. set(ZLIB_DLL_SRCS
  125. win32/zlib1.rc # If present will override custom build rule below.
  126. )
  127. endif()
  128. if(CMAKE_COMPILER_IS_GNUCC)
  129. if(ASM686)
  130. set(ZLIB_ASMS contrib/asm686/match.S)
  131. elseif (AMD64)
  132. set(ZLIB_ASMS contrib/amd64/amd64-match.S)
  133. endif ()
  134. if(ZLIB_ASMS)
  135. add_definitions(-DASMV)
  136. set_source_files_properties(${ZLIB_ASMS} PROPERTIES LANGUAGE C COMPILE_FLAGS -DNO_UNDERLINE)
  137. endif()
  138. endif()
  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. if(ZLIB_ASMS)
  154. add_definitions(-DASMV -DASMINF)
  155. endif()
  156. endif()
  157. # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
  158. file(READ ${CMAKE_CURRENT_SOURCE_DIR}/zlib.h _zlib_h_contents)
  159. string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([-0-9A-Za-z.]+)\".*"
  160. "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
  161. if(MINGW)
  162. # This gets us DLL resource information when compiling on MinGW.
  163. if(NOT CMAKE_RC_COMPILER)
  164. set(CMAKE_RC_COMPILER windres.exe)
  165. endif()
  166. add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
  167. COMMAND ${CMAKE_RC_COMPILER}
  168. -D GCC_WINDRES
  169. -I ${CMAKE_CURRENT_SOURCE_DIR}
  170. -I ${CMAKE_CURRENT_BINARY_DIR}
  171. -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
  172. -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
  173. set(ZLIB_DLL_SRCS ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
  174. endif(MINGW)
  175. add_library(zlibstatic STATIC ${ZLIB_SRCS} ${ZLIB_ASMS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
  176. INSTALL( TARGETS zlibstatic
  177. EXPORT "${TARGETS_EXPORT_NAME}"
  178. LIBRARY DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
  179. ARCHIVE DESTINATION ${ASSIMP_LIB_INSTALL_DIR}
  180. RUNTIME DESTINATION ${ASSIMP_BIN_INSTALL_DIR}
  181. COMPONENT ${LIBASSIMP_COMPONENT})