SlicerMacroBuildBaseQtLibrary.cmake 8.31 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
# SlicerMacroBuildBaseQtLibrary
23
#
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

#
# Parameters:
#
#   NAME .................: Name of the library
#
#   EXPORT_DIRECTIVE .....: Export directive that should be used to export symbol
#
#   SRCS .................: List of source files
#
#   MOC_SRCS .............: Optional list of headers to run through the meta object compiler (moc)
#                           using QT4_WRAP_CPP CMake macro
#
#   UI_SRCS ..............: Optional list of UI file to run through UI compiler (uic) using
#                           QT4_WRAP_UI CMake macro
#
#   INCLUDE_DIRECTORIES ..: Optional list of extra folder that should be included. See implementation
#                           for the list of folder included by default.
#
#   TARGET_LIBRARIES .....: Optional list of target libraries that should be used with TARGET_LINK_LIBRARIES
#                           CMake macro. See implementation for the list of libraries added by default.
#
#   RESOURCES ............: Optional list of files that should be converted into resource header
#                           using QT4_ADD_RESOURCES
#
# Options:
#
#   WRAP_PYTHONQT ........: If specified, the sources (SRCS) will be 'PythonQt' wrapped and a static
#                           library named <NAME>PythonQt will be built.
53 54
#

55
MACRO(SlicerMacroBuildBaseQtLibrary)
56
  SLICER_PARSE_ARGUMENTS(SLICERQTBASELIB
57
    "NAME;EXPORT_DIRECTIVE;SRCS;MOC_SRCS;UI_SRCS;INCLUDE_DIRECTORIES;TARGET_LIBRARIES;RESOURCES"
58
    "WRAP_PYTHONQT"
59 60
    ${ARGN}
    )
61

62
  # --------------------------------------------------------------------------
63
  # Sanity checks
64 65 66 67 68 69 70
  # --------------------------------------------------------------------------
  SET(expected_defined_vars NAME EXPORT_DIRECTIVE)
  FOREACH(var ${expected_defined_vars})
    IF(NOT DEFINED SLICERQTBASELIB_${var})
      MESSAGE(FATAL_ERROR "${var} is mandatory")
    ENDIF()
  ENDFOREACH()
71

72 73
  IF(NOT DEFINED Slicer_INSTALL_NO_DEVELOPMENT)
    MESSAGE(SEND_ERROR "Slicer_INSTALL_NO_DEVELOPMENT is mandatory")
74
  ENDIF()
75

76
  # --------------------------------------------------------------------------
77
  # Define library name
78
  # --------------------------------------------------------------------------
79 80 81 82
  SET(lib_name ${SLICERQTBASELIB_NAME})

  # --------------------------------------------------------------------------
  # Include dirs
83
  # --------------------------------------------------------------------------
84
  SET(QT_INCLUDE_DIRS
85
    ${QT_INCLUDE_DIR}
86
    ${QT_QTWEBKIT_INCLUDE_DIR}
87 88
    ${QT_QTGUI_INCLUDE_DIR}
    ${QT_QTCORE_INCLUDE_DIR}
89
    ${QT_QTXML_INCLUDE_DIR}
90
    )
91

92 93 94 95 96 97 98 99 100 101 102 103
  SET(include_dirs
    ${QT_INCLUDE_DIRS}
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}
    ${SlicerBaseLogic_SOURCE_DIR}
    ${SlicerBaseLogic_BINARY_DIR}
    ${qMRMLWidgets_SOURCE_DIR}
    ${qMRMLWidgets_BINARY_DIR}
    ${MRML_SOURCE_DIR}
    ${MRML_BINARY_DIR}
    ${SLICERQTBASELIB_INCLUDE_DIRECTORIES}
    )
104

105
  INCLUDE_DIRECTORIES(${include_dirs})
106

107
  #-----------------------------------------------------------------------------
108
  # Update Slicer_Base_INCLUDE_DIRS
109
  #-----------------------------------------------------------------------------
110
  SET(Slicer_Base_INCLUDE_DIRS ${Slicer_Base_INCLUDE_DIRS} ${include_dirs} CACHE INTERNAL "Slicer Base includes" FORCE)
111

112 113
  #-----------------------------------------------------------------------------
  # Configure
114
  # --------------------------------------------------------------------------
115
  SET(MY_LIBRARY_EXPORT_DIRECTIVE ${SLICERQTBASELIB_EXPORT_DIRECTIVE})
116
  SET(MY_EXPORT_HEADER_PREFIX ${SLICERQTBASELIB_NAME})
117
  SET(MY_LIBNAME ${lib_name})
118

