Skip to content
Open
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
87 changes: 20 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
cmake_minimum_required(VERSION 3.16.2)
cmake_minimum_required(VERSION 3.22.0)
project(TotalVariation)

if(ITK_USE_SYSTEM_proxTV)
set(TotalVariation_LIBRARIES proxTV::proxTV)
else()
set(TotalVariation_LIBRARIES proxTV)
endif()

set(${PROJECT_NAME}_THIRD_PARTY 1)
set(TotalVariation_LIBRARIES proxTV::proxTV)


include(itk-module-init.cmake)

Expand All @@ -16,19 +12,12 @@ if(NOT ITK_SOURCE_DIR)
list(APPEND CMAKE_MODULE_PATH ${ITK_CMAKE_DIR})
endif()

include(CMakeParseArguments)
include(FetchContent)

# Compile definition needed for proxTV headers
# This will propagate to wrapping.
# For wrapping to work, requires ITK with patch:
# https://github.com/InsightSoftwareConsortium/ITK/pull/707
add_compile_definitions(NOMATLAB)

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 Eigen3 used in ITK
# Set Eigen3_DIR to the internal Eigen3 used in ITK, per documentation in ITK's Eigen3
set(Eigen3_DIR "${ITKInternalEigen3_DIR}")
message(STATUS "ITKTotalVariation: Using internal ITK Eigen Config found in: ${Eigen3_DIR}")
endif()
Expand All @@ -53,14 +42,12 @@ else()
add_compile_definitions(PROXTV_USE_LAPACK)
endif()

# _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)
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}
Expand All @@ -70,6 +57,14 @@ if(NOT ITK_BINARY_DIR)
find_package(proxTV REQUIRED CONFIG)
endif()
")
# When this module is loaded by an app, it is needed to find proxTV and OpenMP
set(${PROJECT_NAME}_EXPORT_CODE_INSTALL
"${${PROJECT_NAME}_EXPORT_CODE_INSTALL}
find_package(OpenMP)
set(proxTV_DIR \"${proxTV_DIR_INSTALL}\")
find_package(proxTV REQUIRED CONFIG)
")

else() # build proxTV here with the selected Eigen3
# Build proxTV with C++11
if(NOT CMAKE_CXX_STANDARD)
Expand All @@ -81,64 +76,24 @@ else() # build proxTV here with the selected Eigen3
if(NOT CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()

message(STATUS "proxTV_Eigen_LIBRARIES: ${proxTV_Eigen_LIBRARIES}")
set(proxTV_GIT_REPOSITORY "https://github.com/phcerdan/proxTV.git")
set(proxTV_GIT_TAG "use_eigen")
set(proxTV_GIT_TAG "itk_installation")
FetchContent_Declare(
proxtv_fetch
GIT_REPOSITORY ${proxTV_GIT_REPOSITORY}
GIT_TAG ${proxTV_GIT_TAG})
GIT_TAG ${proxTV_GIT_TAG}
FIND_PACKAGE_ARGS NAMES proxTV REQUIRED CONFIG
)
FetchContent_GetProperties(proxTV_fetch)
# proxTV options:
set(Eigen3_DIR "${Eigen3_DIR}") # This is not needed but explicit helps reader.
set(proxTV_USE_LAPACK 0)
if(NOT DEFINED proxTV_INSTALL_INCLUDE_DIR)
if(NOT ITK_SOURCE_DIR)
set(ITK_INSTALL_INCLUDE_DIR include/ITK-${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR})
endif()
set(proxTV_INSTALL_INCLUDE_DIR ${ITK_INSTALL_INCLUDE_DIR}/proxTV)
endif()
if(NOT DEFINED proxTV_INSTALL_LIB_DIR)
if(NOT ITK_SOURCE_DIR)
set(ITK_INSTALL_LIBRARY_DIR lib)
endif()
set(proxTV_INSTALL_LIB_DIR ${ITK_INSTALL_LIBRARY_DIR})
endif()
if(NOT DEFINED proxTV_INSTALL_CMAKE_DIR)
if(NOT ITK_SOURCE_DIR)
set(ITK_INSTALL_PACKAGE_DIR "lib/cmake/ITK-${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}")
endif()
set(proxTV_INSTALL_CMAKE_DIR ${ITK_INSTALL_PACKAGE_DIR}/Modules)
endif()

# end proxTV options

FetchContent_MakeAvailable(proxTV_fetch)
# 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 "${CMAKE_INSTALL_PREFIX}/${proxTV_INSTALL_CMAKE_DIR}")
endif()

# When this module is loaded by an app, load proxTV too.
set(${PROJECT_NAME}_EXPORT_CODE_INSTALL
"${${PROJECT_NAME}_EXPORT_CODE_INSTALL}
find_package(OpenMP)
set(proxTV_DIR \"${proxTV_DIR_INSTALL}\")
find_package(proxTV REQUIRED CONFIG)
")

set(_populate_include_dirs_for_swig TRUE)
if(${_populate_include_dirs_for_swig})
# 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})
itk_module_target(proxTV NAMESPACE proxTV::)
endif()


Expand All @@ -151,5 +106,3 @@ else()
endif()


# Add the proxTV library to Modules/Targets/TotalVariationTargets.cmake
itk_module_target(${_proxTV_lib} NO_INSTALL)
3 changes: 0 additions & 3 deletions itk-module-init.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
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)
Expand Down
5 changes: 1 addition & 4 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ set(TotalVariationTests
itkProxTVImageFilterTest.cxx
)

set(Libraries ${TotalVariation-Test_LIBRARIES})
list(APPEND Libraries ${_proxTV_lib})

CreateTestDriver(TotalVariation "${Libraries}" "${TotalVariationTests}")
CreateTestDriver(TotalVariation "${TotalVariation-Test_LIBRARIES}" "${TotalVariationTests}")

itk_add_test(NAME itkProxTVImageFilterTest
COMMAND TotalVariationTestDriver
Expand Down
Loading