Merge pull request #1503 from domin144/drop_cmake_less_3.5
[openjpeg.git] / src / bin / jp2 / CMakeLists.txt
1 # Build the demo app, small examples
2
3 # First thing define the common source:
4 set(common_SRCS
5   convert.c
6   convert.h
7   convertbmp.c
8   index.c
9   index.h
10   ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c
11   ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.h
12   ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c
13   ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h
14   ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_string.h
15   )
16
17 if(OPJ_HAVE_LIBTIFF)
18         list(APPEND common_SRCS converttif.c)
19 endif()
20 if(OPJ_HAVE_LIBPNG)
21         list(APPEND common_SRCS convertpng.c)
22 endif()
23
24 # Headers file are located here:
25 include_directories(
26   ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h
27   ${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h
28   ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2
29   ${OPENJPEG_SOURCE_DIR}/src/bin/common
30   ${LCMS_INCLUDE_DIRNAME}
31   ${Z_INCLUDE_DIRNAME}
32   ${PNG_INCLUDE_DIRNAME}
33   ${TIFF_INCLUDE_DIRNAME}
34   )
35
36 if(WIN32)
37   if(BUILD_SHARED_LIBS)
38     add_definitions(-DOPJ_EXPORTS)
39   else()
40     add_definitions(-DOPJ_STATIC)
41   endif()
42 endif()
43
44 # Loop over all executables:
45 foreach(exe opj_decompress opj_compress opj_dump)
46   add_executable(${exe} ${exe}.c ${common_SRCS})
47   target_compile_options(${exe} PRIVATE ${OPENJP2_COMPILE_OPTIONS})
48   target_link_libraries(${exe} ${OPENJPEG_LIBRARY_NAME}
49     ${PNG_LIBNAME} ${TIFF_LIBNAME} ${LCMS_LIBNAME}
50     )
51   # To support universal exe:
52   if(ZLIB_FOUND AND APPLE)
53     target_link_libraries(${exe} z)
54   else(ZLIB_FOUND AND APPLE)
55     target_link_libraries(${exe} ${Z_LIBNAME})
56   endif()
57
58   # On unix you need to link to the math library:
59   if(UNIX)
60     target_link_libraries(${exe} m)
61     IF("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
62       target_link_libraries(${exe} rt)
63     endif()
64   endif()
65   # Install exe
66   install(TARGETS ${exe}
67     EXPORT OpenJPEGTargets
68     DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
69   )
70   if(OPJ_USE_DSYMUTIL)
71     add_custom_command(TARGET ${exe} POST_BUILD
72     COMMAND "dsymutil" "$<TARGET_FILE:${exe}>"
73     COMMENT "dsymutil $<TARGET_FILE:${exe}>"
74     DEPENDS ${exe})
75   endif()
76 endforeach()
77
78 if(BUILD_DOC)
79 # Install man pages
80 install(
81   FILES       ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_compress.1
82               ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_decompress.1
83               ${OPENJPEG_SOURCE_DIR}/doc/man/man1/opj_dump.1
84   DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
85 #
86 endif()