Commit 014a0d54 authored by Kasper Marstal's avatar Kasper Marstal
Browse files

BUG: Unable to compile more than one module due to CMake global variable conventions

parent 4d5ee1e4
......@@ -6,7 +6,7 @@ macro( _elxmodule_check_name MODULE )
message( FATAL_ERROR "Invalid module name: ${MODULE}" )
endif()
list( FIND ELXMODULE_ALL "${MODULE}" MODULE_FOUND )
list( FIND ELASTIX_MODULES "${MODULE}" MODULE_FOUND )
if( ${MODULE_FOUND} EQUAL -1 )
message( FATAL_ERROR "Module not found: ${MODULE}")
endif()
......@@ -16,7 +16,7 @@ macro( _elxmodule_enable MODULE )
_elxmodule_check_name( ${MODULE} )
if( NOT ${MODULE}_ENABLED )
set( USE_${MODULE} ON )
set( ELASTIX_USE_${MODULE} ON )
include( ${${MODULE}_FILE} )
......@@ -24,14 +24,9 @@ macro( _elxmodule_enable MODULE )
include_directories( ${${MODULE}_INCLUDE_DIRS} )
endif()
add_subdirectory( ${${MODULE}_SOURCE_DIR} )
if( ${MODULE}_LIBRARIES )
link_directories( ${${MODULE}_LIBRARY_DIRS} )
list( APPEND ELASTIX_LIBRARIES
${${MODULE}_LIBRARIES}
)
list( APPEND ELASTIX_LIBRARIES ${${MODULE}_LIBRARIES} )
endif()
# TODO: Add recursive dependency walk
......@@ -43,30 +38,32 @@ macro( _elxmodule_disable MODULE )
endmacro()
macro( _elxmodules_initialize )
set( ELXMODULE_ALL )
set( ELASTIX_LIBRARIES )
set( ELASTIX_MODULES )
file( GLOB MODULE_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
file( GLOB_RECURSE MODULE_FILES RELATIVE "${CMAKE_SOURCE_DIR}"
"${CMAKE_SOURCE_DIR}/Modules/*/elxModule*.cmake"
)
message( STATUS "Found the following elastix modules:")
foreach( MODULE_FILE ${MODULE_FILES})
get_filename_component( MODULE_PATH ${MODULE_FILE} PATH )
get_filename_component( MODULE ${MODULE_FILE} NAME_WE )
message( STATUS " ${MODULE}" )
get_filename_component( MODULE_NAME ${MODULE_FILE} NAME_WE )
get_filename_component( ${MODULE_NAME}_PATH ${MODULE_FILE} PATH )
message( STATUS " ${MODULE_NAME}" )
option( "USE_${MODULE}" OFF )
set( "${MODULE}_FILE" ${CMAKE_SOURCE_DIR}/${MODULE_FILE} )
set( "${MODULE}_ENABLED" OFF )
option( "ELASTIX_USE_${MODULE_NAME}" OFF )
set( "${MODULE_NAME}_FILE" ${CMAKE_SOURCE_DIR}/${MODULE_FILE} )
set( "${MODULE_NAME}_ENABLED" OFF )
set( ${MODULE}_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${MODULE_PATH} )
set( ${MODULE}_BINARY_DIR ${CMAKE_BINARY_DIR}/${MODULE_PATH} )
set( ${MODULE_NAME}_SOURCE_DIR ${CMAKE_SOURCE_DIR}/${${MODULE_NAME}_PATH} )
set( ${MODULE_NAME}_BINARY_DIR ${CMAKE_BINARY_DIR}/${${MODULE_NAME}_PATH} )
set( ${MODULE}_INCLUDE_DIRS )
set( ${MODULE}_LIBRARY_DIRS )
set( ${MODULE}_LIBRARIES )
set( ${MODULE_NAME}_INCLUDE_DIRS )
set( ${MODULE_NAME}_LIBRARY_DIRS )
set( ${MODULE_NAME}_LIBRARIES )
list(APPEND ELXMODULE_ALL ${MODULE} )
list(APPEND ELASTIX_MODULES ${MODULE_NAME} )
endforeach()
endmacro()
......@@ -79,9 +76,3 @@ macro( elxmodule_enable MODULE )
_elxmodule_enable( ${MODULE} )
endmacro()
macro( elxmodule_compile MODULE )
project( "${MODULE}" )
add_library( ${MODULE} STATIC "${${MODULE}_SOURCE_FILES}" )
target_link_libraries( ${MODULE} ${ELASTIX_LIBRARIES} )
list( APPEND ${MODULE}_LIBRARIES ${MODULE} )
endmacro()
......@@ -36,7 +36,6 @@ include_directories( ${Boost_INCLUDE_DIRS} )
# ---------------------------------------------------------------------
# Build Elastix
# For now we just enable all modules
include( "${CMAKE_CURRENT_SOURCE_DIR}/CMake/elxModules.cmake" )
elxmodule_enable( elxModuleCore )
......
elxmodule_compile( ${MODULE} )
set( ${MODULE}_INCLUDE_DIRS
${CMAKE_SOURCE_DIR}/${MODULE_PATH}/Common/include
${CMAKE_SOURCE_DIR}/${MODULE_PATH}/Blueprints/include
)
set( MODULE elxModuleCore )
set( ${MODULE}_SOURCE_FILES
${CMAKE_SOURCE_DIR}/${MODULE_PATH}/Blueprints/src/elxBlueprint.cxx
# Export include files
set( ${MODULE}_INCLUDE_DIRS
${${MODULE}_SOURCE_DIR}/Common/include
${${MODULE}_SOURCE_DIR}/Blueprints/include
)
# Export libraries
set( ${MODULE}_LIBRARIES
${MODULE}
)
# Module source files
set( ${MODULE}_SOURCE_FILES
${${MODULE}_SOURCE_DIR}/Blueprints/src/elxBlueprint.cxx
)
# Compile library
add_library( ${MODULE} STATIC "${${MODULE}_SOURCE_FILES}" )
target_link_libraries( ${MODULE} ${ELASTIX_LIBRARIES} )
......@@ -54,7 +54,6 @@ if( USE_SYSTEM_ITK )
include( "${CMAKE_CURRENT_SOURCE_DIR}/../CMake/elxRequiredITKModules.cmake" )
else()
include( ExternalITK )
list( APPEND ELASTIX_DEPENDENCIES ITK )
endif()
# ---------------------------------------------------------------------
......@@ -66,7 +65,6 @@ if( USE_SYSTEM_BOOST )
find_package( BOOST REQUIRED graph )
else()
include( ExternalBoost )
list( APPEND ELASTIX_DEPENDENCIES BOOST )
endif()
# ---------------------------------------------------------------------
......
set( PROJECT BOOST )
set( proj BOOST )
# Note: It IS important to download different files on different OS's:
# on Unix-like systems, we need the file persmissions (only available in the .tar.gz),
......@@ -19,7 +19,7 @@ else()
endif()
endif()
set( BOOST_BUILD_DIR "${CMAKE_INSTALL_PREFIX}/${PROJECT}-build/" )
set( BOOST_BUILD_DIR "${CMAKE_INSTALL_PREFIX}/${proj}-build/" )
ExternalProject_Add( BOOST
BUILD_IN_SOURCE 1
......@@ -37,3 +37,5 @@ ExternalProject_Add( BOOST
)
set( BOOST_ROOT ${BOOST_BUILD_DIR} )
list( APPEND ELASTIX_DEPENDENCIES ${proj} )
set( PROJECT ITK )
set( proj ITK )
set( ITK_REPOSITORY https://github.com/InsightSoftwareConsortium/ITK.git )
set( ITK_TAG "v${ITK_VERSION_STRING}")
ExternalProject_Add( ${PROJECT}
ExternalProject_Add( ${proj}
GIT_REPOSITORY ${ITK_REPOSITORY}
GIT_TAG ${ITK_TAG}
UPDATE_COMMAND ""
SOURCE_DIR ${PROJECT}
BINARY_DIR ${PROJECT}-build
SOURCE_DIR ${proj}
BINARY_DIR ${proj}-build
CMAKE_ARGS
--no-warn-unused-cli
-DBUILD_EXAMPLES:BOOL=OFF
......@@ -20,5 +20,7 @@ ExternalProject_Add( ${PROJECT}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
)
ExternalProject_Get_Property( ITK install_dir )
ExternalProject_Get_Property( ${proj} install_dir )
set( ITK_DIR "${install_dir}/lib/cmake/ITK-${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}" )
list( APPEND ELASTIX_DEPENDENCIES ${proj} )
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