[trunk] FolderReorgProposal task: only keep a single build system
[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()
15
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
24 project(${OPENJPEG_NAMESPACE} C)
25
26 # Do full dependency headers.
27 include_regular_expression("^.*$")
28
29 #-----------------------------------------------------------------------------
30 # OPENJPEG version number, useful for packaging and doxygen doc:
31 set(OPENJPEG_VERSION_MAJOR 1)
32 set(OPENJPEG_VERSION_MINOR 99)
33 set(OPENJPEG_VERSION_BUILD 0)
34 set(OPENJPEG_VERSION
35   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
36 set(PACKAGE_VERSION
37   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
38 set(OPENJPEG_LIBRARY_PROPERTIES
39   VERSION   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
40   SOVERSION "${OPENJPEG_VERSION_MAJOR}"
41 )
42
43 # --------------------------------------------------------------------------
44 # Path to additional CMake modules
45 set(CMAKE_MODULE_PATH
46     ${CMAKE_SOURCE_DIR}/cmake
47     ${CMAKE_MODULE_PATH})
48
49 # --------------------------------------------------------------------------
50 # On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
51 # warnings
52 if(WIN32)
53   if(NOT BORLAND)
54     if(NOT CYGWIN)
55       if(NOT MINGW)
56         if(NOT ITK_ENABLE_VISUAL_STUDIO_DEPRECATED_C_WARNINGS)
57           add_definitions(
58             -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
59             -D_CRT_IS_WCTYPE_NO_DEPRECATE
60             -D_CRT_MANAGED_FP_NO_DEPRECATE
61             -D_CRT_NONSTDC_NO_DEPRECATE
62             -D_CRT_SECURE_NO_DEPRECATE
63             -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
64             -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
65             -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
66             -D_CRT_VCCLRIT_NO_DEPRECATE
67             -D_SCL_SECURE_NO_DEPRECATE
68             )
69         endif()
70       endif()
71     endif()
72   endif()
73 endif()
74
75
76 # --------------------------------------------------------------------------
77 # Install directories
78
79 string(TOLOWER ${PROJECT_NAME} projectname)
80 set(OPENJPEG_INSTALL_SUBDIR "${projectname}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")
81
82 if(NOT OPENJPEG_INSTALL_BIN_DIR)
83   set(OPENJPEG_INSTALL_BIN_DIR "bin")
84 endif()
85
86 if(NOT OPENJPEG_INSTALL_LIB_DIR)
87   set(OPENJPEG_INSTALL_LIB_DIR "lib")
88 endif()
89
90 if(NOT OPENJPEG_INSTALL_SHARE_DIR)
91   set(OPENJPEG_INSTALL_SHARE_DIR "share")
92 endif()
93
94 if(NOT OPENJPEG_INSTALL_DATA_DIR)
95   set(OPENJPEG_INSTALL_DATA_DIR "${OPENJPEG_INSTALL_SHARE_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
96 endif()
97
98 if(NOT OPENJPEG_INSTALL_INCLUDE_DIR)
99   set(OPENJPEG_INSTALL_INCLUDE_DIR "include/${OPENJPEG_INSTALL_SUBDIR}")
100 endif()
101
102 if(NOT OPENJPEG_INSTALL_MAN_DIR)
103   set(OPENJPEG_INSTALL_MAN_DIR "share/man/")
104 endif()
105
106 if(NOT OPENJPEG_INSTALL_DOC_DIR)
107   set(OPENJPEG_INSTALL_DOC_DIR "share/doc/${OPENJPEG_INSTALL_SUBDIR}")
108 endif()
109
110 if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
111   # We could install *.cmake files in share/ however those files contains
112   # hardcoded path to libraries on a multi-arch system (fedora/debian) those
113   # path will be different (lib/i386-linux-gnu vs lib/x86_64-linux-gnu)
114   set(OPENJPEG_INSTALL_PACKAGE_DIR "${OPENJPEG_INSTALL_LIB_DIR}/${OPENJPEG_INSTALL_SUBDIR}")
115 endif()
116
117 #-----------------------------------------------------------------------------
118 # Big endian test:
119 include (${CMAKE_ROOT}/Modules/TestBigEndian.cmake)
120 TEST_BIG_ENDIAN(OPJ_BIG_ENDIAN)
121
122 #-----------------------------------------------------------------------------
123 # Setup file for setting custom ctest vars
124 configure_file(
125   ${CMAKE_SOURCE_DIR}/cmake/CTestCustom.cmake.in
126   ${CMAKE_BINARY_DIR}/CTestCustom.cmake
127   @ONLY
128   )
129
130 #-----------------------------------------------------------------------------
131 # OpenJPEG build configuration options.
132 option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
133 set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
134 set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
135 mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
136
137 #-----------------------------------------------------------------------------
138 # configure name mangling to allow multiple libraries to coexist
139 # peacefully
140 if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
141 set(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
142 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
143                ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
144                @ONLY)
145 endif()
146
147 #-----------------------------------------------------------------------------
148 # Compiler specific flags:
149 if(CMAKE_COMPILER_IS_GNUCC)
150   # For all builds, make sure openjpeg is std99 compliant:
151   # set(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
152   # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
153   set(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
154 endif()
155
156 #-----------------------------------------------------------------------------
157 # opj_config.h generation (1/2)
158 include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake)
159 CHECK_INCLUDE_FILE("strings.h"      HAVE_STRINGS_H)
160 CHECK_INCLUDE_FILE("inttypes.h"     HAVE_INTTYPES_H)
161 CHECK_INCLUDE_FILE("memory.h"       HAVE_MEMORY_H)
162 CHECK_INCLUDE_FILE("stdint.h"       HAVE_STDINT_H)
163 CHECK_INCLUDE_FILE("stdlib.h"       HAVE_STDLIB_H)
164 CHECK_INCLUDE_FILE("string.h"       HAVE_STRING_H)
165 CHECK_INCLUDE_FILE("sys/stat.h"     HAVE_SYS_STAT_H)
166 CHECK_INCLUDE_FILE("sys/types.h"    HAVE_SYS_TYPES_H)
167 CHECK_INCLUDE_FILE("unistd.h"       HAVE_UNISTD_H)
168
169 # Enable Large file support
170 include(TestLargeFiles)
171 OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES)
172
173 #-----------------------------------------------------------------------------
174 # Build Library
175 include_directories(BEFORE ${OPENJPEG_BINARY_DIR})
176 add_subdirectory(src)
177
178 #-----------------------------------------------------------------------------
179 # Build Applications
180 option(BUILD_CODEC "Build the CODEC executables" ON)
181 option(BUILD_MJ2 "Build the MJ2 executables." OFF)
182 option(BUILD_JPWL "Build the JPWL library and executables" OFF)
183 option(BUILD_JPIP "Build the JPIP library and executables." OFF)
184 if(BUILD_JPIP)
185   option(BUILD_JPIP_SERVER "Build the JPIP server." OFF)
186 endif()
187 option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
188 option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
189 option(BUILD_JP3D "Build the JP3D comp" OFF)
190 mark_as_advanced(BUILD_VIEWER)
191 mark_as_advanced(BUILD_JAVA)
192 mark_as_advanced(BUILD_JP3D)
193
194 if(BUILD_CODEC OR BUILD_MJ2)
195   # OFF: It will only build 3rd party libs if they are not found on the system
196   # ON: 3rd party libs will ALWAYS be build, and used
197   option(BUILD_THIRDPARTY "Build the thirdparty executables if it is needed" OFF)
198   add_subdirectory(thirdparty)
199   add_subdirectory(src/bin)
200 endif ()
201 add_subdirectory(wrapping)
202
203 include(CheckTypeSize)
204 CHECK_TYPE_SIZE(ssize_t     SSIZE_T)
205
206 #-----------------------------------------------------------------------------
207 # opj_config.h generation (2/2)
208 configure_file("${OPENJPEG_SOURCE_DIR}/opj_config.h.cmake.in"
209  "${OPENJPEG_BINARY_DIR}/opj_config.h"
210  @ONLY
211  )
212 #
213 install( FILES  ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h
214  DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers)
215 #-----------------------------------------------------------------------------
216 # Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
217 option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
218 if(BUILD_DOC)
219   add_subdirectory(doc)
220 endif()
221
222 #-----------------------------------------------------------------------------
223 # Buld Testing
224 option(BUILD_TESTING "Build the tests." OFF)
225 if(BUILD_TESTING)
226   if(BUILD_CODEC)
227     enable_testing()
228     include(CTest)
229
230     # Search openjpeg data needed for the tests
231     # They could be found via svn on the OpenJPEG google code project
232     # svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo)
233     find_path(OPJ_DATA_ROOT README-OPJ-Data
234       PATHS
235       $ENV{OPJ_DATA_ROOT}
236       ${CMAKE_SOURCE_DIR}/../data
237       )
238
239     # Add repository where to find tests
240     add_subdirectory(tests)
241
242   else()
243     message(FATAL_ERROR "You need build codec to run the tests")
244   endif()
245 endif()
246
247 #-----------------------------------------------------------------------------
248 # install all targets referenced as OPENJPEGTargets
249 install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
250 configure_file( ${OPENJPEG_SOURCE_DIR}/cmake/OpenJPEGConfig.cmake.in
251   ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
252   @ONLY
253 )
254 install( FILES ${OPENJPEG_BINARY_DIR}/OpenJPEGConfig.cmake
255   DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR}
256 )
257
258 #-----------------------------------------------------------------------------
259 # install CHANGES and LICENSE
260 if(EXISTS ${OPENJPEG_SOURCE_DIR}/CHANGES)
261   install(FILES CHANGES DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
262 endif()
263 install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR})
264
265 include (cmake/OpenJPEGCPack.cmake)