SlicerMacroBuildModuleLogic.cmake 8.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
################################################################################
#
#  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
#
################################################################################

21
#
22
# SlicerMacroBuildModuleLogic
23
24
#

25
MACRO(SlicerMacroBuildModuleLogic)
26
  SLICER_PARSE_ARGUMENTS(MODULELOGIC
27
    "NAME;EXPORT_DIRECTIVE;SRCS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES"
28
    "DISABLE_WRAP_PYTHON"
29
30
31
    ${ARGN}
    )

32
  # --------------------------------------------------------------------------
33
  # Sanity checks
34
35
36
37
38
39
40
41
42
  # --------------------------------------------------------------------------
  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()
  
  # --------------------------------------------------------------------------
43
  # Define library name
44
  # --------------------------------------------------------------------------
45
46
47
48
  SET(lib_name ${MODULELOGIC_NAME})

  # --------------------------------------------------------------------------
  # Include dirs
49
  # --------------------------------------------------------------------------
50
51
52
  INCLUDE_DIRECTORIES(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}
53
54
    ${Slicer_Libs_INCLUDE_DIRS}
    ${Slicer_Base_INCLUDE_DIRS}
55
56
    ${MRMLLogic_SOURCE_DIR}
    ${MRMLLogic_BINARY_DIR}
57
58
59
60
61
62
    ${MODULELOGIC_INCLUDE_DIRECTORIES}
    )

  SET(MY_LIBRARY_EXPORT_DIRECTIVE ${MODULELOGIC_EXPORT_DIRECTIVE})
  SET(MY_EXPORT_HEADER_PREFIX ${MODULELOGIC_NAME})
  SET(MY_LIBNAME ${lib_name})
63
64
65
  
  IF (NOT EXISTS ${Slicer_EXPORT_HEADER_TEMPLATE})
    MESSAGE("Warning, Slicer_EXPORT_HEADER_TEMPLATE doesn't exist: ${Slicer_EXPORT_HEADER_TEMPLATE}")
66
  ENDIF()
