Skip to content

Commit

Permalink
ENH: openjpeg: customize build for ITK integration
Browse files Browse the repository at this point in the history
  • Loading branch information
blowekamp authored and bradking committed Dec 3, 2024
1 parent 1236192 commit 2fe5d73
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Modules/ThirdParty/OpenJPEG/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ project(ITKOpenJPEG)
set(ITKOpenJPEG_THIRD_PARTY 1)

set(ITKOpenJPEG_INCLUDE_DIRS
${ITKOpenJPEG_BINARY_DIR}/src/openjpeg
${ITKOpenJPEG_SOURCE_DIR}/src/openjpeg
${ITKOpenJPEG_SOURCE_DIR}/src/
${ITKOpenJPEG_BINARY_DIR}/src/openjpeg/src/lib/openjp2
${ITKOpenJPEG_SOURCE_DIR}/src/openjpeg/src/lib/openjp2
)
set(ITKOpenJPEG_LIBRARIES itkopenjpeg)
set(ITK_LIBRARY_PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS FALSE)
Expand Down
4 changes: 3 additions & 1 deletion Modules/ThirdParty/OpenJPEG/src/itk_openjpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#ifndef itk_openjpeg_h
#define itk_openjpeg_h

#include <itkopenjpeg/openjpeg.h>
#include <openjpeg/src/lib/openjp2/openjpeg.h>
#include <openjpeg/src/lib/openjp2/opj_includes.h>


#endif
36 changes: 33 additions & 3 deletions Modules/ThirdParty/OpenJPEG/src/openjpeg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
# you will eventually like to prefix the library to avoid linking confusion
# For this purpose you can define a CMake var: OPENJPEG_NAMESPACE to whatever you like
# e.g.:
# set(OPENJPEG_NAMESPACE "GDCMOPENJPEG")
set(OPENJPEG_NAMESPACE "ITKOPENJPEG")
cmake_minimum_required(VERSION 3.5)

if(NOT OPENJPEG_NAMESPACE)
set(OPENJPEG_NAMESPACE "OPENJPEG")
set(OPENJPEG_STANDALONE 1)
endif()
# In all cases:
#string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
set(OPENJPEG_LIBRARY_NAME openjp2)
string(TOLOWER ${OPENJPEG_NAMESPACE} OPENJPEG_LIBRARY_NAME)
#set(OPENJPEG_LIBRARY_NAME openjp2)

project(${OPENJPEG_NAMESPACE} C)

Expand Down Expand Up @@ -103,8 +103,11 @@ endif()
string(TOLOWER ${PROJECT_NAME} PROJECT_NAME)
include(GNUInstallDirs)

#[[ --ITK
# Build DOCUMENTATION (not in ALL target and only if Doxygen is found)
option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF)
# -- ITK ]]
set(BUILD_DOC OFF)

set(OPENJPEG_INSTALL_SUBDIR "${PROJECT_NAME}-${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}")

Expand All @@ -121,7 +124,10 @@ if(NOT OPENJPEG_INSTALL_PACKAGE_DIR)
endif()

if (APPLE)
#[[ --ITK
option(OPJ_USE_DSYMUTIL "Call dsymutil on binaries after build." OFF)
# --ITK ]]
set(OPJ_USE_DSYMUTIL OFF)
endif()

#-----------------------------------------------------------------------------
Expand All @@ -133,19 +139,28 @@ endif()

#-----------------------------------------------------------------------------
# Setup file for setting custom ctest vars
#[[ --ITK
configure_file(
${${OPENJPEG_NAMESPACE}_SOURCE_DIR}/cmake/CTestCustom.cmake.in
${${OPENJPEG_NAMESPACE}_BINARY_DIR}/CTestCustom.cmake
@ONLY
)
# --ITK ]]

