Commit 4c58fa39 authored by Kasper Marstal's avatar Kasper Marstal
Browse files

COMP: Add modular build system for applications

parent b1cc9fb5
......@@ -17,6 +17,9 @@
#
#=========================================================================
# This CMakeLists.txt allows the Applications directory to be built as an
# external project.
cmake_minimum_required( VERSION 3.0.2 )
project(SuperElastixApplications)
......@@ -50,9 +53,8 @@ if( NOT CMAKE_PROJECT_NAME STREQUAL "SuperElastix" )
find_package( ITK )
include( ${ITK_USE_FILE} )
message( STATUS "ELASTIX_USE_FILE: ${ELASTIX_USE_FILE}")
include( ${ELASTIX_USE_FILE} )
endif()
add_subdirectory( CommandlineProgram )
\ No newline at end of file
add_subdirectory( SuperElastixCommandLineInterface )
\ No newline at end of file
......@@ -17,15 +17,30 @@
#
#=========================================================================
set( CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
set( APPLICATION ApplicationSuperElastixCLI )
set( ${APPLICATION}_TARGET_NAME SuperElastix )
set( ${APPLICATION}_SOURCE_FILES
${${APPLICATION}_SOURCE_DIR}/src/selxSuperElastix.cxx
)
set( ${APPLICATION}_LINK_LIBRARIES
${ITK_LIBRARIES}
elastix transformix
${Boost_LIBRARIES}
)
set( ${APPLICATION}_MODULE_DEPENDENCIES
ModuleCore
ModuleController
ModuleElastix
ModuleExamples
ModuleItkImageRegistrationMethodv4
ModuleItkSmoothingRecursiveGaussianImageFilter
ModuleSinksAndSources
)
set( ${APPLICATION}_INTEGRATION_TESTS
--conf ../Configuration/itkv4_SVF_ANTsCC.json --in FixedImage=../Data/coneA2d64.mhd MovingImage=../Data/coneB2d64.mhd --out ResultImage=2A_image_itkv4_NC.mhd ResultDisplacementField=2A_deformation_itkv4_NC.mhd
)
\ No newline at end of file
......@@ -17,6 +17,11 @@
#
#=========================================================================
# This file allows the SuperElastix command line interface to be
# built as an external project.
# ---------------------------------------------------------------------
# Collect header files for Visual Studio Project
# http://stackoverflow.com/questions/8316104/specify-how-cmake-creates-visual-studio-project
file(GLOB COMMANDLINE_HEADER_FILES "${COMMANDLINE_SOURCE_DIR}/*/include/*.*")
......
#=========================================================================
#
# Copyright Leiden University Medical Center, Erasmus University Medical
# Center and contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#=========================================================================
include( selxModules )
# ---------------------------------------------------------------------
# Private macros
macro( _selxapplication_check_name APPLICATION )
# "No funny stuff" - Karl Hungus
if( NOT "${_name}" MATCHES "^[a-zA-Z_]*$" )
message( FATAL_ERROR "Invalid application name: ${APPLICATION}" )
endif()
# Check if application was found during initialization
list( FIND SUPERELASTIX_APPLICATIONS "${APPLICATION}" APPLICATION_FOUND )
if( ${APPLICATION_FOUND} EQUAL -1 )
message( FATAL_ERROR "Application not found: ${APPLICATION}" )
endif()
endmacro()
macro( _selxapplications_initialize )
set( SUPERELASTIX_APPLICATIONS )
file( GLOB_RECURSE APPLICATION_CMAKE_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/Applications/*/Application*.cmake"
)
message( STATUS "Found the following SuperElastix applications:")
foreach( APPLICATION_CMAKE_FILE ${APPLICATION_CMAKE_FILES})
get_filename_component( APPLICATION ${APPLICATION_CMAKE_FILE} NAME_WE )
get_filename_component( ${APPLICATION}_PATH ${APPLICATION_CMAKE_FILE} PATH )
message( STATUS " ${APPLICATION}" )
option( "USE_${APPLICATION}" OFF )
set( "${APPLICATION}_CMAKE_FILE" ${CMAKE_SOURCE_DIR}/${APPLICATION_CMAKE_FILE} )
set( "${APPLICATION}_IS_ENABLED" FALSE )
set( ${APPLICATION}_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${${APPLICATION}_PATH} )
set( ${APPLICATION}_BINARY_DIR ${CMAKE_BINARY_DIR}/${${APPLICATION}_PATH} )
# Collect header files for Visual Studio Project
# http://stackoverflow.com/questions/8316104/specify-how-cmake-creates-visual-studio-project
file( GLOB ${APPLICATION}_HEADER_FILES "${${APPLICATION}_SOURCE_DIR}/*/include/*.*")
list( APPEND SUPERELASTIX_APPLICATIONS ${APPLICATION} )
endforeach()
endmacro()
macro( _selxapplication_enable APPLICATION UPSTREAM )
_selxapplication_check_name( ${APPLICATION} )
message( STATUS "${BoldMagenta}Enabling ${APPLICATION} requested by ${UPSTREAM}.${ColourReset}")
if( NOT ${APPLICATION}_IS_ENABLED )
include( ${${APPLICATION}_CMAKE_FILE} )
set( ${APPLICATION}_IS_ENABLED TRUE )
if( NOT ${APPLICATION}_TARGET_NAME )
set( ${APPLICATION}_TARGET_NAME ${APPLICATION} )
endif()
add_executable( ${${APPLICATION}_TARGET_NAME} "${${APPLICATION}_HEADER_FILES}" "${${APPLICATION}_SOURCE_FILES}" )
if( ${APPLICATION}_INCLUDE_DIRS )
_selxmodule_include_directories( ${${APPLICATION}_TARGET_NAME} ${APPLICATION} )
endif()
if( ${APPLICATION}_MODULE_DEPENDENCIES )
_selxmodule_enable_dependencies( ${APPLICATION}_MODULE_DEPENDENCIES ${APPLICATION} )
_selxmodule_include_directories( ${${APPLICATION}_TARGET_NAME} ${APPLICATION}_MODULE_DEPENDENCIES )
_selxmodule_link_libraries( ${${APPLICATION}_TARGET_NAME} ${APPLICATION}_MODULE_DEPENDENCIES )
endif()
if( ${APPLICATION}_LINK_LIBRARIES )
_selxapplication_link_libraries( ${APPLICATION}_TARGET_NAME ${APPLICATION}_LINK_LIBRARIES )
endif()
message( STATUS "${BoldGreen}${APPLICATION} enabled.${ColourReset}" )
else()
message( STATUS "${Green}${APPLICATION} already enabled.${ColourReset}" )
endif()
endmacro()
macro( _selxapplication_disable APPLICATION )
set( USE_${APPLICATION} FALSE )
endmacro()
macro( _selxapplication_link_libraries TARGET LIBRARIES )
target_link_libraries( ${${TARGET}} ${${LIBRARIES}} )
endmacro()
# ---------------------------------------------------------------------
# Public macros
macro( enable_application APPLICATION )
_selxapplication_enable( ${APPLICATION} "user" )
endmacro()
macro( enable_applications APPLICATIONS )
foreach( APPLICATION ${${APPLICATIONS}} )
message( STATUS "APPLICATION: ${APPLICATION}" )
enable_application( ${APPLICATION} )
endforeach()
endmacro()
macro( disable_application APPLICATION )
_selxapplication_disable( ${APPLICATION} )
endmacro()
macro( disable_applications APPLICATIONS )
foreach( APPLICATION ${${APPLICATIONS}} )
disable_application( ${APPLICATION} "user" )
endforeach()
endmacro()
......@@ -17,12 +17,22 @@
#
#=========================================================================
list( APPEND RequiredITKModules
ITKReview
)
foreach( ITKModule ${RequiredITKModules} )
if( NOT ${ITKModule}_LOADED )
message( FATAL_ERROR "elastix requires that ITK is build with ${ITKModule}. Please rebuild ITK with Module_${ITKModule} set to ON." )
endif()
endforeach()
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(ColourBold "${Esc}[1m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[33m")
set(Blue "${Esc}[34m")
set(Magenta "${Esc}[35m")
set(Cyan "${Esc}[36m")
set(White "${Esc}[37m")
set(BoldRed "${Esc}[1;31m")
set(BoldGreen "${Esc}[1;32m")
set(BoldYellow "${Esc}[1;33m")
set(BoldBlue "${Esc}[1;34m")
set(BoldMagenta "${Esc}[1;35m")
set(BoldCyan "${Esc}[1;36m")
set(BoldWhite "${Esc}[1;37m")
endif()
\ No newline at end of file
......@@ -17,6 +17,8 @@
#
#=========================================================================
include( selxCMakeColors )
# ---------------------------------------------------------------------
# Private macros
......@@ -72,30 +74,44 @@ endmacro()
macro( _selxmodule_enable MODULE UPSTREAM )
_selxmodule_check_name( ${MODULE} )
message( STATUS "Enabling ${MODULE} requested by ${UPSTREAM}.")
message( STATUS "${BoldMagenta}Enabling ${MODULE} requested by ${UPSTREAM}.${ColourReset}")
if( NOT ${MODULE}_IS_ENABLED )
set( ${MODULE}_IS_ENABLED TRUE )
include( ${${MODULE}_CMAKE_FILE} )
add_library( ${MODULE} "${${MODULE}_HEADER_FILES}" "${${MODULE}_SOURCE_FILES}" )
_selxmodule_include_directories( ${MODULE} ${MODULE} )
if( NOT ${MODULE} STREQUAL ModuleCore )
_selxmodule_include_directories( ${MODULE} ModuleCore )
_selxmodule_link_libraries( ${MODULE} ModuleCore )
if( ${MODULE}_INCLUDE_DIRS )
_selxmodule_include_directory( ${MODULE} ${MODULE} )
endif()
if( ${MODULE}_MODULE_DEPENDENCIES )
_selxmodule_include_directories( ${MODULE} ${${MODULE}_MODULE_DEPENDENCIES} )
_selxmodule_link_libraries( ${MODULE} ${${MODULE}_MODULE_DEPENDENCIES} )
if( NOT ${MODULE} STREQUAL ModuleCore )
_selxmodule_include_directory( ${MODULE} ModuleCore )
_selxmodule_link_libraries( ${MODULE} ModuleCore )
endif()
if( SUPERELASTIX_BUILD_TESTING AND ${MODULE}_TEST_SOURCE_FILES )
list( APPEND SUPERELASTIX_TEST_SOURCE_FILES ${${MODULE}_TEST_SOURCE_FILES} )
endif()
if( ${MODULE}_MODULE_DEPENDENCIES )
_selxmodule_enable_dependencies( ${MODULE}_MODULE_DEPENDENCIES ${MODULE} )
_selxmodule_include_directories( ${MODULE} ${MODULE}_MODULE_DEPENDENCIES )
_selxmodule_link_libraries( ${MODULE} ${MODULE}_MODULE_DEPENDENCIES )
# TODO: Resolve cylic dependency graph. SuperElastix compiles only because
# CMake is not aware of dependencies and because of the specific order in
# which modules are compiled
# add_dependencies( ${MODULE} ${${MODULE}_MODULE_DEPENDENCIES} )
endif()
if( ${MODULE}_LINK_LIBARIES )
_selxmodule_link_libraries( ${MODULE} ${MODULE}_LINK_LIBARIES )
endif()
message( STATUS "${BoldGreen}${MODULE} enabled.${ColourReset}" )
# SUPERELASTIX_INCLUDE_DIRS and SUPERELASTIX_LIBRARIES are convenience
# variables that should only be used when absolutely necessary, e.g. when
# compiling tests from a central place in Testing/Unit/CMakeLists.txt
......@@ -106,19 +122,8 @@ macro( _selxmodule_enable MODULE UPSTREAM )
if( ${MODULE}_LIBRARIES )
list( APPEND SUPERELASTIX_LIBRARIES ${${MODULE}_LIBRARIES} )
endif()
if( ${MODULE}_MODULE_DEPENDENCIES )
_selxmodule_enable_dependencies( ${MODULE}_MODULE_DEPENDENCIES ${MODULE} )
# TODO: Resolve cylic dependency graph. SuperElastix compiles only because
# CMake is not aware of dependencies and because of the specific order in
# which modules are compiled
# add_dependencies( ${MODULE} ${${MODULE}_MODULE_DEPENDENCIES} )
endif()
message( STATUS "${MODULE} enabled." )
else()
message( STATUS "${MODULE} already enabled." )
message( STATUS "${Green}${MODULE} already enabled.${ColourReset}" )
endif()
endmacro()
......@@ -129,27 +134,29 @@ macro( _selxmodule_enable_dependencies MODULES UPSTREAM )
endmacro()
macro( _selxmodule_disable MODULE )
set( ${MODULE}_IS_ENABLED FALSE )
set( USE_${MODULE} FALSE )
list( FILTER SUPERELASTIX_INCLUDE_DIRS MATCHES EXCLUDE> REGEX "(.*)${MODULE}(.*)" )
list( FILTER SUPERELASTIX_LIBRARY_DIRS MATCHES EXCLUDE> REGEX "(.*)${MODULE}(.*)" )
list( FILTER SUPERELASTIX_LIBRARIES MATCHES EXCLUDE> REGEX "(.*)${MODULE}(.*)" )
list( FILTER SUPERELASTIX_TEST_SOURCE_FILES MATCHES EXCLUDE> REGEX "(.*)${MODULE}(.*)" )
endmacro()
macro( _selxmodule_include_directory TARGET DEPENDENCY )
target_include_directories( ${TARGET} PUBLIC ${${DEPENDENCY}_INCLUDE_DIRS} )
endmacro()
macro( _selxmodule_include_directories TARGET DEPENDENCIES )
foreach( DEPENDENCY ${DEPENDENCIES} )
target_include_directories( ${TARGET} PUBLIC ${${DEPENDENCY}_INCLUDE_DIRS} )
foreach( DEPENDENCY ${${DEPENDENCIES}} )
_selxmodule_include_directory( ${TARGET} ${DEPENDENCY} )
endforeach()
endmacro()
macro( _selxmodule_link_libraries TARGET DEPENDENCIES )
foreach( DEPENDENCY ${DEPENDENCIES} )
target_include_directories( ${TARGET} PUBLIC ${${DEPENDENCY}_INCLUDE_DIRS} )
foreach( DEPENDENCY ${${DEPENDENCIES}} )
target_link_libraries( ${TARGET} ${DEPENDENCY} )
endforeach()
endmacro()
# ---------------------------------------------------------------------
# Public macros
......@@ -175,10 +182,6 @@ endmacro()
# ---------------------------------------------------------------------
# Build core
_selxmodules_initialize()
_selxmodule_enable( ModuleCore "SuperElastix" )
# Enable user-selected modules
# TODO: Loop over USE
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment