Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

406 lines
12 KiB

  1. cmake_minimum_required(VERSION 2.4.4)
  2. set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)
  3. if(UNIX AND NOT DEFINED CMAKE_BUILD_TYPE)
  4. if(CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION EQUAL 4)
  5. # workaround CMake 2.4.x bug
  6. set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
  7. "Choose the type of build, options are:
  8. None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
  9. Debug
  10. Release
  11. RelWithDebInfo
  12. MinSizeRel.")
  13. else()
  14. set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
  15. "Choose the type of build, options are:
  16. None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used)
  17. Debug
  18. Release
  19. RelWithDebInfo
  20. MinSizeRel.")
  21. endif()
  22. endif()
  23. project(libpng C)
  24. enable_testing()
  25. # Copyright (C) 2007-2011 Glenn Randers-Pehrson
  26. # This code is released under the libpng license.
  27. # For conditions of distribution and use, see the disclaimer
  28. # and license in png.h
  29. set(PNGLIB_MAJOR 1)
  30. set(PNGLIB_MINOR 5)
  31. set(PNGLIB_RELEASE 2)
  32. set(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})
  33. set(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})
  34. # needed packages
  35. find_package(ZLIB REQUIRED)
  36. include_directories(${ZLIB_INCLUDE_DIR})
  37. if(NOT WIN32)
  38. find_library(M_LIBRARY
  39. NAMES m
  40. PATHS /usr/lib /usr/local/lib
  41. )
  42. if(NOT M_LIBRARY)
  43. message(STATUS
  44. "math library 'libm' not found - floating point support disabled")
  45. endif()
  46. else()
  47. # not needed on windows
  48. set(M_LIBRARY "")
  49. endif()
  50. # COMMAND LINE OPTIONS
  51. if(DEFINED PNG_SHARED)
  52. option(PNG_SHARED "Build shared lib" ${PNG_SHARED})
  53. else()
  54. option(PNG_SHARED "Build shared lib" ON)
  55. endif()
  56. if(DEFINED PNG_STATIC)
  57. option(PNG_STATIC "Build static lib" ${PNG_STATIC})
  58. else()
  59. option(PNG_STATIC "Build static lib" ON)
  60. endif()
  61. if(MINGW)
  62. option(PNG_TESTS "Build pngtest" NO)
  63. else()
  64. option(PNG_TESTS "Build pngtest" YES)
  65. endif()
  66. option(PNG_NO_CONSOLE_IO "FIXME" YES)
  67. option(PNG_NO_STDIO "FIXME" YES)
  68. option(PNG_DEBUG "Build with debug output" NO)
  69. option(PNGARG "FIXME" YES)
  70. #TODO:
  71. # PNG_CONSOLE_IO_SUPPORTED
  72. # maybe needs improving, but currently I don't know when we can enable what :)
  73. set(png_asm_tmp "OFF")
  74. if(NOT WIN32)
  75. find_program(uname_executable NAMES uname PATHS /bin /usr/bin /usr/local/bin)
  76. if(uname_executable)
  77. exec_program(${uname_executable}
  78. ARGS --machine OUTPUT_VARIABLE uname_output)
  79. if("uname_output" MATCHES "^.*i[1-9]86.*$")
  80. set(png_asm_tmp "ON")
  81. else("uname_output" MATCHES "^.*i[1-9]86.*$")
  82. set(png_asm_tmp "OFF")
  83. endif("uname_output" MATCHES "^.*i[1-9]86.*$")
  84. endif(uname_executable)
  85. else()
  86. # this env var is normally only set on win64
  87. set(TEXT "ProgramFiles(x86)")
  88. if("$ENV{${TEXT}}" STREQUAL "")
  89. set(png_asm_tmp "ON")
  90. endif("$ENV{${TEXT}}" STREQUAL "")
  91. endif()
  92. # SET LIBNAME
  93. set(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})
  94. # to distinguish between debug and release lib
  95. set(CMAKE_DEBUG_POSTFIX "d")
  96. # Use the prebuilt pnglibconf.h file from the scripts folder
  97. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt
  98. ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)
  99. include_directories(${CMAKE_CURRENT_BINARY_DIR})
  100. # OUR SOURCES
  101. set(libpng_public_hdrs
  102. png.h
  103. pngconf.h
  104. ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h
  105. )
  106. set(libpng_sources
  107. ${libpng_public_hdrs}
  108. pngdebug.h
  109. pnginfo.h
  110. pngpriv.h
  111. pngstruct.h
  112. png.c
  113. pngerror.c
  114. pngget.c
  115. pngmem.c
  116. pngpread.c
  117. pngread.c
  118. pngrio.c
  119. pngrtran.c
  120. pngrutil.c
  121. pngset.c
  122. pngtrans.c
  123. pngwio.c
  124. pngwrite.c
  125. pngwtran.c
  126. pngwutil.c
  127. )
  128. set(pngtest_sources
  129. pngtest.c
  130. )
  131. # SOME NEEDED DEFINITIONS
  132. add_definitions(-DPNG_CONFIGURE_LIBPNG)
  133. if(_AIX)
  134. add_definitions(-D_ALL_SOURCE)
  135. endif(_AIX)
  136. if(MSVC)
  137. add_definitions(-DPNG_NO_MODULEDEF -D_CRT_SECURE_NO_DEPRECATE)
  138. endif(MSVC)
  139. if(PNG_SHARED OR NOT MSVC)
  140. #if building msvc static this has NOT to be defined
  141. add_definitions(-DZLIB_DLL)
  142. endif()
  143. if(PNG_CONSOLE_IO_SUPPORTED)
  144. add_definitions(-DPNG_CONSOLE_IO_SUPPORTED)
  145. endif()
  146. if(PNG_NO_CONSOLE_IO)
  147. add_definitions(-DPNG_NO_CONSOLE_IO)
  148. endif()
  149. if(PNG_NO_STDIO)
  150. add_definitions(-DPNG_NO_STDIO)
  151. endif()
  152. if(PNG_DEBUG)
  153. add_definitions(-DPNG_DEBUG)
  154. endif()
  155. if(NOT M_LIBRARY AND NOT WIN32)
  156. add_definitions(-DPNG_NO_FLOATING_POINT_SUPPORTED)
  157. endif()
  158. # NOW BUILD OUR TARGET
  159. include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})
  160. if(PNG_SHARED)
  161. add_library(${PNG_LIB_NAME} SHARED ${libpng_sources})
  162. if(MSVC)
  163. # msvc does not append 'lib' - do it here to have consistent name
  164. set_target_properties(${PNG_LIB_NAME} PROPERTIES PREFIX "lib")
  165. set_target_properties(${PNG_LIB_NAME} PROPERTIES IMPORT_PREFIX "lib")
  166. endif()
  167. target_link_libraries(${PNG_LIB_NAME} ${ZLIB_LIBRARY} ${M_LIBRARY})
  168. endif()
  169. if(PNG_STATIC)
  170. # does not work without changing name
  171. set(PNG_LIB_NAME_STATIC ${PNG_LIB_NAME}_static)
  172. add_library(${PNG_LIB_NAME_STATIC} STATIC ${libpng_sources})
  173. if(MSVC)
  174. # msvc does not append 'lib' - do it here to have consistent name
  175. set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES PREFIX "lib")
  176. endif()
  177. target_link_libraries(${PNG_LIB_NAME_STATIC} ${ZLIB_LIBRARY} ${M_LIBRARY})
  178. endif()
  179. if(PNG_SHARED AND WIN32)
  180. set_target_properties(${PNG_LIB_NAME} PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)
  181. endif()
  182. if(PNG_TESTS AND PNG_SHARED)
  183. # does not work with msvc due to png_lib_ver issue
  184. add_executable(pngtest ${pngtest_sources})
  185. target_link_libraries(pngtest ${PNG_LIB_NAME})
  186. add_test(pngtest ./pngtest ${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png)
  187. endif()
  188. #
  189. # Set a variable with CMake code which:
  190. # Creates a symlink from src to dest (if possible) or alternatively
  191. # copies if different.
  192. macro(_png_generate_symlink_code CODE SRC DEST)
  193. if(WIN32 AND NOT CYGWIN)
  194. set(_png_gsc_message "Copying ${SRC} to ${DEST} if needed")
  195. set(_png_gsc_operation "copy_if_different")
  196. else()
  197. set(_png_gsc_message "Symlinking ${SRC} to ${DEST}")
  198. set(_png_gsc_operation "create_symlink")
  199. endif()
  200. set(${CODE} "
  201. message(STATUS \"${_png_gsc_message}\")
  202. execute_process(COMMAND \${CMAKE_COMMAND} -E ${_png_gsc_operation}
  203. \"${SRC}\" \"${DEST}\")
  204. ")
  205. endmacro()
  206. # CREATE PKGCONFIG FILES
  207. # we use the same files like ./configure, so we have to set its vars
  208. if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
  209. set(CMAKE_INSTALL_LIBDIR lib)
  210. endif(NOT DEFINED CMAKE_INSTALL_LIBDIR)
  211. set(prefix ${CMAKE_INSTALL_PREFIX})
  212. set(exec_prefix ${CMAKE_INSTALL_PREFIX})
  213. set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
  214. set(includedir ${CMAKE_INSTALL_PREFIX}/include)
  215. set(LIBS "-lz -lm")
  216. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
  217. ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
  218. _png_generate_symlink_code(PNG_PC_INSTALL_CODE
  219. ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
  220. ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
  221. install(CODE ${PNG_PC_INSTALL_CODE})
  222. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
  223. ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)
  224. _png_generate_symlink_code(PNG_CONFIG_INSTALL_CODE
  225. ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
  226. ${CMAKE_CURRENT_BINARY_DIR}/libpng-config)
  227. install(CODE ${PNG_CONFIG_INSTALL_CODE})
  228. # SET UP LINKS
  229. if(PNG_SHARED)
  230. set_target_properties(${PNG_LIB_NAME} PROPERTIES
  231. # VERSION 15.${PNGLIB_RELEASE}.1.5.2
  232. VERSION 15.${PNGLIB_RELEASE}.0
  233. SOVERSION 15
  234. CLEAN_DIRECT_OUTPUT 1)
  235. endif()
  236. if(PNG_STATIC)
  237. # MSVC doesn't use a different file extension for shared vs. static
  238. # libs. We are able to change OUTPUT_NAME to remove the _static
  239. # for all other platforms.
  240. if(NOT MSVC)
  241. set_target_properties(${PNG_LIB_NAME_STATIC} PROPERTIES
  242. OUTPUT_NAME ${PNG_LIB_NAME}
  243. CLEAN_DIRECT_OUTPUT 1)
  244. endif()
  245. endif()
  246. # If CMake > 2.4.x, we set a variable used below to export
  247. # targets to an export file.
  248. # TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2
  249. if(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)
  250. set(PNG_EXPORT_RULE EXPORT libpng)
  251. elseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof
  252. set(PNG_EXPORT_RULE EXPORT libpng)
  253. endif()
  254. # INSTALL
  255. if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
  256. if(PNG_SHARED)
  257. install(TARGETS ${PNG_LIB_NAME}
  258. ${PNG_EXPORT_RULE}
  259. RUNTIME DESTINATION bin
  260. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  261. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  262. # Create a symlink for libpng.dll.a => libpng15.dll.a on Cygwin
  263. if(CYGWIN)
  264. _png_generate_symlink_code(PNG_SHARED_IMPLIB_INSTALL_CODE
  265. ${PNGLIB_NAME}${CMAKE_IMPORT_LIBRARY_SUFFIX}
  266. libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})
  267. install(CODE ${PNG_SHARED_IMPLIB_INSTALL_CODE})
  268. install(FILES
  269. ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}
  270. DESTINATION ${CMAKE_INSTALL_LIBDIR})
  271. endif()
  272. if(NOT WIN32)
  273. IF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  274. _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE
  275. ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
  276. ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
  277. install(CODE ${PNG_SHARED_INSTALL_CODE})
  278. install(FILES
  279. ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
  280. DESTINATION ${CMAKE_INSTALL_LIBDIR})
  281. ELSE(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  282. _png_generate_symlink_code(PNG_SHARED_INSTALL_CODE
  283. ${PNGLIB_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
  284. libpng${CMAKE_SHARED_LIBRARY_SUFFIX})
  285. install(CODE ${PNG_SHARED_INSTALL_CODE})
  286. install(FILES
  287. ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}
  288. DESTINATION ${CMAKE_INSTALL_LIBDIR})
  289. ENDIF(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
  290. endif()
  291. endif()
  292. if(PNG_STATIC)
  293. install(TARGETS ${PNG_LIB_NAME_STATIC}
  294. ${PNG_EXPORT_RULE}
  295. LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
  296. ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
  297. if(NOT WIN32 OR CYGWIN)
  298. IF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  299. _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE
  300. ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
  301. ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
  302. install(CODE ${PNG_STATIC_INSTALL_CODE})
  303. install(FILES
  304. ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
  305. DESTINATION ${CMAKE_INSTALL_LIBDIR})
  306. ELSE(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  307. _png_generate_symlink_code(PNG_STATIC_INSTALL_CODE
  308. ${PNGLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX}
  309. libpng${CMAKE_STATIC_LIBRARY_SUFFIX})
  310. install(CODE ${PNG_STATIC_INSTALL_CODE})
  311. install(FILES
  312. ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}
  313. DESTINATION ${CMAKE_INSTALL_LIBDIR})
  314. ENDIF(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
  315. endif()
  316. endif()
  317. endif()
  318. if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
  319. install(FILES ${libpng_public_hdrs} DESTINATION include)
  320. install(FILES ${libpng_public_hdrs} DESTINATION include/${PNGLIB_NAME})
  321. endif()
  322. if(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )
  323. install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)
  324. install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
  325. DESTINATION bin)
  326. endif()
  327. if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
  328. # Install man pages
  329. if(NOT PNG_MAN_DIR)
  330. set(PNG_MAN_DIR "share/man")
  331. endif()
  332. install(FILES libpng.3 libpngpf.3 DESTINATION ${PNG_MAN_DIR}/man3)
  333. install(FILES png.5 DESTINATION ${PNG_MAN_DIR}/man5)
  334. # Install pkg-config files
  335. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
  336. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  337. install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
  338. DESTINATION bin)
  339. install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
  340. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
  341. install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
  342. DESTINATION bin)
  343. endif()
  344. # On versions of CMake that support it, create an export file CMake
  345. # users can include() to import our targets
  346. if(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )
  347. install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)
  348. endif()
  349. # what's with libpng-$VER%.txt and all the extra files?
  350. # UNINSTALL
  351. # do we need this?
  352. # DIST
  353. # do we need this?
  354. # to create msvc import lib for mingw compiled shared lib
  355. # pexports libpng.dll > libpng.def
  356. # lib /def:libpng.def /machine:x86