Skip to content
This repository was archived by the owner on Jun 6, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 37 additions & 32 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set(TotalVariation_LIBRARIES TotalVariation)

set(${PROJECT_NAME}_THIRD_PARTY 1)

include(itk-module-init.cmake)

if(NOT ITK_SOURCE_DIR)
find_package(ITK REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
Expand All @@ -13,11 +15,7 @@ endif()
include(CMakeParseArguments)
include(FetchContent)

# This be here, just in case, in the future we switch to use lapack instead of eigen for proxTV.
option(TotalVariation_proxTV_USE_EIGEN "proxTV in TotalVariation uses EIGEN" ON)
# Add the option to use Eigen3 from outside, or the internal Eigen3 install in ITK.
option(ITK_USE_SYSTEM_EIGEN "Uses external Eigen3, when OFF uses the internal Eigen3 from ITK." OFF)

message(STATUS "TotalVariation_proxTV_USE_EIGEN: ${TotalVariation_proxTV_USE_EIGEN}")
if(TotalVariation_proxTV_USE_EIGEN)
if(NOT ITK_USE_SYSTEM_EIGEN)
# Set Eigen3_DIR to the internal ITKEigen3 module.
Expand All @@ -43,33 +41,22 @@ else()
set(proxTV_USE_LAPACK 1)
endif()

# _proxTV_lib will have `proxTV::proxTV` when find_package, and `proxTV` when add_subdirectory(proxTV_folder)
# _proxTV_lib will be `proxTV::proxTV` when find_package, and `proxTV` when add_subdirectory(proxTV_folder)
set(_proxTV_lib "")
# if proxTV is built elsewhere
if(ITK_USE_SYSTEM_proxTV)
find_package(proxTV REQUIRED CONFIG)
set(_proxTV_lib proxTV::proxTV)

# When this module is loaded by an app, load proxTV too.
set(${PROJECT_NAME}_EXPORT_CODE_INSTALL
"${${PROJECT_NAME}_EXPORT_CODE_INSTALL}
set(proxTV_DIR \"${proxTV_DIR}\")
find_package(proxTV REQUIRED CONFIG)
")
set(proxTV_DIR_INSTALL ${proxTV_DIR})
set(proxTV_DIR_BUILD ${proxTV_DIR})
# It is only needed to EXPORT_CODE_BUILD when using external proxTV
set(${PROJECT_NAME}_EXPORT_CODE_BUILD
"${${PROJECT_NAME}_EXPORT_CODE_BUILD}
if(NOT ITK_BINARY_DIR)
set(proxTV_DIR \"${proxTV_DIR}\")
set(proxTV_DIR \"${proxTV_DIR_BUILD}\")
find_package(proxTV REQUIRED CONFIG)
endif()
")

if(NOT ITK_SOURCE_DIR)
include(ITKModuleExternal)
else()
itk_module_impl()
endif()

else(ITK_USE_SYSTEM_proxTV) # build proxTV here with the selected Eigen3
# Build proxTV with C++11
if(NOT CMAKE_CXX_STANDARD)
Expand All @@ -81,12 +68,9 @@ else(ITK_USE_SYSTEM_proxTV) # build proxTV here with the selected Eigen3
if(NOT CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
set(proxTV_EPNAME ${PROJECT_NAME}_ExtProject)
set(lib_dir ${CMAKE_CURRENT_BINARY_DIR}/${proxTV_EPNAME}-build/lib)

set(proxTV_GIT_REPOSITORY "https://github.com/phcerdan/proxTV.git")
set(proxTV_GIT_TAG "use_eigen")
# itk_download_attempt_check(${proxTV_EPNAME})
FetchContent_Declare(
proxtv_fetch
GIT_REPOSITORY ${proxTV_GIT_REPOSITORY}
Expand All @@ -101,22 +85,43 @@ else(ITK_USE_SYSTEM_proxTV) # build proxTV here with the selected Eigen3
# proxTV will generate a target proxTV::proxTV when using find_package,
# or a library proxTV when using add_subdirectory
set(_proxTV_lib proxTV) # proxTV generated in subdirectory
set(proxTV_DIR_INSTALL "\${ITK_MODULES_DIR}/../proxTV")
endif(ITK_USE_SYSTEM_proxTV)

# Populate module variables
if(NOT ITK_SOURCE_DIR)
include(ITKModuleExternal)
else()
set(ITK_DIR ${CMAKE_BINARY_DIR})
itk_module_impl()
endif()
# When this module is loaded by an app, load proxTV too.
set(${PROJECT_NAME}_EXPORT_CODE_INSTALL
"${${PROJECT_NAME}_EXPORT_CODE_INSTALL}
set(proxTV_DIR \"${proxTV_DIR_INSTALL}\")
find_package(proxTV REQUIRED CONFIG)
")

# SWIG (wrapping) requires INCLUDE_DIRS
get_target_property(proxTV_INCLUDE_DIRS ${_proxTV_lib} INTERFACE_INCLUDE_DIRECTORIES)
string(REGEX REPLACE
".*BUILD_INTERFACE:(.*/proxtv_fetch-build/src/include).*"
"\\1"
proxTV_INCLUDE_DIRS_STRIP
${proxTV_INCLUDE_DIRS})
message(STATUS "proxTV_INCLUDE_DIRS: ${proxTV_INCLUDE_DIRS}")
message(STATUS "proxTV_INCLUDE_DIRS_STRIP: ${proxTV_INCLUDE_DIRS_STRIP}")
set(TotalVariation_INCLUDE_DIRS ${proxTV_INCLUDE_DIRS_STRIP})

# Populate module variables
if(NOT ITK_SOURCE_DIR)
include(ITKModuleExternal)
else()
set(ITK_DIR ${CMAKE_BINARY_DIR})
itk_module_impl()
endif()

endif(ITK_USE_SYSTEM_proxTV)

if(NOT ITK_USE_SYSTEM_proxTV)
set(arg_module_target "")
if(CMAKE_VERSION VERSION_LESS 3.13)
# Hits lack of feature: install TARGETS given target "proxTV" which does not exist in this directory.
# Remote Modules do not have to support installing anyway.
list(APPEND arg_module_target "NO_INSTALL")
endif()
# Add the proxTV library to Modules/Targets/TotalVariationTargets.cmake
itk_module_target(${_proxTV_lib} ${arg_module_target})
endif()
13 changes: 13 additions & 0 deletions itk-module-init.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
option(ITK_USE_SYSTEM_proxTV "Use external proxTV" OFF)
mark_as_advanced(ITK_USE_SYSTEM_proxTV)

option(ITK_USE_SYSTEM_EIGEN "Use External Eigen3" OFF)
mark_as_advanced(ITK_USE_SYSTEM_EIGEN)

# In case in the future we switch to use lapack instead of eigen for proxTV.
option(TotalVariation_proxTV_USE_EIGEN "proxTV in TotalVariation uses EIGEN" ON)
mark_as_advanced(TotalVariation_proxTV_USE_EIGEN)

if(ITK_USE_SYSTEM_proxTV)
find_package(proxTV REQUIRED CONFIG)
endif()
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ set(TotalVariation_SRCS
)

itk_module_add_library(TotalVariation ${TotalVariation_SRCS})
# add_dependencies(TotalVariation ${_proxTV_lib})
# TODO: Remove debug messages
message(STATUS "proxTV_lib: ${_proxTV_lib}")
if(TARGET ${_proxTV_lib})
message(STATUS "proxTV_lib: ${_proxTV_lib} TARGET EXISTS")
else()
message(STATUS "proxTV_lib: ${_proxTV_lib} TARGET DOES NOT EXISTS")
endif()
target_link_libraries(TotalVariation PUBLIC ${_proxTV_lib})