CMakeLists.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. # Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org)
  2. # Written by Mathieu Malaterre
  3. # This CMake project will by default create a library called openjpeg
  4. # But if you want to use this project within your own (CMake) project
  5. # you will eventually like to prefix the library to avoid linking confusion
  6. # For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like
  7. # e.g.:
  8. # set(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
  9. cmake_minimum_required(VERSION 2.8.2)
  10. if(COMMAND CMAKE_POLICY)
  11. cmake_policy(SET CMP0003 NEW)
  12. if (NOT (${CMAKE_VERSION} VERSION_LESS 3.0))
  13. cmake_policy(SET CMP0042 NEW)
  14. endif()
  15. endif()
  16. if(NOT OPENJPEG_NAMESPACE)
  17. set(OPENJPEG_NAMESPACE "OPENJPEG")
  18. set(OPENJPEG_STANDALONE 1)
  19. endif()
  20. # In all cases:
  21. #string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
  22. set(OPENJPEG_LIBRARY_NAME openjp2)
  23. project(${OPENJPEG_NAMESPACE})
  24. # Do full dependency headers.
  25. include_regular_expression("^.*$")
  26. #-----------------------------------------------------------------------------
  27. # OPENJPEG version number, useful for packaging and doxygen doc:
  28. set(OPENJPEG_VERSION_MAJOR 2)
  29. set(OPENJPEG_VERSION_MINOR 3)
  30. set(OPENJPEG_VERSION_BUILD 1)
  31. set(OPENJPEG_VERSION
  32. "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
  33. set(PACKAGE_VERSION
  34. "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
  35. # Because autotools does not support X.Y notation for SOVERSION, we have to use
  36. # two numbering, one for the openjpeg version and one for openjpeg soversion
  37. # version | soversion
  38. # 1.0 | 0
  39. # 1.1 | 1
  40. # 1.2 | 2
  41. # 1.3 | 3
  42. # 1.4 | 4
  43. # 1.5 | 5
  44. # 1.5.1 | 5
  45. # 2.0 | 6
  46. # 2.0.1 | 6
  47. # 2.1 | 7
  48. # 2.1.1 | 7
  49. # 2.1.2 | 7
  50. # 2.2.0 | 7
  51. # 2.3.0 | 7
  52. # 2.3.1 | 7
  53. # above is the recommendation by the OPJ team. If you really need to override this default,
  54. # you can specify your own OPENJPEG_SOVERSION at cmake configuration time:
  55. # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg
  56. if(NOT OPENJPEG_SOVERSION)
  57. set(OPENJPEG_SOVERSION 7)
  58. endif(NOT OPENJPEG_SOVERSION)
  59. set(OPENJPEG_LIBRARY_PROPERTIES
  60. VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
  61. SOVERSION "${OPENJPEG_SOVERSION}"
  62. )
  63. # --------------------------------------------------------------------------
  64. # Path to additional CMake modules
  65. set(CMAKE_MODULE_PATH
  66. ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake
  67. ${CMAKE_MODULE_PATH})
  68. # --------------------------------------------------------------------------
  69. # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
  70. # warnings
  71. if(WIN32)
  72. if(NOT BORLAND)
  73. if(NOT CYGWIN)
  74. if(NOT MINGW)
  75. if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
  76. add_definitions(
  77. -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
  78. -D_CRT_IS_WCTYPE_NO_DEPRECATE
  79. -D_CRT_MANAGED_FP_NO_DEPRECATE
  80. -D_CRT_NONSTDC_NO_DEPRECATE
  81. -D_CRT_SECURE_NO_DEPRECATE
  82. -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
  83. -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
  84. -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
  85. -D_CRT_VCCLRIT_NO_DEPRECATE
  86. -D_SCL_SECURE_NO_DEPRECATE
  87. )
  88. endif()
  89. endif()
  90. endif()
  91. endif()
  92. endif()
  93. # --------------------------------------------------------------------------
  94. # Install directories
  95. # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
  96. option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
  97. string(TOLOWER ${PROJECT_NAME} projectname)
  98. set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
  99. if(NOT OPENJPEG_INSTALL_BIN_DIR)
  100. set(OPENJPEG_INSTALL_BIN_DIR "bin")
  101. endif()
  102. if(NOT OPENJPEG_INSTALL_LIB_DIR)
  103. set(OPENJPEG_INSTALL_LIB_DIR "lib")
  104. endif()
  105. if(NOT OPENJPEG_INSTALL_SHARE_DIR)
  106. set(OPENJPEG_INSTALL_SHARE_DIR "share")
  107. endif()
  108. if(NOT OPENJPEG_INSTALL_DATA_DIR)
  109. set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
  110. endif()
  111. if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
  112. set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
  113. endif()
  114. if(BUILD_DOC)
  115. if(NOT OPENJPEG_INSTALL_MAN_DIR)
  116. set(OPENJPEG_INSTALL_MAN_DIR "share/man/")
  117. endif()
  118. if(NOT OPENJPEG_INSTALL_DOC_DIR)
  119. set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
  120. endif()
  121. endif()
  122. if(NOT OPENJPEG_INSTALL_JNI_DIR)
  123. if(WIN32)
  124. set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_BIN_DIR})
  125. else()
  126. set(OPENJPEG_INSTALL_JNI_DIR ${OPENJPEG_INSTALL_LIB_DIR})
  127. endif()
  128. endif()
  129. if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
  130. # We could install *.cmake files in share/ however those files contains
  131. # hardcoded path to libraries on a multi-arch system (fedora/debian) those
  132. # path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
  133. set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
  134. endif()
  135. if (APPLE)
  136. list(APPEND OPENJPEG_LIBRARY_PROPERTIES INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${OPENJPEG_INSTALL_LIB_DIR}")
  137. option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
  138. endif()
  139. #-----------------------------------------------------------------------------
  140. # Big endian test:
  141. include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
  142. TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
  143. #-----------------------------------------------------------------------------
  144. # Setup file for setting custom ctest vars
  145. configure_file(
  146. ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in
  147. ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake
  148. @ONLY
  149. )
  150. #-----------------------------------------------------------------------------
  151. # OpenJPEG build configuration options.
  152. option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
  153. option(BUILD_STATIC_LIBS "Build OpenJPEG static library." ON)
  154. set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
  155. set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
  156. mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
  157. #-----------------------------------------------------------------------------
  158. # configure name mangling to allow multiple libraries to coexist
  159. # peacefully
  160. if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
  161. set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
  162. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
  163. ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
  164. @ONLY)
  165. endif()
  166. #-----------------------------------------------------------------------------
  167. # Compiler specific flags:
  168. if(CMAKE_COMPILER_IS_GNUCC)
  169. # For all builds, make sure openjpeg is std99 compliant:
  170. # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
  171. # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
  172. set(OPENJPEG_LIBRARY_COMPILE_OPTIONS ${OPENJPEG_LIBRARY_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>")
  173. set(OPENJP2_COMPILE_OPTIONS ${OPENJP2_COMPILE_OPTIONS} "$<$<CONFIG:Release>:-ffast-math>" -Wall -Wextra -Wconversion -Wunused-parameter -Wdeclaration-after-statement -Werror=declaration-after-statement)
  174. endif()
  175. #-----------------------------------------------------------------------------
  176. # opj_config.h generation (1/2)
  177. # Check if some include files are provided by the system
  178. include(EnsureFileInclude)
  179. # These files are mandatory
  180. ensure_file_include("string.h" HAVE_STRING_H YES)
  181. ensure_file_include("memory.h" HAVE_MEMORY_H YES)
  182. ensure_file_include("stdlib.h" HAVE_STDLIB_H YES)
  183. ensure_file_include("stdio.h" HAVE_STDIO_H YES)
  184. ensure_file_include("math.h" HAVE_MATH_H YES)
  185. ensure_file_include("float.h" HAVE_FLOAT_H YES)
  186. ensure_file_include("time.h" HAVE_TIME_H YES)
  187. ensure_file_include("stdarg.h" HAVE_STDARG_H YES)
  188. ensure_file_include("ctype.h" HAVE_CTYPE_H YES)
  189. ensure_file_include("assert.h" HAVE_ASSERT_H YES)
  190. # For the following files, we provide an alternative, they are not mandatory
  191. ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO)
  192. ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO)
  193. # why check this one ? for openjpip ?
  194. include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
  195. CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
  196. CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
  197. CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
  198. CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
  199. # Enable Large file support
  200. include(TestLargeFiles)
  201. OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
  202. # Allocating Aligned Memory Blocks
  203. include(CheckIncludeFiles)
  204. check_include_files(malloc.h OPJ_HAVE_MALLOC_H)
  205. include(CheckSymbolExists)
  206. # _aligned_alloc https://msdn.microsoft.com/en-us/library/8z34s9c6.aspx
  207. check_symbol_exists(_aligned_malloc malloc.h OPJ_HAVE__ALIGNED_MALLOC)
  208. # posix_memalign (needs _POSIX_C_SOURCE >= 200112L on Linux)
  209. set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=200112L)
  210. check_symbol_exists(posix_memalign stdlib.h OPJ_HAVE_POSIX_MEMALIGN)
  211. unset(CMAKE_REQUIRED_DEFINITIONS)
  212. # memalign (obsolete)
  213. check_symbol_exists(memalign malloc.h OPJ_HAVE_MEMALIGN)
  214. #-----------------------------------------------------------------------------
  215. # Build Library
  216. if(BUILD_JPIP_SERVER)
  217. find_package(CURL REQUIRED)
  218. find_package(FCGI REQUIRED)
  219. find_package(Threads REQUIRED)
  220. if(NOT CMAKE_USE_PTHREADS_INIT)
  221. message(FATAL_ERROR "Only pthread are supported")
  222. endif()
  223. endif()
  224. add_subdirectory(src/lib)
  225. option(BUILD_LUTS_GENERATOR "Build utility to generate t1_luts.h" OFF)
  226. option(BUILD_UNIT_TESTS "Build unit tests (bench_dwt, test_sparse_array, etc..)" OFF)
  227. #-----------------------------------------------------------------------------
  228. # Build Applications
  229. option(BUILD_CODEC "Build the CODEC executables" ON)
  230. option(BUILD_MJ2 "Build the MJ2 executables." OFF)
  231. option(BUILD_JPWL "Build the JPWL library and executables" OFF)
  232. option(BUILD_JPIP "Build the JPIP library and executables." OFF)
  233. if(BUILD_JPIP)
  234. option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
  235. endif()
  236. option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
  237. option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
  238. option(BUILD_JP3D "Build the JP3D comp" OFF)
  239. mark_as_advanced(BUILD_VIEWER)
  240. mark_as_advanced(BUILD_JAVA)
  241. mark_as_advanced(BUILD_JP3D)
  242. if(BUILD_CODEC OR BUILD_MJ2)
  243. # OFF: It will only build 3rd party libs if they are not found on the system
  244. # ON: 3rd party libs will ALWAYS be build, and used
  245. option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
  246. add_subdirectory(thirdparty)
  247. add_subdirectory(src/bin)
  248. endif ()
  249. add_subdirectory(wrapping)
  250. #-----------------------------------------------------------------------------
  251. # opj_config.h generation (2/2)
  252. configure_file(
  253. ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in
  254. ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h
  255. @ONLY
  256. )
  257. configure_file(
  258. ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in
  259. ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h
  260. @ONLY
  261. )
  262. #-----------------------------------------------------------------------------
  263. # build documentation in doc subdir:
  264. if(BUILD_DOC)
  265. add_subdirectory(doc)
  266. endif()
  267. #-----------------------------------------------------------------------------
  268. # Buld Testing
  269. option(BUILD_TESTING "Build the tests." OFF)
  270. if(BUILD_TESTING)
  271. if(BUILD_CODEC)
  272. enable_testing()
  273. include(CTest)
  274. # Search openjpeg data needed for the tests
  275. # They could be found via git on the OpenJPEG GitHub code project
  276. # git clone https://github.com/uclouvain/openjpeg-data.git
  277. find_path(OPJ_DATA_ROOT README-OPJ-Data
  278. PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data
  279. NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH
  280. )
  281. # Add repository where to find tests
  282. add_subdirectory(tests)
  283. else()
  284. message(FATAL_ERROR "You need build codec to run the tests")
  285. endif()
  286. endif()
  287. #-----------------------------------------------------------------------------
  288. # install all targets referenced as OPENJPEGTargets
  289. install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
  290. configure_file( ${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
  291. ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/OpenJPEGConfig.cmake
  292. @ONLY
  293. )
  294. install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
  295. DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
  296. )
  297. #-----------------------------------------------------------------------------
  298. # install CHANGES and LICENSE
  299. if(BUILD_DOC)
  300. if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
  301. install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
  302. endif()
  303. install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
  304. endif()
  305. include (cmake/OpenJPEGCPack.cmake)
  306. #-----------------------------------------------------------------------------
  307. # pkgconfig support
  308. # enabled by default on Unix or if using GCC, disabled by default on other platforms
  309. if(UNIX OR CMAKE_COMPILER_IS_GNUCC)
  310. option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" ON)
  311. else()
  312. option(BUILD_PKGCONFIG_FILES "Build and install pkg-config files" OFF)
  313. endif()
  314. if(BUILD_PKGCONFIG_FILES)
  315. # install in lib and not share (see multi-arch note above)
  316. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in
  317. ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY)
  318. install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION
  319. ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
  320. #
  321. if(BUILD_JPWL)
  322. # install in lib and not share (see multi-arch note above)
  323. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpwl/libopenjpwl.pc.cmake.in
  324. ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc @ONLY)
  325. install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc DESTINATION
  326. ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
  327. endif()
  328. #
  329. if(BUILD_JPIP)
  330. # install in lib and not share (see multi-arch note above)
  331. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in
  332. ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY)
  333. install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION
  334. ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
  335. endif()
  336. #
  337. if(BUILD_JP3D)
  338. # install in lib and not share (see multi-arch note above)
  339. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp3d/libopenjp3d.pc.cmake.in
  340. ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc @ONLY)
  341. install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc DESTINATION
  342. ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
  343. endif()
  344. endif()
  345. #-----------------------------------------------------------------------------
  346. # build our version of astyle
  347. SET (WITH_ASTYLE FALSE CACHE BOOL "If you plan to contribute you should reindent with scripts/prepare-commit.sh (using 'our' astyle)")