CMakeLists.txt 6.68 KB
Newer Older
1
project(MRMLIDImageIO)
2

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#-----------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.2)
#-----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# See http://cmake.org/cmake/help/cmake-2-8-docs.html#section_Policies for details
#-----------------------------------------------------------------------------

SET(project_policies
  CMP0001 # NEW: CMAKE_BACKWARDS_COMPATIBILITY should no longer be used.
  CMP0002 # NEW: Logical target names must be globally unique.
  CMP0003 # NEW: Libraries linked via full path no longer produce linker search paths.
  CMP0004 # NEW: Libraries linked may NOT have leading or trailing whitespace.
  CMP0005 # NEW: Preprocessor definition values are now escaped automatically.
  CMP0006 # NEW: Installing MACOSX_BUNDLE targets requires a BUNDLE DESTINATION.
  CMP0007 # NEW: List command no longer ignores empty elements.
  CMP0008 # NEW: Libraries linked by full-path must have a valid library file name.
  CMP0009 # NEW: FILE GLOB_RECURSE calls should not follow symlinks by default.
  CMP0010 # NEW: Bad variable reference syntax is an error.
  CMP0011 # NEW: Included scripts do automatic cmake_policy PUSH and POP.
  CMP0012 # NEW: if() recognizes numbers and boolean constants.
  CMP0013 # NEW: Duplicate binary directories are not allowed.
  CMP0014 # NEW: Input directories must have CMakeLists.txt
  )
FOREACH(policy ${project_policies})
  IF(POLICY ${policy})
    CMAKE_POLICY(SET ${policy} NEW)
  ENDIF()
ENDFOREACH()
32

33
34
35
36
37
38
39
40
41
42
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})

if(NOT DEFINED BUILD_SHARED_LIBS)
  option(BUILD_SHARED_LIBS "Build with shared libraries." ON)
endif(NOT DEFINED BUILD_SHARED_LIBS)
 
43
44
# --------------------------------------------------------------------------
# Include dirs
45
# --------------------------------------------------------------------------
46
set(include_dirs
47
48
  ${CMAKE_CURRENT_SOURCE_DIR}
  ${CMAKE_CURRENT_BINARY_DIR}
49
50
  ${MRML_SOURCE_DIR}
  ${MRML_BINARY_DIR}
51
  )
52
include_directories(${include_dirs})
53

54
55
56
57
# --------------------------------------------------------------------------
# Configure headers
# --------------------------------------------------------------------------
set(configure_header_file itkMRMLIDImageIOConfigure.h)
58
configure_file(
59
60
  ${CMAKE_CURRENT_SOURCE_DIR}/${configure_header_file}.in 
  ${CMAKE_CURRENT_BINARY_DIR}/${configure_header_file}
61
62
  )

63
64
65
66
67
68
69
70
71
72
73
74
# --------------------------------------------------------------------------
# Install headers
# --------------------------------------------------------------------------
IF(NOT DEFINED ${PROJECT_NAME}_INSTALL_NO_DEVELOPMENT)
  SET(${PROJECT_NAME}_INSTALL_NO_DEVELOPMENT ON)
