Merge pull request #1518 from dg0yt/static-windows
[openjpeg.git] / INSTALL.md
1
2 # OpenJPEG installation
3
4 The build method maintained by OpenJPEG is [CMake](https://cmake.org/).
5
6 ## UNIX/LINUX - MacOS (terminal) - WINDOWS (cygwin, MinGW)
7
8 To build the library, type from source tree directory:
9 ```
10 mkdir build
11 cd build
12 cmake .. -DCMAKE_BUILD_TYPE=Release
13 make
14 ```
15 Binaries are then located in the 'bin' directory.
16
17 To install the library, type with root privileges:
18 ```
19 make install
20 make clean
21 ```
22
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)
25 ```
26 make doc
27 ```
28
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):
40 ```
41 cmake . -DBUILD_TESTING:BOOL=ON -DOPJ_DATA_ROOT:PATH='path/to/the/data/directory' -DBUILDNAME:STRING='name_of_the_build'
42 make
43 make Experimental
44 ```
45 Note : test data is available on the following github repo: https://github.com/uclouvain/openjpeg-data
46
47 If '-DOPJ\_DATA\_ROOT:PATH' option is omitted, test files will be automatically searched in '${CMAKE\_SOURCE\_DIR}/../data'.
48
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.
50
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:
52 ```
53 sudo apt-get install liblcms2-dev  libtiff-dev libpng-dev libz-dev
54 ```
55
56 Note 4 : On MacOS, if it does not work, try adding the following flag to the cmake command :
57 ```
58 -DCMAKE_OSX_ARCHITECTURES:STRING=i386
59 ```
60
61 ## MacOS (XCode) - WINDOWS (VisualStudio, etc)
62
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.
65
66 Examples for Windows with Visual Studio C++ compiler:
67
68 If using directly the cl compiler:
69
70 ```
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" ..
72 ```
73
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).
75
76
77 If you do not want directly use the cl compiler, you could use:
78
79 ```
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" ..
81 ```
82
83 To create Visual Studio solution (.sln) and project files (.vcproj / .vcxproj):
84 ```
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" ..
86 ```
87
88 64-bit application:
89 ```
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" ..
91 ```
92
93
94 # Enabling CPU specific optimizations
95
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
101 CPUs)
102
103 With gcc/clang, it is possible to enable those instruction sets with the following :
104
105 ```
106 cmake -DCMAKE_C_FLAGS="-O3 -msse4.1 -DNDEBUG" ..
107 ```
108
109 ```
110 cmake -DCMAKE_C_FLAGS="-O3 -mavx2 -DNDEBUG" ..
111 ```
112
113 (AVX2 implies SSE4.1)
114
115 Or if the binary is dedicated to run on the machine where it has
116 been compiled :
117
118 ```
119 cmake -DCMAKE_C_FLAGS="-O3 -march=native -DNDEBUG" ..
120 ```
121
122 # Modifying OpenJPEG
123
124 Before committing changes, run:
125 ```scripts/prepare-commit.sh```
126
127 # Using OpenJPEG
128
129 To use openjpeg exported cmake file, simply create your application doing:
130
131 ```
132 $ cat CMakeLists.txt
133 find_package(OpenJPEG REQUIRED)
134 include_directories(${OPENJPEG_INCLUDE_DIRS})
135 add_executable(myapp myapp.c)
136 target_link_libraries(myapp ${OPENJPEG_LIBRARIES})
137 ```