67
  CONFIGURE_FILE(
68
    ${Slicer_EXPORT_HEADER_TEMPLATE}
69
70
71
72
73
74
    ${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
    )
  SET(dynamicHeaders
    "${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")

  #-----------------------------------------------------------------------------
75
76
  # Source groups
  # --------------------------------------------------------------------------
77
78
79
80
81
  SOURCE_GROUP("Generated" FILES
    ${dynamicHeaders}
    )

  # --------------------------------------------------------------------------
82
83
  # Build library
  # --------------------------------------------------------------------------
84
85
86
87
88
89
90
91
  ADD_LIBRARY(${lib_name}
    ${MODULELOGIC_SRCS}
    )

  # Set loadable modules output path
  SET_TARGET_PROPERTIES(${lib_name}
    PROPERTIES
    RUNTIME_OUTPUT_DIRECTORY
92
    "${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_BIN_DIR}"
93
    LIBRARY_OUTPUT_DIRECTORY
94
    "${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}"
95
    ARCHIVE_OUTPUT_DIRECTORY
96
    "${CMAKE_BINARY_DIR}/${Slicer_INSTALL_QTLOADABLEMODULES_LIB_DIR}"
97
98
    )

99
  # TODO: fix this
100
101
  # HACK Since we don't depend on qSlicerBaseQT{Base, Core, CLI, CoreModules, GUI},
  # let's remove them from the list
102
103
104
105
106
107
  SET(Slicer_ModuleLogic_Base_LIBRARIES ${Slicer_Base_LIBRARIES})
  LIST(REMOVE_ITEM Slicer_ModuleLogic_Base_LIBRARIES qSlicerBaseQTBase)
  LIST(REMOVE_ITEM Slicer_ModuleLogic_Base_LIBRARIES qSlicerBaseQTCore)
  LIST(REMOVE_ITEM Slicer_ModuleLogic_Base_LIBRARIES qSlicerBaseQTCLI)
  LIST(REMOVE_ITEM Slicer_ModuleLogic_Base_LIBRARIES qSlicerBaseQTCoreModules)
  LIST(REMOVE_ITEM Slicer_ModuleLogic_Base_LIBRARIES qSlicerBaseQTGUI)
108
  # Let's also remove dependency on SlicerBaseGUI
109
  LIST(REMOVE_ITEM Slicer_ModuleLogic_Base_LIBRARIES SlicerBaseGUI)
110

111
  TARGET_LINK_LIBRARIES(${lib_name}
112
    ${Slicer_Libs_LIBRARIES}
113
    ${Slicer_ModuleLogic_Base_LIBRARIES}
114
115
116
117
    ${MODULELOGIC_TARGET_LIBRARIES}
    )

  # Apply user-defined properties to the library target.
118
  IF(Slicer_LIBRARY_PROPERTIES)
119
120
    SET_TARGET_PROPERTIES(${lib_name} PROPERTIES ${Slicer_LIBRARY_PROPERTIES})
  ENDIF()
121
  
122
123
124
  # --------------------------------------------------------------------------
  # Install library
  # --------------------------------------------------------------------------
125
  INSTALL(TARGETS ${lib_name}
126
127
128
    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
129
130
    )

131
  # --------------------------------------------------------------------------
132
  # Install headers
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  # --------------------------------------------------------------------------
  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()
  
  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()
  
153
  IF(NOT ${MODULELOGIC_DISABLE_WRAP_PYTHON} AND VTK_WRAP_PYTHON AND BUILD_SHARED_LIBS)
154

155
156
157
158
159
160
161
    # TODO: A parameter named 'WRAPPED_TARGET_LIBRARIES'
    # should be added to the macro.
    # VTK wrapped libraries
    SET(VTK_WRAPPED_LIBRARIES
      vtkVolumeRendering
      )

162
163
164
    # TODO: Slicer's Use file should export this list automatically
    # (currently the wrapped and non-wrapped libs are mixed together)
    # See "HACK" above
165
    SET(Slicer_Wrapped_LIBRARIES
166
      vtkTeem vtkITK FreeSurfer MRML MRMLCLI MRMLLogic MRMLDisplayableManager
167
168
169
      RemoteIO SlicerBaseLogic
      )
    LIST(APPEND Slicer_Wrapped_LIBRARIES ${VTK_WRAPPED_LIBRARIES})
170
171
172
173
174
175

    INCLUDE(${VTK_CMAKE_DIR}/vtkWrapPython.cmake)
    VTK_WRAP_PYTHON3(${lib_name}Python PYTHON_SRCS "${MODULELOGIC_SRCS}")
    ADD_LIBRARY(${lib_name}PythonD ${PYTHON_SRCS})
    ADD_LIBRARY(${lib_name}Python MODULE ${lib_name}PythonInit.cxx)
    
176
    TARGET_LINK_LIBRARIES(${lib_name}PythonD ${lib_name} ${PYTHON_LIBRARIES})
177
178
179
    
    FOREACH(c ${Slicer_Wrapped_LIBRARIES})
      TARGET_LINK_LIBRARIES(${lib_name}PythonD ${c}PythonD ${c})
180
    ENDFOREACH()
181
182
183
184
185
186

    TARGET_LINK_LIBRARIES(${lib_name}Python ${lib_name}PythonD ${lib_name})

    ## Python modules on Windows must have the extension ".pyd"
    IF(WIN32 AND NOT CYGWIN)
      SET_TARGET_PROPERTIES(${lib_name}Python PROPERTIES SUFFIX ".pyd")
187
    ENDIF()
188
189
190
191
192
193
194
195
196

    # Apply user-defined properties to the library target.
    IF(Slicer_LIBRARY_PROPERTIES)
      SET_TARGET_PROPERTIES(${lib_name}Python PROPERTIES
         ${Slicer_LIBRARY_PROPERTIES}
      )
      SET_TARGET_PROPERTIES(${lib_name}PythonD PROPERTIES
         ${Slicer_LIBRARY_PROPERTIES}
      )
197
    ENDIF()
198
199
200
201
202
203
204

    INSTALL(TARGETS ${lib_name}PythonD ${lib_name}Python
      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
      )

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
    # 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.\"\"\"

import os

if os.name == 'posix':
  from lib${lib_name}Python import *
else:
  from ${lib_name}Python import *

# Removing things the user shouldn't have to see.
del os
")

    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()
234

235
  ENDIF()
236
    
237
ENDMACRO()