Merge pull request #936 from rouault/master_warnings
[openjpeg.git] / src / lib / openjp2 / CMakeLists.txt
1 include_regular_expression("^.*$")
2
3 #
4 install( FILES  ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h
5  DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers)
6
7 include_directories(
8   ${${OPENJPEG_NAMESPACE}_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h
9 )
10 # Defines the source code for the library
11 set(OPENJPEG_SRCS
12   ${CMAKE_CURRENT_SOURCE_DIR}/thread.c
13   ${CMAKE_CURRENT_SOURCE_DIR}/thread.h
14   ${CMAKE_CURRENT_SOURCE_DIR}/bio.c
15   ${CMAKE_CURRENT_SOURCE_DIR}/bio.h
16   ${CMAKE_CURRENT_SOURCE_DIR}/cio.c
17   ${CMAKE_CURRENT_SOURCE_DIR}/cio.h
18   ${CMAKE_CURRENT_SOURCE_DIR}/dwt.c
19   ${CMAKE_CURRENT_SOURCE_DIR}/dwt.h
20   ${CMAKE_CURRENT_SOURCE_DIR}/event.c
21   ${CMAKE_CURRENT_SOURCE_DIR}/event.h
22   ${CMAKE_CURRENT_SOURCE_DIR}/image.c
23   ${CMAKE_CURRENT_SOURCE_DIR}/image.h
24   ${CMAKE_CURRENT_SOURCE_DIR}/invert.c
25   ${CMAKE_CURRENT_SOURCE_DIR}/invert.h
26   ${CMAKE_CURRENT_SOURCE_DIR}/j2k.c
27   ${CMAKE_CURRENT_SOURCE_DIR}/j2k.h
28   ${CMAKE_CURRENT_SOURCE_DIR}/jp2.c
29   ${CMAKE_CURRENT_SOURCE_DIR}/jp2.h
30   ${CMAKE_CURRENT_SOURCE_DIR}/mct.c
31   ${CMAKE_CURRENT_SOURCE_DIR}/mct.h
32   ${CMAKE_CURRENT_SOURCE_DIR}/mqc.c
33   ${CMAKE_CURRENT_SOURCE_DIR}/mqc.h
34   ${CMAKE_CURRENT_SOURCE_DIR}/mqc_inl.h
35   ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.c
36   ${CMAKE_CURRENT_SOURCE_DIR}/openjpeg.h
37   ${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.c
38   ${CMAKE_CURRENT_SOURCE_DIR}/opj_clock.h
39   ${CMAKE_CURRENT_SOURCE_DIR}/pi.c
40   ${CMAKE_CURRENT_SOURCE_DIR}/pi.h
41   ${CMAKE_CURRENT_SOURCE_DIR}/raw.c
42   ${CMAKE_CURRENT_SOURCE_DIR}/raw.h
43   ${CMAKE_CURRENT_SOURCE_DIR}/t1.c
44   ${CMAKE_CURRENT_SOURCE_DIR}/t1.h
45   ${CMAKE_CURRENT_SOURCE_DIR}/t2.c
46   ${CMAKE_CURRENT_SOURCE_DIR}/t2.h
47   ${CMAKE_CURRENT_SOURCE_DIR}/tcd.c
48   ${CMAKE_CURRENT_SOURCE_DIR}/tcd.h
49   ${CMAKE_CURRENT_SOURCE_DIR}/tgt.c
50   ${CMAKE_CURRENT_SOURCE_DIR}/tgt.h
51   ${CMAKE_CURRENT_SOURCE_DIR}/function_list.c
52   ${CMAKE_CURRENT_SOURCE_DIR}/function_list.h
53   ${CMAKE_CURRENT_SOURCE_DIR}/opj_codec.h
54   ${CMAKE_CURRENT_SOURCE_DIR}/opj_includes.h
55   ${CMAKE_CURRENT_SOURCE_DIR}/opj_intmath.h
56   ${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.c
57   ${CMAKE_CURRENT_SOURCE_DIR}/opj_malloc.h
58   ${CMAKE_CURRENT_SOURCE_DIR}/opj_stdint.h
59 )
60 if(BUILD_JPIP)
61   add_definitions(-DUSE_JPIP)
62   set(OPENJPEG_SRCS
63     ${OPENJPEG_SRCS}
64     ${CMAKE_CURRENT_SOURCE_DIR}/cidx_manager.c
65     ${CMAKE_CURRENT_SOURCE_DIR}/cidx_manager.h
66     ${CMAKE_CURRENT_SOURCE_DIR}/phix_manager.c
67     ${CMAKE_CURRENT_SOURCE_DIR}/ppix_manager.c
68     ${CMAKE_CURRENT_SOURCE_DIR}/thix_manager.c
69     ${CMAKE_CURRENT_SOURCE_DIR}/tpix_manager.c
70     ${CMAKE_CURRENT_SOURCE_DIR}/indexbox_manager.h
71   )
72 endif()
73
74 option(OPJ_DISABLE_TPSOT_FIX "Disable TPsot==TNsot fix. See https://github.com/uclouvain/openjpeg/issues/254." OFF)
75 if(OPJ_DISABLE_TPSOT_FIX)
76   add_definitions(-DOPJ_DISABLE_TPSOT_FIX)
77 endif()
78
79 # Special case for old i586-mingw32msvc-gcc cross compiler
80 if(NOT WIN32 AND CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER MATCHES ".*mingw32msvc.*" )
81   set(WIN32 YES)
82 endif()
83
84 # Build the library
85 if(WIN32)
86   if(BUILD_SHARED_LIBS)
87     add_definitions(-DOPJ_EXPORTS)
88   else()
89     add_definitions(-DOPJ_STATIC)
90   endif()
91 endif()
92 add_library(${OPENJPEG_LIBRARY_NAME} ${OPENJPEG_SRCS})
93 if(UNIX)
94   target_link_libraries(${OPENJPEG_LIBRARY_NAME} m)
95 endif()
96 set_target_properties(${OPENJPEG_LIBRARY_NAME} PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
97 if(${CMAKE_VERSION} VERSION_GREATER "2.8.11")
98   target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJP2_COMPILE_OPTIONS})
99 endif()
100
101 # Install library
102 install(TARGETS ${OPENJPEG_LIBRARY_NAME}
103   EXPORT OpenJPEGTargets
104   RUNTIME DESTINATION ${OPENJPEG_INSTALL_BIN_DIR} COMPONENT Applications
105   LIBRARY DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
106   ARCHIVE DESTINATION ${OPENJPEG_INSTALL_LIB_DIR} COMPONENT Libraries
107 )
108
109 # Install includes files
110 install(FILES openjpeg.h opj_stdint.h
111   DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers
112 )
113
114 if(BUILD_DOC)
115 # install man page of the library
116 install(
117   FILES       ${OPENJPEG_SOURCE_DIR}/doc/man/man3/libopenjp2.3
118   DESTINATION ${OPENJPEG_INSTALL_MAN_DIR}/man3)
119 endif()
120
121 if(BUILD_LUTS_GENERATOR)
122 # internal utility to generate t1_luts.h (part of the jp2 lib)
123 # no need to install:
124   add_executable(t1_generate_luts t1_generate_luts.c)
125   if(UNIX)
126     target_link_libraries(t1_generate_luts m)
127   endif()
128 endif()
129
130 # Experimental option; let's how cppcheck performs
131 # Implementation details:
132 # I could not figure out how to easily upload a file to CDash. Instead simply
133 # pretend cppcheck is part of the Build step. Technically cppcheck can even
134 # output gcc formatted error/warning report
135 # Another implementation detail: I could not redirect error to the error
136 # catching mechanism something is busted in cmake 2.8.5, I had to use the
137 # warning regex to catch them.
138 if(OPENJPEG_CPPCHECK)
139   find_package(CPPCHECK REQUIRED)
140   foreach(f ${OPENJPEG_SRCS})
141     # cppcheck complains about too many configuration, pretend to be WIN32:
142     add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME}
143       COMMAND ${CPPCHECK_EXECUTABLE} -DWIN32 ${f})
144   endforeach()
145 endif()
146
147 if(OPJ_USE_DSYMUTIL)
148   if(BUILD_SHARED_LIBS)
149     add_custom_command(TARGET ${OPENJPEG_LIBRARY_NAME} POST_BUILD
150     COMMAND "dsymutil" "$<TARGET_SONAME_FILE:${OPENJPEG_LIBRARY_NAME}>"
151     COMMENT "dsymutil $<TARGET_SONAME_FILE:${OPENJPEG_LIBRARY_NAME}>"
152     DEPENDS ${OPENJPEG_LIBRARY_NAME})
153   endif()
154 endif()
155
156 #################################################################################
157 # threading configuration
158 #################################################################################
159 set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
160
161 option(OPJ_USE_THREAD "Build with thread/mutex support " ON)
162 if(NOT OPJ_USE_THREAD)
163    add_definitions( -DMUTEX_stub)
164 endif(NOT OPJ_USE_THREAD)
165
166 find_package(Threads QUIET)
167
168 if(OPJ_USE_THREAD AND WIN32 AND NOT Threads_FOUND )
169     add_definitions( -DMUTEX_win32)
170     set(Threads_FOUND YES)
171 endif()
172
173 if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_WIN32_THREADS_INIT )
174    add_definitions( -DMUTEX_win32)
175 endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_WIN32_THREADS_INIT )
176
177 if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT )
178    add_definitions( -DMUTEX_pthread)
179 endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT )
180
181 if(OPJ_USE_THREAD AND NOT Threads_FOUND)
182   message(FATAL_ERROR "No thread library found and thread/mutex support is required by OPJ_USE_THREAD option")
183 endif(OPJ_USE_THREAD AND NOT Threads_FOUND)
184
185 if(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
186    TARGET_LINK_LIBRARIES(${OPENJPEG_LIBRARY_NAME} ${CMAKE_THREAD_LIBS_INIT})
187 endif(OPJ_USE_THREAD AND Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)