2 # OpenJPEG installation
4 The build method maintained by OpenJPEG is [CMake](https://cmake.org/).
6 ## UNIX/LINUX - MacOS (terminal) - WINDOWS (cygwin, MinGW)
8 To build the library, type from source tree directory:
12 cmake .. -DCMAKE_BUILD_TYPE=Release
15 Binaries are then located in the 'bin' directory.
17 To install the library, type with root privileges:
23 To build the html documentation, you need doxygen to be installed on your system.
24 It will create an "html" directory in TOP\_LEVEL/build/doc)
29 Main available cmake flags:
30 * To specify the install path: '-DCMAKE\_INSTALL\_PREFIX=/path'
31 * To build the shared libraries and links the executables against it: '-DBUILD\_SHARED\_LIBS:bool=on' (default: 'ON')
32 > Note: when using this option, static libraries are not built and executables are dynamically linked.
33 * To build the CODEC executables: '-DBUILD\_CODEC:bool=on' (default: 'ON')
34 * To build opjstyle (internal version of astyle) for OpenJPEG development: '-DWITH_ASTYLE=ON'
35 * [OBSOLETE] To build the MJ2 executables: '-DBUILD\_MJ2:bool=on' (default: 'OFF')
36 * [OBSOLETE] To build the JPWL executables and JPWL library: '-DBUILD\_JPWL:bool=on' (default: 'OFF')
37 * [OBSOLETE] To build the JPIP client (java compiler recommended) library and executables: '-DBUILD\_JPIP:bool=on' (default: 'OFF')
38 * [OBSOLETE] To build the JPIP server (need fcgi) library and executables: '-DBUILD\_JPIP\_SERVER:bool=on' (default: 'OFF')
39 * To enable testing (and automatic result upload to http://my.cdash.org/index.php?project=OPENJPEG):
41 cmake . -DBUILD_TESTING:BOOL=ON -DOPJ_DATA_ROOT:PATH='path/to/the/data/directory' -DBUILDNAME:STRING='name_of_the_build'
45 Note : test data is available on the following github repo: https://github.com/uclouvain/openjpeg-data
47 If '-DOPJ\_DATA\_ROOT:PATH' option is omitted, test files will be automatically searched in '${CMAKE\_SOURCE\_DIR}/../data'.
49 Note 2 : to execute the encoding test suite, kakadu binaries are needed to decode encoded image and compare it to the baseline. Kakadu binaries are freely available for non-commercial purposes at http://www.kakadusoftware.com. kdu\_expand will need to be in your PATH for cmake to find it.
51 Note 3 : OpenJPEG encoder and decoder (not the library itself !) depends on several libraries: png, tiff, lcms, z. If these libraries are not found on the system, they are automatically built from the versions available in the source tree. You can force the use of these embedded version with BUILD\_THIRDPARTY:BOOL=ON. On a Debian-like system you can also simply install these libraries with:
53 sudo apt-get install liblcms2-dev libtiff-dev libpng-dev libz-dev
56 Note 4 : On MacOS, if it does not work, try adding the following flag to the cmake command :
58 -DCMAKE_OSX_ARCHITECTURES:STRING=i386
61 ## MacOS (XCode) - WINDOWS (VisualStudio, etc)
63 You can use cmake to generate the project files for the IDE you are using (VC2010, XCode, etc).
64 Type `cmake --help` for available generators on your platform.
66 Examples for Windows with Visual Studio C++ compiler:
68 If using directly the cl compiler:
71 cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" ..
74 To compile a 64-bit application, open 64-Bit Visual C\+\+ toolset on the command line and run cmake. For further information, please refer to: [How to: Enable a 64-Bit Visual C\+\+ Toolset on the Command Line](https://msdn.microsoft.com/en-us/library/x4d2c09s.aspx).
77 If you do not want directly use the cl compiler, you could use:
80 cmake -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" ..
83 To create Visual Studio solution (.sln) and project files (.vcproj / .vcxproj):
85 cmake -G "Visual Studio 14 2015" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" ..
90 cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE:string="Release" -DBUILD_SHARED_LIBS:bool=on -DCMAKE_INSTALL_PREFIX:path="%USERPROFILE%" -DCMAKE_LIBRARY_PATH:path="%USERPROFILE%" -DCMAKE_INCLUDE_PATH:path="%USERPROFILE%\include" ..
94 # Enabling CPU specific optimizations
96 For Intel/AMD processors, OpenJPEG implements optimizations using the SSE4.1
97 instruction set (for example, for the 9x7 inverse MCT transform) and the AVX2
98 instruction set (for example, for the 5x3 inverse discrete wavelet transform).
99 Currently, those optimizations are only available if OpenJPEG is built to
100 use those instruction sets (and the resulting binary will only run on compatible
103 With gcc/clang, it is possible to enable those instruction sets with the following :
106 cmake -DCMAKE_C_FLAGS="-O3 -msse4.1 -DNDEBUG" ..
110 cmake -DCMAKE_C_FLAGS="-O3 -mavx2 -DNDEBUG" ..
113 (AVX2 implies SSE4.1)
115 Or if the binary is dedicated to run on the machine where it has
119 cmake -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG" ..
124 Before committing changes, run:
125 ```scripts/prepare-commit.sh```
129 To use openjpeg exported cmake file, simply create your application doing:
133 find_package(OpenJPEG REQUIRED)
134 include_directories(${OPENJPEG_INCLUDE_DIRS})
135 add_executable(myapp myapp.c)
136 target_link_libraries(myapp ${OPENJPEG_LIBRARIES})