119
  CONFIGURE_FILE(
120
    ${Slicer_SOURCE_DIR}/qSlicerExport.h.in
121
    ${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h
122
    )
123 124
  SET(dynamicHeaders
    "${dynamicHeaders};${CMAKE_CURRENT_BINARY_DIR}/${MY_EXPORT_HEADER_PREFIX}Export.h")
125

126 127
  #-----------------------------------------------------------------------------
  # Sources
128
  # --------------------------------------------------------------------------
129
  QT4_WRAP_CPP(SLICERQTBASELIB_MOC_OUTPUT ${SLICERQTBASELIB_MOC_SRCS})
130
  QT4_WRAP_UI(SLICERQTBASELIB_UI_CXX ${SLICERQTBASELIB_UI_SRCS})
131
  IF(DEFINED SLICERQTBASELIB_RESOURCES)
132
    QT4_ADD_RESOURCES(SLICERQTBASELIB_QRC_SRCS ${SLICERQTBASELIB_RESOURCES})
133 134
  ENDIF(DEFINED SLICERQTBASELIB_RESOURCES)

135
  QT4_ADD_RESOURCES(SLICERQTBASELIB_QRC_SRCS ${Slicer_SOURCE_DIR}/Resources/qSlicerLogos.qrc)
136 137 138

  SET_SOURCE_FILES_PROPERTIES(
    ${SLICERQTBASELIB_UI_CXX}
139 140
    ${SLICERQTBASELIB_MOC_OUTPUT}
    ${SLICERQTBASELIB_QRC_SRCS}
141 142
    WRAP_EXCLUDE
    )
143 144 145 146
  
  # --------------------------------------------------------------------------
  # Source groups
  # --------------------------------------------------------------------------
147 148
  SOURCE_GROUP("Resources" FILES
    ${SLICERQTBASELIB_UI_SRCS}
149
    ${Slicer_SOURCE_DIR}/Resources/qSlicerLogos.qrc
150 151 152 153 154 155 156 157 158
    ${SLICERQTBASELIB_RESOURCES}
  )

  SOURCE_GROUP("Generated" FILES
    ${SLICERQTBASELIB_UI_CXX}
    ${SLICERQTBASELIB_MOC_OUTPUT}
    ${SLICERQTBASELIB_QRC_SRCS}
    ${dynamicHeaders}
  )
159 160 161 162
  
  # --------------------------------------------------------------------------
  # Build the library
  # --------------------------------------------------------------------------
163 164
  ADD_LIBRARY(${lib_name}
    ${SLICERQTBASELIB_SRCS}
165
    ${SLICERQTBASELIB_MOC_OUTPUT}
166 167 168
    ${SLICERQTBASELIB_UI_CXX}
    ${SLICERQTBASELIB_QRC_SRCS}
    )
169
  SET_TARGET_PROPERTIES(${lib_name} PROPERTIES LABELS ${lib_name})
170

171
  # Apply user-defined properties to the library target.
172 173
  IF(Slicer_LIBRARY_PROPERTIES)
    SET_TARGET_PROPERTIES(${lib_name} PROPERTIES ${Slicer_LIBRARY_PROPERTIES})
174
  ENDIF()
175 176 177 178 179

  SET(QT_LIBRARIES
    ${QT_QTCORE_LIBRARY}
    ${QT_QTGUI_LIBRARY}
    ${QT_QTWEBKIT_LIBRARY}
180
    )
181

182 183
  TARGET_LINK_LIBRARIES(${lib_name}
    ${QT_LIBRARIES}
184
    ${CTK_EXTERNAL_LIBRARIES}
185 186
    ${SLICERQTBASELIB_TARGET_LIBRARIES}
    )
187

188 189 190
  #-----------------------------------------------------------------------------
  # Install library
  #-----------------------------------------------------------------------------
191
  INSTALL(TARGETS ${lib_name}
192 193 194
    RUNTIME DESTINATION ${Slicer_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
    LIBRARY DESTINATION ${Slicer_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
    ARCHIVE DESTINATION ${Slicer_INSTALL_LIB_DIR} COMPONENT Development
195
  )
196 197
  
  # --------------------------------------------------------------------------
198
  # Install headers
199 200 201 202 203 204 205 206 207 208 209
  # --------------------------------------------------------------------------
  IF(NOT Slicer_INSTALL_NO_DEVELOPMENT)
    # Install headers
    FILE(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
    INSTALL(FILES
      ${headers}
      ${dynamicHeaders}
      DESTINATION ${Slicer_INSTALL_INCLUDE_DIR}/${PROJECT_NAME} COMPONENT Development
      )
  ENDIF()
  
210
  # --------------------------------------------------------------------------
211
  # PythonQt wrapping
212
  # --------------------------------------------------------------------------
213
  IF(Slicer_USE_PYTHONQT AND SLICERQTBASELIB_WRAP_PYTHONQT)
214
    SET(KIT_PYTHONQT_SRCS) # Clear variable
215 216 217 218
    ctkMacroWrapPythonQt("org.slicer.base" ${lib_name}
      KIT_PYTHONQT_SRCS "${SLICERQTBASELIB_SRCS}" FALSE)
    ADD_LIBRARY(${lib_name}PythonQt STATIC ${KIT_PYTHONQT_SRCS})
    TARGET_LINK_LIBRARIES(${lib_name}PythonQt ${lib_name})
219
    IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
220
      SET_TARGET_PROPERTIES(${lib_name}PythonQt PROPERTIES COMPILE_FLAGS "-fPIC")
221 222
    ENDIF()
  ENDIF()
223 224 225 226 227
  
  # --------------------------------------------------------------------------
  # Export target
  # --------------------------------------------------------------------------
  SET_PROPERTY(GLOBAL APPEND PROPERTY Slicer_TARGETS ${SLICERQTBASELIB_NAME})
228

229
ENDMACRO()