Commit 9fd742e6 authored by jcfr's avatar jcfr

ENH: Do not require "if(NOT Slicer_SOURCE_DIR)" in extension

Before this commit, to allow extension or module to be bundled
directly within Slicer by setting the variable
Slicer_EXTENSION_SOURCE_DIRS, it was required to explicitly exclude
the call to:
 find_package(Slicer ...)
 include(${Slicer_USE_FILE})
 include(${Slicer_EXTENSION_CPACK})
by check if Slicer_SOURCE_DIR was set .

This commit improves the build system so that making this
call is a no-op when bundling modules or extensions.

This will allow extension developer to write simpler CMakeLists.txt



Before:

cmake_minimum_required(VERSION 2.8.9)

if(NOT Slicer_SOURCE_DIR)
  find_package(Slicer COMPONENTS ConfigurePrerequisites)
endif()

if(NOT Slicer_SOURCE_DIR)
  set(EXTENSION_NAME EmptyExtensionTemplate)
  set(EXTENSION_HOMEPAGE "http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Extensions/EmptyExtensionTemplate")
  set(EXTENSION_CATEGORY "Examples")
  set(EXTENSION_CONTRIBUTORS "Jean-Christophe Fillion-Robin (Kitware)")
  set(EXTENSION_DESCRIPTION "This is an example of extension bundling N module(s)")
  set(EXTENSION_ICONURL "http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Extensions/Testing/EmptyExtensionTemplate/EmptyExtensionTemplate.png?revision=21746&view=co")
  set(EXTENSION_SCREENSHOTURLS "http://wiki.slicer.org/slicerWiki/images/4/42/Slicer-r19441-EmptyExtensionTemplate-screenshot.png")
endif()

if(NOT Slicer_SOURCE_DIR)
  find_package(Slicer REQUIRED)
  include(${Slicer_USE_FILE})
endif()


add_subdirectory(ModuleA)

if(NOT Slicer_SOURCE_DIR)
  include(${Slicer_EXTENSION_CPACK})
endif()




After:

cmake_minimum_required(VERSION 2.8.9)

find_package(Slicer COMPONENTS ConfigurePrerequisites)

project(EmptyExtensionTemplate)

set(EXTENSION_HOMEPAGE "http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Extensions/EmptyExtensionTemplate")
set(EXTENSION_CATEGORY "Examples")
set(EXTENSION_CONTRIBUTORS "Jean-Christophe Fillion-Robin (Kitware)")
set(EXTENSION_DESCRIPTION "This is an example of empty extension")
set(EXTENSION_ICONURL "http://viewvc.slicer.org/viewvc.cgi/Slicer4/trunk/Extensions/Testing/EmptyExtensionTemplate/EmptyExtensionTemplate.png?revision=21746&view=co")
set(EXTENSION_SCREENSHOTURLS "http://wiki.slicer.org/slicerWiki/images/4/42/Slicer-r19441-EmptyExtensionTemplate-screenshot.png")

find_package(Slicer REQUIRED)
include(${Slicer_USE_FILE})

add_subdirectory(ModuleA)

include(${Slicer_EXTENSION_CPACK})

