Commit 62a564c6 authored by jcfr's avatar jcfr
Browse files

COMP: Factorize out code from SlicerMacroBuildModuleLogic into...

COMP: Factorize out code from SlicerMacroBuildModuleLogic into SlicerMacroBuildModuleLibrary and SlicerMacroPythonWrapModuleLibrary

git-svn-id: http://svn.slicer.org/Slicer4/trunk@16473 3bd1e089-480b-0410-8dfb-8563597acbee
parent 7ed82762
################################################################################
#
# Program: 3D Slicer
#
# Copyright (c) 2010 Kitware Inc.
#
# See Doc/copyright/copyright.txt
# or http://www.slicer.org/copyright/copyright.txt for details.
#
# 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.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 3P41RR013218-12S1
#
################################################################################
#
# SlicerMacroBuildModuleLibrary
#
MACRO(SlicerMacroBuildModuleLibrary)
SLICER_PARSE_ARGUMENTS(MODULELIBRARY
"NAME;EXPORT_DIRECTIVE;SRCS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES"
"DISABLE_WRAP_PYTHON"
${ARGN}
)
# --------------------------------------------------------------------------
# Sanity checks
# --------------------------------------------------------------------------
SET(expected_nonempty_vars NAME EXPORT_DIRECTIVE SRCS)
FOREACH(var ${expected_nonempty_vars})
IF("${MODULELIBRARY_${var}}" STREQUAL "")
MESSAGE(FATAL_ERROR "error: ${var} CMake variable is empty !")
ENDIF()
ENDFOREACH()
# --------------------------------------------------------------------------
# Define library name
# --------------------------------------------------------------------------
SET(lib_name ${MODULELIBRARY_NAME})
# --------------------------------------------------------------------------
# Include dirs
# --------------------------------------------------------------------------
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${MODULELIBRARY_INCLUDE_DIRECTORIES}
)
#-----------------------------------------------------------------------------
# Configure export header
#-----------------------------------------------------------------------------
SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MODULELIBRARY_EXPORT_DIRECTIVE})
SET(MY_EXPORT_HEADER_PREFIX ${MODULELIBRARY_NAME})
SET(MY_LIBNAME ${lib_name})
# Sanity checks
IF (NOT EXISTS ${Slicer_EXPORT_HEADER_TEMPLATE})
MESSAGE(FATAL_ERROR "error: Slicer_EXPORT_HEADER_TEMPLATE doesn't exist: ${Slicer_EXPORT_HEADER_TEMPLATE}")
ENDIF()
CONFIGURE_FILE(
${Slicer_EXPORT_HEADER_TEMPLATE}
${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
)
SET(dynamicHeaders
"${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
#-----------------------------------------------------------------------------
# Source groups
# --------------------------------------------------------------------------
SOURCE_GROUP("Generated" FILES
${dynamicHeaders}
)
# --------------------------------------------------------------------------
# Build library
# --------------------------------------------------------------------------
ADD_LIBRARY(${lib_name}
${MODULELIBRARY_SRCS}
)
# Set loadable modules output path
SET_TARGET_PROPERTIES(${lib_name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR}"
LIBRARY_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}"
ARCHIVE_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}"
)
TARGET_LINK_LIBRARIES(${lib_name}
${MODULELIBRARY_TARGET_LIBRARIES}
)
# Apply user-defined properties to the library target.
IF(Slicer_LIBRARY_PROPERTIES)
SET_TARGET_PROPERTIES(${lib_name} PROPERTIES ${Slicer_LIBRARY_PROPERTIES})
ENDIF()
# --------------------------------------------------------------------------
# Install library
# --------------------------------------------------------------------------
INSTALL(TARGETS ${lib_name}
RUNTIME DESTINATION ${Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR} COMPONENT Development
)
# --------------------------------------------------------------------------
# Install headers
# --------------------------------------------------------------------------
IF(DEFINED Slicer_DEVELOPMENT_INSTALL)
IF(NOT DEFINED ${MODULELIBRARY_NAME}_DEVELOPMENT_INSTALL)
SET(${MODULELIBRARY_NAME}_DEVELOPMENT_INSTALL ${Slicer_DEVELOPMENT_INSTALL})
ENDIF()
ELSE()
IF (NOT DEFINED ${MODULELIBRARY_NAME}_DEVELOPMENT_INSTALL)
SET(${MODULELIBRARY_NAME}_DEVELOPMENT_INSTALL OFF)
ENDIF()
ENDIF()
IF(${MODULELIBRARY_NAME}_DEVELOPMENT_INSTALL)
FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
INSTALL(FILES
${headers}
${dynamicHeaders}
DESTINATION ${Slicer_INSTALL_QTLOADABLEMODULES_INCLUDE_DIR}/${MODULELIBRARY_NAME} COMPONENT Development
)
ENDIF()
ENDMACRO()
......@@ -28,181 +28,58 @@ MACRO(SlicerMacroBuildModuleLogic)
"DISABLE_WRAP_PYTHON"
${ARGN}
)
# --------------------------------------------------------------------------
# Sanity checks
# --------------------------------------------------------------------------
SET(expected_defined_vars NAME EXPORT_DIRECTIVE)
FOREACH(var ${expected_defined_vars})
IF(NOT DEFINED MODULELOGIC_${var})
MESSAGE(FATAL_ERROR "${var} is mandatory")
ENDIF()
ENDFOREACH()
# --------------------------------------------------------------------------
# Define library name
# --------------------------------------------------------------------------
SET(lib_name ${MODULELOGIC_NAME})
# --------------------------------------------------------------------------
# Include dirs
# --------------------------------------------------------------------------
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
LIST(APPEND MODULELOGIC_INCLUDE_DIRECTORIES
${Slicer_Libs_INCLUDE_DIRS}
${Slicer_Base_INCLUDE_DIRS}
${Slicer_ModuleLogic_INCLUDE_DIRS}
${MODULELOGIC_INCLUDE_DIRECTORIES}
)
#-----------------------------------------------------------------------------
# Update Slicer_ModuleLogic_INCLUDE_DIRS
#-----------------------------------------------------------------------------
SET(Slicer_ModuleLogic_INCLUDE_DIRS ${Slicer_ModuleLogic_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "Slicer Module logic includes" FORCE)
#-----------------------------------------------------------------------------
# Configure export header
#-----------------------------------------------------------------------------
SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MODULELOGIC_EXPORT_DIRECTIVE})
SET(MY_EXPORT_HEADER_PREFIX ${MODULELOGIC_NAME})
SET(MY_LIBNAME ${lib_name})
# Sanity checks
IF (NOT EXISTS ${Slicer_EXPORT_HEADER_TEMPLATE})
MESSAGE(FATAL_ERROR "error: Slicer_EXPORT_HEADER_TEMPLATE doesn't exist: ${Slicer_EXPORT_HEADER_TEMPLATE}")
ENDIF()
CONFIGURE_FILE(
${Slicer_EXPORT_HEADER_TEMPLATE}
${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
)
SET(dynamicHeaders
"${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
#-----------------------------------------------------------------------------
# Source groups
# --------------------------------------------------------------------------
SOURCE_GROUP("Generated" FILES
${dynamicHeaders}
)
# --------------------------------------------------------------------------
# Build library
# --------------------------------------------------------------------------
ADD_LIBRARY(${lib_name}
${MODULELOGIC_SRCS}
)
# Set loadable modules output path
SET_TARGET_PROPERTIES(${lib_name}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR}"
LIBRARY_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}"
ARCHIVE_OUTPUT_DIRECTORY
"${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}"
)
TARGET_LINK_LIBRARIES(${lib_name}
LIST(APPEND MODULELOGIC_TARGET_LIBRARIES
${Slicer_Libs_LIBRARIES}
SlicerBaseLogic
SlicerBaseCLI
${Slicer_ModuleLogic_LIBRARIES}
${MODULELOGIC_TARGET_LIBRARIES}
)
# Apply user-defined properties to the library target.
IF(Slicer_LIBRARY_PROPERTIES)
SET_TARGET_PROPERTIES(${lib_name} PROPERTIES ${Slicer_LIBRARY_PROPERTIES})
ENDIF()
# --------------------------------------------------------------------------
# Update Slicer_ModuleLogic_LIBRARIES
# --------------------------------------------------------------------------
SET(Slicer_ModuleLogic_LIBRARIES ${Slicer_ModuleLogic_LIBRARIES} ${lib_name} CACHE INTERNAL "Slicer Module logic libraries" FORCE)
# --------------------------------------------------------------------------
# Install library
# --------------------------------------------------------------------------
INSTALL(TARGETS ${lib_name}
RUNTIME DESTINATION ${Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR} COMPONENT RuntimeLibraries
LIBRARY DESTINATION ${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR} COMPONENT RuntimeLibraries
ARCHIVE DESTINATION ${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR} COMPONENT Development
SlicerMacroBuildModuleLibrary(
NAME ${MODULELOGIC_NAME}
EXPORT_DIRECTIVE ${MODULELOGIC_EXPORT_DIRECTIVE}
SRCS ${MODULELOGIC_SRCS}
INCLUDE_DIRECTORIES ${MODULELOGIC_INCLUDE_DIRECTORIES}
TARGET_LIBRARIES ${MODULELOGIC_TARGET_LIBRARIES}
)
# --------------------------------------------------------------------------
# Install headers
# --------------------------------------------------------------------------
IF(DEFINED Slicer_DEVELOPMENT_INSTALL)
IF(NOT DEFINED ${MODULELOGIC_NAME}_DEVELOPMENT_INSTALL)
SET(${MODULELOGIC_NAME}_DEVELOPMENT_INSTALL ${Slicer_DEVELOPMENT_INSTALL})
ENDIF()
ELSE()
IF (NOT DEFINED ${MODULELOGIC_NAME}_DEVELOPMENT_INSTALL)
SET(${MODULELOGIC_NAME}_DEVELOPMENT_INSTALL OFF)
ENDIF()
ENDIF()
#-----------------------------------------------------------------------------
# Update Slicer_ModuleLogic_INCLUDE_DIRS and Slicer_ModuleLogic_LIBRARIES
#-----------------------------------------------------------------------------
SET(Slicer_ModuleLogic_INCLUDE_DIRS
${Slicer_ModuleLogic_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
CACHE INTERNAL "Slicer Module logic includes" FORCE)
IF(${MODULELOGIC_NAME}_DEVELOPMENT_INSTALL)
FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
INSTALL(FILES
${headers}
${dynamicHeaders}
DESTINATION ${Slicer_INSTALL_QTLOADABLEMODULES_INCLUDE_DIR}/${MODULELOGIC_NAME} COMPONENT Development
)
ENDIF()
SET(Slicer_ModuleLogic_LIBRARIES
${Slicer_ModuleLogic_LIBRARIES}
${MODULELOGIC_NAME}
CACHE INTERNAL "Slicer Module logic libraries" FORCE)
IF(NOT ${MODULELOGIC_DISABLE_WRAP_PYTHON} AND VTK_WRAP_PYTHON AND BUILD_SHARED_LIBS)
SET(VTK_PYTHON_WRAPPED_LIBRARIES)
FOREACH(lib ${VTK_LIBRARIES})
LIST(APPEND VTK_PYTHON_WRAPPED_LIBRARIES ${lib}PythonD)
ENDFOREACH()
SET(Slicer_Libs_VTK_PYTHON_WRAPPED_LIBRARIES)
FOREACH(lib ${Slicer_Libs_VTK_WRAPPED_LIBRARIES})
LIST(APPEND Slicer_Libs_VTK_PYTHON_WRAPPED_LIBRARIES ${lib}PythonD)
ENDFOREACH()
# --------------------------------------------------------------------------
# Python wrapping
# --------------------------------------------------------------------------
IF(NOT ${MODULELOGIC_DISABLE_WRAP_PYTHON} AND VTK_WRAP_PYTHON)
SET(Slicer_Wrapped_LIBRARIES
${VTK_PYTHON_WRAPPED_LIBRARIES}
${Slicer_Libs_VTK_PYTHON_WRAPPED_LIBRARIES}
SlicerBaseLogicPythonD
)
vtkMacroKitPythonWrap(
KIT_NAME ${lib_name}
KIT_SRCS ${MODULELOGIC_SRCS}
KIT_INSTALL_BIN_DIR ${Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR}
KIT_INSTALL_LIB_DIR ${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}
KIT_PYTHON_LIBRARIES ${Slicer_Wrapped_LIBRARIES}
SlicerMacroPythonWrapModuleLibrary(
NAME ${MODULELOGIC_NAME}
SRCS ${MODULELOGIC_SRCS}
WRAPPED_TARGET_LIBRARIES ${Slicer_Wrapped_LIBRARIES}
RELATIVE_PYTHON_DIR "slicer/modulelogic"
)
# Generate "Python/<lib_name>.py" file
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/Python/slicer/modulelogic/${lib_name}.py "
\"\"\" This module loads all the classes from the ${lib_name} library into its
namespace.\"\"\"
from ${lib_name}Python import *
")
FILE(GLOB PYFILES
RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/Python"
"${CMAKE_CURRENT_BINARY_DIR}/Python/slicer/modulelogic/*.py")
if ( PYFILES )
ctkMacroCompilePythonScript(
TARGET_NAME ${lib_name}
SCRIPTS "${PYFILES}"
RESOURCES ""
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/Python
DESTINATION_DIR ${Slicer_BINARY_DIR}/bin/Python
INSTALL_DIR ${Slicer_INSTALL_BIN_DIR}
)
ENDIF()
ENDIF()
ENDMACRO()
################################################################################
#
# Program: 3D Slicer
#
# Copyright (c) 2010 Kitware Inc.
#
# See Doc/copyright/copyright.txt
# or http://www.slicer.org/copyright/copyright.txt for details.
#
# 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.
#
# This file was originally developed by Jean-Christophe Fillion-Robin, Kitware Inc.
# and was partially funded by NIH grant 3P41RR013218-12S1
#
################################################################################
#
# SlicerMacroPythonWrapModuleLibrary
#
MACRO(SlicerMacroPythonWrapModuleLibrary)
SLICER_PARSE_ARGUMENTS(PYTHONWRAPMODULELIBRARY
"NAME;SRCS;WRAPPED_TARGET_LIBRARIES;RELATIVE_PYTHON_DIR"
""
${ARGN}
)
# --------------------------------------------------------------------------
# Sanity checks
# --------------------------------------------------------------------------
SET(expected_defined_vars VTK_LIBRARIES Slicer_Libs_VTK_WRAPPED_LIBRARIES)
FOREACH(var ${expected_defined_vars})
IF(NOT DEFINED ${var})
MESSAGE(FATAL_ERROR "error: ${var} CMake variable is not defined !")
ENDIF()
ENDFOREACH()
SET(expected_nonempty_vars NAME SRCS)
FOREACH(var ${expected_nonempty_vars})
IF("${MODULELIBRARY_${var}}" STREQUAL "")
MESSAGE(FATAL_ERROR "error: ${var} CMake variable is empty !")
ENDIF()
ENDFOREACH()
SET(VTK_PYTHON_WRAPPED_LIBRARIES)
FOREACH(lib ${VTK_LIBRARIES})
LIST(APPEND VTK_PYTHON_WRAPPED_LIBRARIES ${lib}PythonD)
ENDFOREACH()
SET(Slicer_Libs_VTK_PYTHON_WRAPPED_LIBRARIES)
FOREACH(lib ${Slicer_Libs_VTK_WRAPPED_LIBRARIES})
LIST(APPEND Slicer_Libs_VTK_PYTHON_WRAPPED_LIBRARIES ${lib}PythonD)
ENDFOREACH()
SET(PYTHONWRAPMODULELIBRARY_Wrapped_LIBRARIES
${VTK_PYTHON_WRAPPED_LIBRARIES}
${Slicer_Libs_VTK_PYTHON_WRAPPED_LIBRARIES}
${PYTHONWRAPMODULELIBRARY_WRAPPED_TARGET_LIBRARIES}
)
vtkMacroKitPythonWrap(
KIT_NAME ${PYTHONWRAPMODULELIBRARY_NAME}
KIT_SRCS ${PYTHONWRAPMODULELIBRARY_SRCS}
KIT_INSTALL_BIN_DIR ${Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR}
KIT_INSTALL_LIB_DIR ${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}
KIT_PYTHON_LIBRARIES ${PYTHONWRAPMODULELIBRARY_Wrapped_LIBRARIES}
)
# Generate "Python/<lib_name>.py" file
FILE(WRITE ${CMAKE_CURRENT_BINARY_DIR}/Python/${PYTHONWRAPMODULELIBRARY_RELATIVE_PYTHON_DIR}/${lib_name}.py "
\"\"\" This module loads all the classes from the ${lib_name} library into its
namespace.\"\"\"
from ${lib_name}Python import *
")
FILE(GLOB PYFILES
RELATIVE "${CMAKE_CURRENT_BINARY_DIR}/Python"
"${CMAKE_CURRENT_BINARY_DIR}/Python/${PYTHONWRAPMODULELIBRARY_RELATIVE_PYTHON_DIR}/*.py")
if ( PYFILES )
ctkMacroCompilePythonScript(
TARGET_NAME ${lib_name}
SCRIPTS "${PYFILES}"
RESOURCES ""
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/Python
DESTINATION_DIR ${Slicer_BINARY_DIR}/bin/Python
INSTALL_DIR ${Slicer_INSTALL_BIN_DIR}
)
ENDIF()
ENDMACRO()
......@@ -553,6 +553,8 @@ ADD_SUBDIRECTORY(Resources)
# Module Logic
#-----------------------------------------------------------------------------
INCLUDE(SlicerMacroBuildModuleLibrary)
INCLUDE(SlicerMacroPythonWrapModuleLibrary)
INCLUDE(SlicerMacroBuildModuleLogic)
# KWWidgets and Qt modules share the same logics typically located in the
......
......@@ -66,6 +66,8 @@ link_directories(
include(CMakeParseArguments)
#include(ctkMacroCompilePythonScript)
include(SlicerMacroParseArguments)
include(SlicerMacroBuildModuleLibrary)
#include(SlicerMacroPythonWrapModuleLibrary)
include(SlicerMacroBuildModuleLogic)
include(SlicerMacroBuildQtModule)
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