ENDIF()
IF(NOT ${PROJECT_NAME}_INSTALL_NO_DEVELOPMENT)
  file(GLOB headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
  install(
    FILES ${headers} ${CMAKE_CURRENT_BINARY_DIR}/${configure_header_file}
    DESTINATION include/${PROJECT_NAME} COMPONENT Development)
ENDIF()
75
76
77

# --------------------------------------------------------------------------
# Sources
78
# --------------------------------------------------------------------------
79
80
81
82
83
84
set(MRMLIDImageIO_SRCS
  itkMRMLIDImageIO.cxx
  itkMRMLIDImageIOFactory.cxx
  )

# --------------------------------------------------------------------------
85
86
# Build library
# --------------------------------------------------------------------------
87
# Note: Library name is different from the directory name !
88
set(lib_name MRMLIDIO)
89
90
91
92
93
94

SET(srcs ${MRMLIDImageIO_SRCS})
add_library(${lib_name} ${srcs})

set(libs MRML)
target_link_libraries(${lib_name} ${libs})
95

96
# Apply user-defined properties to the library target.
97
IF(Slicer_LIBRARY_PROPERTIES)
98
99
  SET_TARGET_PROPERTIES(${lib_name} PROPERTIES ${Slicer_LIBRARY_PROPERTIES})
ENDIF()
100

101
102
103
# --------------------------------------------------------------------------
# Install library
# --------------------------------------------------------------------------
104
105
106
107
108
109
110
111
112
113
114
IF(NOT DEFINED ${PROJECT_NAME}_INSTALL_BIN_DIR)
  SET(${PROJECT_NAME}_INSTALL_BIN_DIR bin)
ENDIF()
IF(NOT DEFINED ${PROJECT_NAME}_INSTALL_LIB_DIR)
  SET(${PROJECT_NAME}_INSTALL_LIB_DIR lib/${PROJECT_NAME})
ENDIF()

INSTALL(TARGETS ${lib_name}
  RUNTIME DESTINATION ${${PROJECT_NAME}_INSTALL_BIN_DIR} COMPONENT RuntimeLibraries
  LIBRARY DESTINATION ${${PROJECT_NAME}_INSTALL_LIB_DIR} COMPONENT RuntimeLibraries
  ARCHIVE DESTINATION ${${PROJECT_NAME}_INSTALL_LIB_DIR} COMPONENT Development
115
  )
116

117
118
119
120
121
# Shared library that when placed in ITK_AUTOLOAD_PATH, will add
# MRMLIDImageIO as an ImageIOFactory.  Need to have separate shared
# library for each new format. Note that the plugin library is placed
# in a special directory to speed up the searching for ImageIO
# factories (which improves the speed at which plugins run).
122

123
124
if(NOT DEFINED MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR)
  set(MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR lib/ITKFactories)
125
endif()
126

127
128
add_library(MRMLIDIOPlugin SHARED 
  itkMRMLIDIOPlugin.cxx
129
  )
130
131
132
133
set_target_properties(MRMLIDIOPlugin
  PROPERTIES 
  RUNTIME_OUTPUT_DIRECTORY 
  "${CMAKE_BINARY_DIR}/${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR}"
barre's avatar
barre committed
134
135
136
137
  LIBRARY_OUTPUT_DIRECTORY 
  "${CMAKE_BINARY_DIR}/${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR}"
  ARCHIVE_OUTPUT_DIRECTORY 
  "${CMAKE_BINARY_DIR}/${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR}"
138
  )
139
target_link_libraries(MRMLIDIOPlugin ${lib_name})
140

141
142
143
# --------------------------------------------------------------------------
# Install library - MRMLIDIO and MRMLIDOPlugin are installed in different locations
# --------------------------------------------------------------------------
144
install(TARGETS MRMLIDIOPlugin
145
146
  RUNTIME DESTINATION ${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR} COMPONENT RuntimeLibraries
  LIBRARY DESTINATION ${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR} COMPONENT RuntimeLibraries
147
  ARCHIVE DESTINATION ${${PROJECT_NAME}_INSTALL_LIB_DIR} COMPONENT Development
148
  )
149

150
151
# --------------------------------------------------------------------------
# Make a copy named '.so' for compatibility with the expectations
152
# of the ITK Factory mechanism on macs
153
# --------------------------------------------------------------------------
154
155
if(APPLE)
  add_custom_command(
156
    TARGET MRMLIDIOPlugin
barre's avatar
barre committed
157
    DEPENDS "${CMAKE_BINARY_DIR}/${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR}/libMRMLIDIOPlugin.dylib"
158
159
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy
barre's avatar
barre committed
160
161
    "${CMAKE_BINARY_DIR}/${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR}/libMRMLIDIOPlugin.dylib"
    "${CMAKE_BINARY_DIR}/${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR}/libMRMLIDIOPlugin.so"
162
    VERBATIM
163
    )
164
165
166
167
  install(FILES
    "${CMAKE_BINARY_DIR}/${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR}/libMRMLIDIOPlugin.so"
    DESTINATION ${MRMLIDImageIO_INSTALL_ITKFACTORIES_DIR}
    )
168
endif()