git-svn-id: http://svn.slicer.org/Slicer4/trunk@22063 3bd1e089-480b-0410-8dfb-8563597acbee
parent 5036d0a4
......@@ -28,11 +28,6 @@
# end of CMakeLists processing, i.e. instead of waiting until some variables
# are configured in SUBDIRS.
#-----------------------------------------------------------------------------
configure_file(
${Slicer_SOURCE_DIR}/CMake/UseSlicer.cmake.in
${Slicer_BINARY_DIR}/UseSlicer.cmake COPYONLY)
#-----------------------------------------------------------------------------
get_property(Slicer_TARGETS GLOBAL PROPERTY Slicer_TARGETS)
export(TARGETS ${Slicer_TARGETS} APPEND FILE ${Slicer_BINARY_DIR}/SlicerTargets.cmake)
......@@ -42,9 +37,5 @@ export(TARGETS ${Slicer_TARGETS} APPEND FILE ${Slicer_BINARY_DIR}/SlicerTargets.
# Since it might generate configuration file depending
include(${Slicer_SOURCE_DIR}/CMake/SlicerGenerateSlicerConfig.cmake)
configure_file(
${Slicer_SOURCE_DIR}/CMake/SlicerConfigVersion.cmake.in
${Slicer_BINARY_DIR}/SlicerConfigVersion.cmake @ONLY)
#-----------------------------------------------------------------------------
include(${Slicer_SOURCE_DIR}/CMake/SlicerCPack.cmake)
......@@ -68,6 +68,9 @@ if(NOT DEFINED Slicer_USE_CONFIGUREPREREQUISITES)
set(Slicer_USE_CONFIGUREPREREQUISITES FALSE)
endif()
if(Slicer_SOURCE_DIR)
return()
endif()
# --------------------------------------------------------------------------
set(Slicer_CMAKE_DIR "@Slicer_CMAKE_DIR@")
......
......@@ -29,6 +29,11 @@ foreach(var ${expected_nonempty_vars})
endif()
endforeach()
if(Slicer_SOURCE_DIR)
message(STATUS "Skipping extension packaging: ${EXTENSION_NAME}")
return()
endif()
set(expected_existing_vars EXTENSION_README_FILE EXTENSION_LICENSE_FILE)
foreach(var ${expected_existing_vars})
if(NOT EXISTS ${${var}})
......
......@@ -18,7 +18,7 @@
#
#
set(Slicer_USE_FILE_CONFIG ${Slicer_BINARY_DIR}/UseSlicer.cmake)
set(Slicer_USE_FILE_CONFIG ${Slicer_USE_FILE})
# Compilation settings
set(Slicer_CMAKE_CXX_COMPILER_CONFIG ${CMAKE_CXX_COMPILER})
......@@ -39,7 +39,7 @@ set(Slicer_CXX_MODULE_TEST_TEMPLATES_DIR_CONFIG ${Slicer_CXX_MODULE_TEST_TEMPLAT
set(Slicer_PYTHON_MODULE_TEST_TEMPLATES_DIR_CONFIG ${Slicer_PYTHON_MODULE_TEST_TEMPLATES_DIR})
# Path to extension CPack script(s)
set(Slicer_EXTENSION_CPACK_CONFIG ${Slicer_SOURCE_DIR}/CMake/SlicerExtensionCPack.cmake)
set(Slicer_EXTENSION_CPACK_CONFIG ${Slicer_EXTENSION_CPACK})
set(Slicer_EXTENSION_CPACK_BUNDLE_FIXUP_CONFIG ${Slicer_SOURCE_DIR}/CMake/SlicerExtensionCPackBundleFixup.cmake.in)
set(Slicer_GUI_LIBRARY_CONFIG ${Slicer_GUI_LIBRARY})
......
......@@ -68,13 +68,17 @@ if(NOT Slicer_DONT_USE_EXTENSION)
endif()
slicer_setting_variable_message("EXTENSION_NAME")
endif()
if(NOT Slicer_SKIP_EXTENSION_NAME_CHECK AND "${EXTENSION_NAME}" STREQUAL "")
if(NOT Slicer_SKIP_EXTENSION_NAME_CHECK AND "${EXTENSION_NAME}" MATCHES "^$|^Slicer$|^Project$")
message(FATAL_ERROR
"error: Make sure to call 'project(<extension_name>)' or "
"set EXTENSION_NAME (or MODULE_NAME) prior to call 'include(\${Slicer_USE_FILE})' !")
endif()
endif()
if(Slicer_SOURCE_DIR)
return()
endif()
# --------------------------------------------------------------------------
# Setup project
# --------------------------------------------------------------------------
......
......@@ -960,9 +960,28 @@ else()
)
endif()
#-----------------------------------------------------------------------------
set(Slicer_USE_FILE ${Slicer_BINARY_DIR}/UseSlicer.cmake)
configure_file(
${Slicer_SOURCE_DIR}/CMake/UseSlicer.cmake.in
${Slicer_USE_FILE} COPYONLY)
configure_file(
${Slicer_SOURCE_DIR}/CMake/SlicerConfigVersion.cmake.in
${Slicer_BINARY_DIR}/SlicerConfigVersion.cmake @ONLY)
set(Slicer_EXTENSION_CPACK ${Slicer_SOURCE_DIR}/CMake/SlicerExtensionCPack.cmake)
# --------------------------------------------------------------------------
# Bundle extension(s)
# --------------------------------------------------------------------------
# Configure SlicerConfig for bundled extension(s) or module(s)
set(Slicer_DIR "${Slicer_BINARY_DIR}/Extensions")
configure_file(
${Slicer_SOURCE_DIR}/CMake/SlicerConfig.cmake.in
${Slicer_DIR}/SlicerConfig.cmake @ONLY)
# List of extension source directories can be passed at configuration time
# using the following syntax:
# cmake -DSlicer_EXTENSION_SOURCE_DIRS:STRING=/path/to/ExtensionA;/path/to/ExtensionB /path/to/source/Slicer
......@@ -977,6 +996,7 @@ foreach(extension_source_dir ${Slicer_EXTENSION_SOURCE_DIRS})
${${extension_source_dirname}_BINARY_DIR}
)
endforeach()
unset(Slicer_DIR)
# --------------------------------------------------------------------------
# Recover the QM output directories
......
Markdown is supported
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