ENH: Added custom configuration for CTest. This allows to fine tune
[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 4)
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
43
44 #-----------------------------------------------------------------------------
45 # OpenJPEG build configuration options.
46 OPTION(BUILD_SHARED_LIBS "Build OpenJPEG with shared libraries." OFF)
47
48 #-----------------------------------------------------------------------------
49 SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
50 SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
51 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
52
53 #-----------------------------------------------------------------------------
54 # Setup file for setting custom ctest vars
55 CONFIGURE_FILE(
56   ${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake.in
57   ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake
58   @ONLY
59   )
60
61 #-----------------------------------------------------------------------------
62 # For the codec...
63 OPTION(BUILD_EXAMPLES "Build the Examples (codec...)." OFF)
64
65
66 # configure name mangling to allow multiple libraries to coexist
67 # peacefully
68 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
69 SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
70 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
71                ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
72                @ONLY IMMEDIATE)
73 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
74
75 #-----------------------------------------------------------------------------
76 # Always build the library
77 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
78 SUBDIRS(
79   libopenjpeg
80   mj2
81   # cmake 2.4.5 has poor java support
82   #j2kviewer/src
83   )
84
85 IF(NOT UNIX)
86 SUBDIRS(
87   jpwl
88   jp3d
89   indexer_JPIP
90   )
91 ENDIF(NOT UNIX)
92
93 #-----------------------------------------------------------------------------
94 # Build example only if requested
95 IF(BUILD_EXAMPLES)
96   SUBDIRS(codec)
97 ENDIF(BUILD_EXAMPLES)
98
99 #-----------------------------------------------------------------------------
100 # For the documentation
101 OPTION(BUILD_DOCUMENTATION "Build the doxygen documentation" OFF)
102 IF(BUILD_DOCUMENTATION)
103   SUBDIRS(doc)
104 ENDIF(BUILD_DOCUMENTATION)
105
106 #-----------------------------------------------------------------------------
107 # For openjpeg team if they ever want Dart+CMake
108 IF(OPENJPEG_STANDALONE)
109   INCLUDE(CTest)
110   #MARK_AS_ADVANCED(BUILD_TESTING DART_ROOT TCL_TCLSH)
111   IF(BUILD_TESTING)
112     ENABLE_TESTING()
113     #SET(BUILDNAME "OpenJPEG-${CMAKE_SYSTEM}-${CMAKE_C_COMPILER}" CACHE STRING "Name of build on the dashboard")
114     MARK_AS_ADVANCED(BUILDNAME)
115   ENDIF(BUILD_TESTING)
116 ENDIF(OPENJPEG_STANDALONE)
117
118 # Adding test with dataset from:
119 # http://www.crc.ricoh.com/~gormish/jpeg2000conformance/
120 # -> wget http://www.crc.ricoh.com/~gormish/jpeg2000conformance/j2kp4files_v1_5.zip
121 # http://www.jpeg.org/jpeg2000guide/testimages/testimages.html
122 #-----------------------------------------------------------------------------
123 # Adding JPEG2000_CONFORMANCE_DATA_ROOT
124 FIND_PATH(JPEG2000_CONFORMANCE_DATA_ROOT testimages.html
125   ${OPENJPEG_SOURCE_DIR}/../jpeg2000testimages
126   $ENV{JPEG2000_CONFORMANCE_DATA_ROOT}
127 )
128
129 #-----------------------------------------------------------------------------
130 # Compiler specific flags:
131 IF(CMAKE_COMPILER_IS_GNUCC)
132   # For all builds, make sure openjpeg is std99 compliant:
133   SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}")
134   # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
135   SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
136 ENDIF(CMAKE_COMPILER_IS_GNUCC)
137