27203d9cef6364395e840cc6afdbf0ffa16e2f24
[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.4)
11
12 IF(NOT OPENJPEG_NAMESPACE)
13   SET(OPENJPEG_NAMESPACE "OPENJPEG")
14   SET(OPENJPEG_STANDALONE 1)
15 ENDIF(NOT OPENJPEG_NAMESPACE)
16 # In all cases:
17 STRING(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
18
19 IF(COMMAND CMAKE_POLICY)
20   CMAKE_POLICY(SET CMP0003 NEW)
21 ENDIF(COMMAND CMAKE_POLICY)
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 #-----------------------------------------------------------------------------
75 # Test for some required system information.
76 INCLUDE (${CMAKE_ROOT}/Modules/CMakeBackwardCompatibilityC.cmake)
77
78 #-----------------------------------------------------------------------------
79 # Setup file for setting custom ctest vars
80 CONFIGURE_FILE(
81   ${CMAKE_CURRENT_SOURCE_DIR}/CMake/CTestCustom.cmake.in
82   ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
83   @ONLY
84   )
85
86 #-----------------------------------------------------------------------------
87 # OpenJPEG build configuration options.
88 OPTION(BUILD_SHARED_LIBS "Build OpenJPEG with shared libraries." OFF)
89 OPTION(ENABLE_PROFILING "Enable profiling for the library" OFF)
90
91 #-----------------------------------------------------------------------------
92 SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
93 SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
94 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
95
96
97 #-----------------------------------------------------------------------------
98 # For the codec...
99 OPTION(BUILD_EXAMPLES "Build the Examples (codec...)." OFF)
100
101
102 # configure name mangling to allow multiple libraries to coexist
103 # peacefully
104 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
105 SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
106 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
107                ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
108                @ONLY IMMEDIATE)
109 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
110
111 #-----------------------------------------------------------------------------
112 # Configure files with settings for use by the build.
113 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/opj_configure.h.in 
114                ${CMAKE_CURRENT_BINARY_DIR}/opj_configure.h)
115
116
117 #-----------------------------------------------------------------------------
118 # Always build the library
119 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
120 SUBDIRS(
121   libopenjpeg
122   # mj2
123   #j2kviewer/src
124   )
125 IF(BUILD_EXAMPLES)
126   SUBDIRS(codec)
127 ENDIF(BUILD_EXAMPLES)
128
129 #IF(NOT UNIX)
130 #SUBDIRS(
131 #  jpwl
132 #  jp3d
133 #  indexer_JPIP
134 #  )
135 #ENDIF(NOT UNIX)
136
137 #-----------------------------------------------------------------------------
138 # For the documentation
139 OPTION(BUILD_DOCUMENTATION "Build the doxygen documentation" OFF)
140 IF(BUILD_DOCUMENTATION)
141   SUBDIRS(doc)
142 ENDIF(BUILD_DOCUMENTATION)
143
144 #-----------------------------------------------------------------------------
145 # For openjpeg team if they ever want CDash+CMake
146 OPTION(BUILD_TESTING "Build the tests." OFF)
147 IF(BUILD_TESTING)
148   ENABLE_TESTING()
149   INCLUDE(CTest)
150 ENDIF(BUILD_TESTING)
151
152 IF(BUILD_TESTING)
153   SUBDIRS(
154     test_V2_tile_handling
155     test_Free_image_V2_tile_handling
156   )
157 ENDIF(BUILD_TESTING)
158
159 # Adding test with dataset from:
160 # http://www.crc.ricoh.com/~gormish/jpeg2000conformance/
161 # http://www.jpeg.org/jpeg2000guide/testimages/testimages.html
162
163 #-----------------------------------------------------------------------------
164 # Adding JPEG2000_CONFORMANCE_DATA_ROOT
165 FIND_PATH(JPEG2000_CONFORMANCE_DATA_ROOT testimages.html
166   ${OPENJPEG_SOURCE_DIR}/../jpeg2000testimages
167   $ENV{JPEG2000_CONFORMANCE_DATA_ROOT}
168 )
169
170 #-----------------------------------------------------------------------------
171 # Compiler specific flags:
172 IF(CMAKE_COMPILER_IS_GNUCC)
173   # For all builds, make sure openjpeg is std99 compliant:
174   # SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}") # FIXME: this setting prevented us from setting a coverage build.
175   # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
176   SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
177 ENDIF(CMAKE_COMPILER_IS_GNUCC)
178