#[[ --ITK
#-----------------------------------------------------------------------------
# OpenJPEG build configuration options.
option(BUILD_SHARED_LIBS "Build OpenJPEG shared library and link executables against it." ON)
option(BUILD_STATIC_LIBS "Build OpenJPEG static library." ON)
set (EXECUTABLE_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all executables.")
set (LIBRARY_OUTPUT_PATH ${OPENJPEG_BINARY_DIR}/bin CACHE PATH "Single output directory for building all libraries.")
mark_as_advanced(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH)
# --ITK ]]
if (BUILD_SHARED_LIBS)
set(BUILD_STATIC_LIBS OFF)
else()
set(BUILD_STATIC_LIBS ON)
endif ()

#-----------------------------------------------------------------------------
# configure name mangling to allow multiple libraries to coexist
Expand Down Expand Up @@ -227,6 +242,7 @@ endif()

#-----------------------------------------------------------------------------
# Build Applications
#[[ --ITK
option(BUILD_CODEC "Build the CODEC executables" ON)
option(BUILD_JPIP "Build the JPIP library and executables." OFF)
if(BUILD_JPIP)
Expand All @@ -236,6 +252,12 @@ option(BUILD_VIEWER "Build the OPJViewer executable (C++)" OFF)
option(BUILD_JAVA "Build the openjpeg jar (Java)" OFF)
mark_as_advanced(BUILD_VIEWER)
mark_as_advanced(BUILD_JAVA)
# --ITK ]]
set(BUILD_CODEC OFF)
set(BUILD_JPIP OFF)
set(BUILD_JPIP_SERVER OFF)
set(BUILD_VIEWER OFF)
set(BUILD_JAVA OFF)

if(BUILD_CODEC)
# OFF: It will only build 3rd party libs if they are not found on the system
Expand All @@ -244,7 +266,9 @@ if(BUILD_CODEC)
add_subdirectory(thirdparty)
add_subdirectory(src/bin)
endif ()
#[[ --ITK
add_subdirectory(wrapping)
# --ITK ]]

#-----------------------------------------------------------------------------
# opj_config.h generation (2/2)
Expand All @@ -268,7 +292,10 @@ endif()

#-----------------------------------------------------------------------------
# Build Testing
#[[ --ITK
option(BUILD_TESTING "Build the tests." OFF)
# --ITK ]]
set(BUILD_TESTING OFF)
if(BUILD_TESTING)
if(BUILD_CODEC)
enable_testing()
Expand All @@ -290,6 +317,9 @@ if(BUILD_TESTING)
endif()
endif()

# -- ITK - skip OpenJPEG installation
return()

#-----------------------------------------------------------------------------
# install all targets referenced as OPENJPEGTargets (relocatable with CMake 3.0+)
install(EXPORT OpenJPEGTargets DESTINATION ${OPENJPEG_INSTALL_PACKAGE_DIR})
Expand Down
12 changes: 12 additions & 0 deletions Modules/ThirdParty/OpenJPEG/src/openjpeg/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# required dep for server:
#if(BUILD_JPIP_SERVER)
# find_package(CURL REQUIRED)
# find_package(FCGI REQUIRED)
# find_package(Threads REQUIRED)
# if(NOT CMAKE_USE_PTHREADS_INIT)
# message(FATAL_ERROR "Only pthread are supported")
# endif()
#endif()

#add_subdirectory(lib)
#add_subdirectory(bin)
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ if(BUILD_JPIP)
)
endif()

#[[ -- ITK
option(OPJ_DISABLE_TPSOT_FIX "Disable TPsot==TNsot fix. See https://github.com/uclouvain/openjpeg/issues/254." OFF)
# -- ITK]]
set(OPJ_DISABLE_TPSOT_FIX OFF)
if(OPJ_DISABLE_TPSOT_FIX)
add_definitions(-DOPJ_DISABLE_TPSOT_FIX)
endif()
Expand Down Expand Up @@ -111,19 +114,35 @@ endif()
set_target_properties(${OPENJPEG_LIBRARY_NAME} PROPERTIES ${OPENJPEG_LIBRARY_PROPERTIES})
target_compile_options(${OPENJPEG_LIBRARY_NAME} PRIVATE ${OPENJP2_COMPILE_OPTIONS})

#[[ --ITK
# Install library
install(TARGETS ${INSTALL_LIBS}
EXPORT OpenJPEGTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Applications
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Libraries
)
# --ITK]]

# Install includes files
install(FILES openjpeg.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${OPENJPEG_INSTALL_SUBDIR} COMPONENT Headers
)

# -- ITK Begin
# Apply user-defined properties to the library target.
if(ITK_LIBRARY_PROPERTIES)
set_target_properties(${INSTALL_LIBS} PROPERTIES ${ITK_LIBRARY_PROPERTIES})
endif(ITK_LIBRARY_PROPERTIES)

install(TARGETS ${INSTALL_LIBS}
EXPORT ${ITK3P_INSTALL_EXPORT_NAME}
RUNTIME DESTINATION ${ITK3P_INSTALL_RUNTIME_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${ITK3P_INSTALL_LIBRARY_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${ITK3P_INSTALL_ARCHIVE_DIR} COMPONENT Development
)
#-- ITK End

if(BUILD_DOC)
# install man page of the library
install(
Expand Down Expand Up @@ -171,7 +190,10 @@ endif()
#################################################################################
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)

#[[ -- ITK
option(OPJ_USE_THREAD "Build with thread/mutex support " ON)
# -- ITK]]
set(OPJ_USE_THREAD OFF)
if(NOT OPJ_USE_THREAD)
add_definitions( -DMUTEX_stub)
endif(NOT OPJ_USE_THREAD)
Expand Down

0 comments on commit 2fe5d73

Please sign in to comment.