ENH: do not set ffast-math for all configurations, please
[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 PROJECT(OPENJPEG C)
11 CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
12
13 IF(NOT OPENJPEG_NAMESPACE)
14   SET(OPENJPEG_NAMESPACE "OPENJPEG")
15   SET(OPENJPEG_STANDALONE 1)
16 ENDIF(NOT OPENJPEG_NAMESPACE)
17 # In all cases:
18 STRING(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
19
20 PROJECT(${JPEG_NAMESPACE} C)
21
22 # Do full dependency headers.
23 INCLUDE_REGULAR_EXPRESSION("^.*$")
24
25 #-----------------------------------------------------------------------------
26 # OPENJPEG version number, useful for packaging and doxygen doc:
27 SET(OPENJPEG_VERSION_MAJOR 1)
28 SET(OPENJPEG_VERSION_MINOR 2)
29 SET(OPENJPEG_VERSION_BUILD 0)
30 SET(OPENJPEG_VERSION
31   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}")
32
33 # This setting of SOVERSION assumes that any API change
34 # will increment either the minor or major version number of openjpeg
35 SET(OPENJPEG_LIBRARY_PROPERTIES
36   VERSION   "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}"
37   SOVERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}"
38 )
39
40
41 #-----------------------------------------------------------------------------
42 # OpenJPEG build configuration options.
43 OPTION(BUILD_SHARED_LIBS "Build OpenJPEG with shared libraries." OFF)
44
45 #-----------------------------------------------------------------------------
46 SET (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
47 SET (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
48 MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
49
50
51 #-----------------------------------------------------------------------------
52 # For the codec...
53 OPTION(BUILD_EXAMPLES "Build the Examples (codec...)." OFF)
54
55
56 # configure name mangling to allow multiple libraries to coexist
57 # peacefully
58 IF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
59 SET(MANGLE_PREFIX ${OPENJPEG_LIBRARY_NAME})
60 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in
61                ${CMAKE_CURRENT_BINARY_DIR}/openjpeg_mangle.h
62                @ONLY IMMEDIATE)
63 ENDIF(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg_mangle.h.in)
64
65 #-----------------------------------------------------------------------------
66 # Always build the library
67 INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_BINARY_DIR})
68 SUBDIRS(
69   libopenjpeg
70   mj2
71   # cmake 2.4.5 has poor java support
72   #j2kviewer/src
73   )
74
75 IF(NOT UNIX)
76 SUBDIRS(
77   jpwl
78   jp3d
79   indexer_JPIP
80   )
81 ENDIF(NOT UNIX)
82
83 #-----------------------------------------------------------------------------
84 # Build example only if requested
85 IF(BUILD_EXAMPLES)
86   SUBDIRS(codec)
87 ENDIF(BUILD_EXAMPLES)
88
89 #-----------------------------------------------------------------------------
90 # For the documentation
91 OPTION(BUILD_DOCUMENTATION "Build the doxygen documentation" OFF)
92 IF(BUILD_DOCUMENTATION)
93   SUBDIRS(doc)
94 ENDIF(BUILD_DOCUMENTATION)
95
96 #-----------------------------------------------------------------------------
97 # For openjpeg team if they ever want Dart+CMake
98 IF(OPENJPEG_STANDALONE)
99   INCLUDE(Dart)
100   MARK_AS_ADVANCED(BUILD_TESTING DART_ROOT TCL_TCLSH)
101   IF(BUILD_TESTING)
102     ENABLE_TESTING()
103     SET(BUILDNAME "OpenJPEG-${CMAKE_SYSTEM}-${CMAKE_C_COMPILER}" CACHE STRING "Name of build on the dashboard")
104     MARK_AS_ADVANCED(BUILDNAME)
105   ENDIF(BUILD_TESTING)
106 ENDIF(OPENJPEG_STANDALONE)
107
108 # Adding test with dataset from:
109 # http://www.crc.ricoh.com/~gormish/jpeg2000conformance/
110 # http://www.jpeg.org/jpeg2000guide/testimages/testimages.html
111
112 #-----------------------------------------------------------------------------
113 # Adding JPEG2000_CONFORMANCE_DATA_ROOT
114 FIND_PATH(JPEG2000_CONFORMANCE_DATA_ROOT testimages.html
115   ${OPENJPEG_SOURCE_DIR}/../jpeg2000testimages
116   $ENV{JPEG2000_CONFORMANCE_DATA_ROOT}
117 )
118
119 #-----------------------------------------------------------------------------
120 # Compiler specific flags:
121 IF(CMAKE_COMPILER_IS_GNUCC)
122   # For all builds, make sure openjpeg is std99 compliant:
123   SET(CMAKE_C_FLAGS "-Wall -std=c99 ${CMAKE_C_FLAGS}")
124   # Do not use ffast-math for all build, it would produce incorrect results, only set for release:
125   SET(CMAKE_C_FLAGS_RELEASE "-ffast-math ${CMAKE_C_FLAGS_RELEASE}")
126 ENDIF(CMAKE_COMPILER_IS_GNUCC)
127