1 # Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org)
2 # Written by Mathieu Malaterre
4 # This CMake project will by default create a library called openjpeg
5 # But if you want to use this project within your own (CMake) project
6 # you will eventually like to prefix the library to avoid linking confusion
7 # For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like
9 # SET(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
10 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
12 IF(COMMAND CMAKE_POLICY)
13 CMAKE_POLICY(SET CMP0003 NEW)
14 ENDIF(COMMAND CMAKE_POLICY)
16 IF(NOT OPENJPEG_NAMESPACE)
17 SET(OPENJPEG_NAMESPACE "OPENJPEG")
18 SET(OPENJPEG_STANDALONE 1)
19 ENDIF(NOT OPENJPEG_NAMESPACE)
21 STRING(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
23 PROJECT(${OPENJPEG_NAMESPACE} C)
25 # Do full dependency headers.
26 INCLUDE_REGULAR_EXPRESSION("^.*$")
28 #-----------------------------------------------------------------------------
29 # OPENJPEG version number, useful for packaging and doxygen doc:
30 SET(OPENJPEG_VERSION_MAJOR 1)
31 SET(OPENJPEG_VERSION_MINOR 99)
32 SET(OPENJPEG_VERSION_BUILD 0)
34 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
36 "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
37 SET(OPENJPEG_LIBRARY_PROPERTIES
38 VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
39 SOVERSION "${OPENJPEG_VERSION_MAJOR}"
42 # --------------------------------------------------------------------------
43 # Path to additional CMake modules
45 ${CMAKE_SOURCE_DIR}/CMake
48 # --------------------------------------------------------------------------
49 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
55 IF(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
57 -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
58 -D_CRT_IS_WCTYPE_NO_DEPRECATE
59 -D_CRT_MANAGED_FP_NO_DEPRECATE
60 -D_CRT_NONSTDC_NO_DEPRECATE
61 -D_CRT_SECURE_NO_DEPRECATE
62 -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
63 -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
64 -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
65 -D_CRT_VCCLRIT_NO_DEPRECATE
66 -D_SCL_SECURE_NO_DEPRECATE
68 ENDIF(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
75 # --------------------------------------------------------------------------
78 STRING(TOLOWER ${PROJECT_NAME} projectname)
79 SET(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
81 IF(NOT OPENJPEG_INSTALL_BIN_DIR)
82 SET(OPENJPEG_INSTALL_BIN_DIR "bin")
83 ENDIF(NOT OPENJPEG_INSTALL_BIN_DIR)
85 IF(NOT OPENJPEG_INSTALL_LIB_DIR)
86 SET(OPENJPEG_INSTALL_LIB_DIR "lib")
87 ENDIF(NOT OPENJPEG_INSTALL_LIB_DIR)
89 IF(NOT OPENJPEG_INSTALL_DATA_DIR)
90 SET(OPENJPEG_INSTALL_DATA_DIR "share/${OPENJPEG_INSTALL_SUBDIR}")
91 ENDIF(NOT OPENJPEG_INSTALL_DATA_DIR)
93 IF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
94 SET(OPENJPEG_INSTALL_INCLUDE_DIR "include/")
95 ENDIF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
97 IF(NOT OPENJPEG_INSTALL_MAN_DIR)
98 SET(OPENJPEG_INSTALL_MAN_DIR "share/man/")
99 ENDIF(NOT OPENJPEG_INSTALL_MAN_DIR)
101 IF(NOT OPENJPEG_INSTALL_DOC_DIR)
102 SET(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
103 ENDIF(NOT OPENJPEG_INSTALL_DOC_DIR)
105 IF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
106 SET(OPENJPEG_INSTALL_PACKAGE_DIR ${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}
108 ENDIF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
110 #-----------------------------------------------------------------------------
111 # Test for some required system information.
112 INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
115 INCLUDE (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
116 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
118 #-----------------------------------------------------------------------------
119 # Setup file for setting custom ctest vars
121 ${CMAKE_SOURCE_DIR}/CMake/CTestCustom.cmake.in
122 ${CMAKE_BINARY_DIR}/CTestCustom.cmake
126 #-----------------------------------------------------------------------------
127 # OpenJPEG build configuration options.
128 OPTION(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
129 SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
130 SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
131 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
133 #-----------------------------------------------------------------------------
134 # configure name mangling to allow multiple libraries to coexist
136 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
137 SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
138 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
139 ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
141 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
143 #-----------------------------------------------------------------------------
145 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libopenjpeg1.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/libopenjpeg1.pc @ONLY)
146 INSTALL( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpeg1.pc DESTINATION ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig )
148 "EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E create_symlink \"libopenjpeg1.pc\" \"\$ENV{DESTDIR}${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig/libopenjpeg.pc\")")
150 #-----------------------------------------------------------------------------
151 # Compiler specific flags:
152 IF(CMAKE_COMPILER_IS_GNUCC)
153 # For all builds, make sure openjpeg is std99 compliant:
154 # SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
155 # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
156 SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
157 ENDIF(CMAKE_COMPILER_IS_GNUCC)
159 #-----------------------------------------------------------------------------
160 # opj_config.h generation (1/2)
161 CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H)
162 CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H)
163 CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H)
164 CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H)
165 CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H)
166 CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H)
167 CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H)
168 CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H)
169 CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H)
171 #-----------------------------------------------------------------------------
173 INCLUDE_DIRECTORIES(BEFORE ${OPENJPEG_BINARY_DIR})
174 ADD_SUBDIRECTORY(libopenjpeg)
176 #-----------------------------------------------------------------------------
178 OPTION(BUILD_CODEC "Build the CODEC executables" ON)
179 OPTION(BUILD_MJ2 "Build the MJ2 executables." OFF)
180 OPTION(BUILD_JPIP "Build the JPIP library and executables." OFF)
182 IF(BUILD_CODEC OR BUILD_MJ2 OR BUILD_JPIP)
183 OPTION(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
184 ADD_SUBDIRECTORY(thirdparty)
185 ADD_SUBDIRECTORY(applications)
186 ENDIF (BUILD_CODEC OR BUILD_MJ2 OR BUILD_JPIP)
188 #-----------------------------------------------------------------------------
189 # opj_config.h generation (2/2)
190 CONFIGURE_FILE("${OPENJPEG_SOURCE_DIR}/opj_config.h.cmake.in"
191 "${OPENJPEG_BINARY_DIR}/opj_config.h"
195 #-----------------------------------------------------------------------------
196 # Build JPWL-flavoured library and executables
197 OPTION(BUILD_JPWL "Build the JPWL library and executables" OFF)
199 #-----------------------------------------------------------------------------
200 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
201 OPTION(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
203 ADD_SUBDIRECTORY(doc)
206 #-----------------------------------------------------------------------------
208 OPTION(BUILD_TESTING "Build the tests." OFF)
214 # Search openjpeg data needed for the tests
215 # They could be found via svn on the OpenJPEG google code project
216 # svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo)
217 FIND_PATH(OPJ_DATA_ROOT README-OPJ-Data
220 ${CMAKE_SOURCE_DIR}/../data
223 # For encoding tests we need the path to the ref decoder exe/lib (kakadu)
224 SET (REF_DECODER_BIN_PATH "NOTFOUND" CACHE PATH "Single directory where find the reference decoder binaries to enable encoding test suite.")
225 MARK_AS_ADVANCED(REF_DECODER_BIN_PATH)
227 # Add repository where to find tests
228 ADD_SUBDIRECTORY(tests)
231 message(FATAL_ERROR "You need build codec to run the tests")
235 #-----------------------------------------------------------------------------
236 # install all targets referenced as OPENJPEGTargets
237 INSTALL(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
238 CONFIGURE_FILE( ${OPENJPEG_SOURCE_DIR}/CMake/OpenJPEGConfig.cmake.in
239 ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
242 INSTALL( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
243 DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
246 #-----------------------------------------------------------------------------
247 # install CHANGES and LICENSE
251 DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})