The lrintf function should use "long" instead of "int"
[openjpeg.git] / CMakeLists.txt
1 # Main CMakeLists.txt to build the OpenJPEG project using CMake (www.cmake.org)
2 # Written by Mathieu Malaterre
3
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
8 # e.g.:
9 # SET(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
10 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
11
12 IF(COMMAND CMAKE_POLICY)
13   CMAKE_POLICY(SET CMP0003 NEW)
14 ENDIF(COMMAND CMAKE_POLICY)
15
16 IF(NOT OPENJPEG_NAMESPACE)
17   SET(OPENJPEG_NAMESPACE "OPENJPEG")
18   SET(OPENJPEG_STANDALONE 1)
19 ENDIF(NOT OPENJPEG_NAMESPACE)
20 # In all cases:
21 STRING(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
22
23 PROJECT(${OPENJPEG_NAMESPACE} C)
24
25 # Do full dependency headers.
26 INCLUDE_REGULAR_EXPRESSION("^.*$")
27
28 #-----------------------------------------------------------------------------
29 # OPENJPEG version number, useful for packaging and doxygen doc:
30 SET(OPENJPEG_VERSION_MAJOR 2)
31 SET(OPENJPEG_VERSION_MINOR 0)
32 SET(OPENJPEG_VERSION_BUILD 0)
33 SET(OPENJPEG_VERSION
34   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
35
36 # This setting of SOVERSION assumes that any API change
37 # will increment either the minor or major version number of openjpeg
38 SET(OPENJPEG_LIBRARY_PROPERTIES
39   VERSION   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
40   SOVERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}"
41 )
42 # You will also need to define a value for the following variables:
43 # OPENJPEG_INSTALL_BIN_DIR          - binary dir (executables)
44 # OPENJPEG_INSTALL_LIB_DIR          - library dir (libs)
45 # OPENJPEG_INSTALL_DATA_DIR         - share dir (say, examples, data, etc)
46 # OPENJPEG_INSTALL_INCLUDE_DIR      - include dir (headers)
47
48 # --------------------------------------------------------------------------
49 # Install directories
50
51 STRING(TOLOWER ${PROJECT_NAME} projectname)
52 SET(subdir "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
53
54 IF(NOT OPENJPEG_INSTALL_BIN_DIR)
55   SET(OPENJPEG_INSTALL_BIN_DIR "bin")
56 ENDIF(NOT OPENJPEG_INSTALL_BIN_DIR)
57
58 IF(NOT OPENJPEG_INSTALL_LIB_DIR)
59   SET(OPENJPEG_INSTALL_LIB_DIR "lib")
60 ENDIF(NOT OPENJPEG_INSTALL_LIB_DIR)
61
62 IF(NOT OPENJPEG_INSTALL_DATA_DIR)
63   SET(OPENJPEG_INSTALL_DATA_DIR "share/${subdir}")
64 ENDIF(NOT OPENJPEG_INSTALL_DATA_DIR)
65
66 IF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
67   SET(OPENJPEG_INSTALL_INCLUDE_DIR "include/${subdir}")
68 ENDIF(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
69
70 IF(NOT OPENJPEG_INSTALL_DOC_DIR)
71   SET(OPENJPEG_INSTALL_DOC_DIR "share/doc/${subdir}")
72 ENDIF(NOT OPENJPEG_INSTALL_DOC_DIR)
73
74 IF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
75   SET(OPENJPEG_INSTALL_PACKAGE_DIR ${OPENJPEG_INSTALL_LIB_DIR}/${subdir}
76     CACHE INTERNAL "")
77 ENDIF(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
78
79 #-----------------------------------------------------------------------------
80 # Test for some required system information.
81 INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
82
83 #-----------------------------------------------------------------------------
84 # Setup file for setting custom ctest vars
85 CONFIGURE_FILE(
86   ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CTestCustom.cmake.in
87   ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
88   @ONLY
89   )
90
91 #-----------------------------------------------------------------------------
92 # OpenJPEG build configuration options.
93 OPTION(BUILD_SHARED_LIBS "Build OpenJPEG with shared libraries." OFF)
94 OPTION(ENABLE_PROFILING "Enable profiling for the library" OFF)
95
96 #-----------------------------------------------------------------------------
97 SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
98 SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
99 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
100
101
102 #-----------------------------------------------------------------------------
103 # For the codec...
104 OPTION(BUILD_EXAMPLES "Build the Examples (codec...)." OFF)
105
106
107 # configure name mangling to allow multiple libraries to coexist
108 # peacefully
109 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
110 SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
111 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
112                ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
113                @ONLY IMMEDIATE)
114 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
115
116 #-----------------------------------------------------------------------------
117 # Configure files with settings for use by the build.
118 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/opj_configure.h.in 
119                ${CMAKE_CURRENT_BINARY_DIR}/opj_configure.h)
120
121
122 #-----------------------------------------------------------------------------
123 # Always build the library
124 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
125 SUBDIRS(
126   libopenjpeg
127   # mj2
128   #j2kviewer/src
129   )
130
131 #IF(NOT UNIX)
132 #SUBDIRS(
133 #  jpwl
134 #  jp3d
135 #  indexer_JPIP
136 #  )
137 #ENDIF(NOT UNIX)
138
139 #-----------------------------------------------------------------------------
140 # Build example only if requested
141 IF(BUILD_EXAMPLES)
142   SUBDIRS(codec)
143 ENDIF(BUILD_EXAMPLES)
144
145 #-----------------------------------------------------------------------------
146 # For the documentation
147 OPTION(BUILD_DOCUMENTATION "Build the doxygen documentation" OFF)
148 IF(BUILD_DOCUMENTATION)
149   SUBDIRS(doc)
150 ENDIF(BUILD_DOCUMENTATION)
151
152 #-----------------------------------------------------------------------------
153 # For openjpeg team if they ever want CDash+CMake
154 OPTION(BUILD_TESTING "Build the tests." OFF)
155 IF(BUILD_TESTING)
156   ENABLE_TESTING()
157   INCLUDE(CTest)
158 ENDIF(BUILD_TESTING)
159
160 IF(BUILD_TESTING)
161 SET(CMAKE_MODULE_PATH "${OPENJPEG_SOURCE_DIR}/CMake")
162 FIND_PACKAGE(FreeImage REQUIRED)
163 INCLUDE_DIRECTORIES( ${FREEIMAGE_INCLUDE_PATH} )
164
165   SUBDIRS(
166     test_V2_tile_handling
167     test_Free_image_V2_tile_handling
168   )
169 ENDIF(BUILD_TESTING)
170
171 # Adding test with dataset from:
172 # http://www.crc.ricoh.com/~gormish/jpeg2000conformance/
173 # -> wget http://www.crc.ricoh.com/~gormish/jpeg2000conformance/j2kp4files_v1_5.zip
174 # http://www.jpeg.org/jpeg2000guide/testimages/testimages.html
175 #-----------------------------------------------------------------------------
176 # Adding JPEG2000_CONFORMANCE_DATA_ROOT
177 FIND_PATH(JPEG2000_CONFORMANCE_DATA_ROOT testimages.html
178   ${OPENJPEG_SOURCE_DIR}/../jpeg2000testimages
179   $ENV{JPEG2000_CONFORMANCE_DATA_ROOT}
180 )
181
182 #-----------------------------------------------------------------------------
183 # Compiler specific flags:
184 IF(CMAKE_COMPILER_IS_GNUCC)
185   # For all builds, make sure openjpeg is std99 compliant:
186   # SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
187   # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
188   SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
189 ENDIF(CMAKE_COMPILER_IS_GNUCC)
190
191 # install all targets referenced as OPENJPEGTargets
192 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
193 CONFIGURE_FILE( ${OPENJPEG_SOURCE_DIR}/CMake/OpenJPEGConfig.cmake.in
194   ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
195   @ONLY
196 )
197 INSTALL( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
198   DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
199 )
200