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