Skip to content

Instantly share code, notes, and snippets.

@dlrdave
Last active December 15, 2015 00:28
Show Gist options
  • Save dlrdave/5172611 to your computer and use it in GitHub Desktop.
Save dlrdave/5172611 to your computer and use it in GitHub Desktop.
EchoRequirements: A minimal project CMakeLists.txt file whose sole purpose is to spit out VTK and ITK compiler definitions, include directories and libraries to link to.
#
# EchoRequirements
#
# A minimal project CMakeLists.txt file whose sole purpose is to spit out
# VTK and ITK compiler definitions, include directories and libraries to
# link to.
#
# This is for when you want to use VTK and ITK from a non-CMake-based
# project, and need to know all the stuff that CMake does for you but don't
# want to CMake-ify your project just to get it done today. Use the output
# from this to figure out how to add VTK and ITK libs to your hand-crafted
# Visual Studio or Xcode project files.
#
# What this doesn't do for you is to get all the extra libraries that may
# be required as transitive dependencies of the VTK and ITK libraries
# themselves. You may still need some underlying system libraries on your
# link line to resolve symbols at link time. But this should get you most
# of the way there.
#
cmake_minimum_required(VERSION 2.8)
project(EchoRequirements)
set(ER_VTK_COMPONENTS
ALL
CACHE STRING
"Semi-colon separated list of VTK components, set to 'ALL' for everything"
)
if("${ER_VTK_COMPONENTS}" STREQUAL "ALL")
find_package(VTK 6.0 NO_MODULE REQUIRED)
else()
find_package(VTK 6.0 COMPONENTS ${ER_VTK_COMPONENTS} NO_MODULE REQUIRED)
endif()
include(${VTK_USE_FILE})
set(ER_ITK_COMPONENTS
ALL
CACHE STRING
"Semi-colon separated list of ITK components, set to 'ALL' for everything"
)
if("${ER_ITK_COMPONENTS}" STREQUAL "ALL")
find_package(ITK 4.4 NO_MODULE REQUIRED)
else()
find_package(ITK 4.4 COMPONENTS ${ER_ITK_COMPONENTS} NO_MODULE REQUIRED)
endif()
include(${ITK_USE_FILE})
# Assumes vtkCommonCore is always enabled... to derive the default library
# suffix and the VTK library directory.
#
get_property(vtkCommonCore_LOCATION TARGET vtkCommonCore PROPERTY LOCATION)
get_filename_component(vtkCommonCore_DIR "${vtkCommonCore_LOCATION}" PATH)
string(REGEX REPLACE "^.*(\\.[^.]+)$" "\\1"
vtkCommonCore_EXTENSION "${vtkCommonCore_LOCATION}")
# Assumes ITKCommon is always enabled... to derive the ITK library directory.
#
get_property(ITKCommon_LOCATION TARGET ITKCommon PROPERTY LOCATION)
get_filename_component(ITKCommon_DIR "${ITKCommon_LOCATION}" PATH)
string(REGEX REPLACE "^.*(\\.[^.]+)$" "\\1"
ITKCommon_EXTENSION "${ITKCommon_LOCATION}")
set(ER_LIB_SUFFIX "${vtkCommonCore_EXTENSION}"
CACHE STRING
"Suffix to use on printed list of libraries"
)
message("# VTK compiler flags")
message("VTK_REQUIRED_C_FLAGS='${VTK_REQUIRED_C_FLAGS}'")
message("VTK_REQUIRED_CXX_FLAGS='${VTK_REQUIRED_CXX_FLAGS}'")
message("VTK_REQUIRED_EXE_LINKER_FLAGS='${VTK_REQUIRED_EXE_LINKER_FLAGS}'")
message("VTK_REQUIRED_MODULE_LINKER_FLAGS='${VTK_REQUIRED_MODULE_LINKER_FLAGS}'")
message("VTK_REQUIRED_SHARED_LINKER_FLAGS='${VTK_REQUIRED_SHARED_LINKER_FLAGS}'")
message("")
message("# VTK_DEFINITIONS - compiler /D args")
foreach(def ${VTK_DEFINITIONS})
message(${def})
endforeach()
message("# /VTK_DEFINITIONS")
message("")
message("# VTK_INCLUDE_DIRS - compiler /I args")
foreach(dir ${VTK_INCLUDE_DIRS})
message(${dir})
endforeach()
message("# /VTK_INCLUDE_DIRS")
message("")
message("# Adjust ER_LIB_SUFFIX if '${ER_LIB_SUFFIX}' is not what you're looking for...")
message("#")
message("# VTK_LIBRARIES - pass as input to the linker")
set(suff "-${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION}${ER_LIB_SUFFIX}")
foreach(lib ${VTK_LIBRARIES})
message(${lib}${suff})
endforeach()
message("# As one giant string:")
string(REPLACE ";" "${suff};" vtk_libs "${VTK_LIBRARIES}")
set(vtk_libs "${vtk_libs}${suff}")
message("VTK_LIBRARIES='${vtk_libs}'")
message("# /VTK_LIBRARIES")
message("")
message("# vtkCommonCore_DIR: Not an officially VTK-provided CMake variable.")
message("# VTK now uses imported targets to give per-target directory")
message("# settings. Presumably other libs are in this directory too...")
message("vtkCommonCore_DIR='${vtkCommonCore_DIR}'")
message("vtkCommonCore_EXTENSION='${vtkCommonCore_EXTENSION}'")
message("vtkCommonCore_LOCATION='${vtkCommonCore_LOCATION}'")
message("")
message("# VTK_LIBRARY_DIRS - from what I can see, this is always empty")
message("# in VTK 6 and later")
foreach(dir ${VTK_LIBRARY_DIRS})
message(${dir})
endforeach()
message("# /VTK_LIBRARY_DIRS")
message("")
message("# VTK CMake module path")
message("VTK_CMAKE_DIR='${VTK_CMAKE_DIR}'")
message("")
message("# Other possible variables of interest")
message("VTK_DIR='${VTK_DIR}'")
message("VTK_USE_FILE='${VTK_USE_FILE}'")
message("VTK_VERSION='${VTK_VERSION}'")
message("VTK_MODULES_ENABLED='${VTK_MODULES_ENABLED}'")
message("")
message("# ITK compiler flags")
message("ITK_REQUIRED_C_FLAGS='${ITK_REQUIRED_C_FLAGS}'")
message("ITK_REQUIRED_CXX_FLAGS='${ITK_REQUIRED_CXX_FLAGS}'")
message("ITK_REQUIRED_EXE_LINKER_FLAGS='${ITK_REQUIRED_EXE_LINKER_FLAGS}'")
message("ITK_REQUIRED_MODULE_LINKER_FLAGS='${ITK_REQUIRED_MODULE_LINKER_FLAGS}'")
message("ITK_REQUIRED_SHARED_LINKER_FLAGS='${ITK_REQUIRED_SHARED_LINKER_FLAGS}'")
message("")
message("# ITK_DEFINITIONS - compiler /D args")
foreach(def ${ITK_DEFINITIONS})
message(${def})
endforeach()
message("# /ITK_DEFINITIONS")
message("")
message("# ITK_INCLUDE_DIRS - compiler /I args")
foreach(dir ${ITK_INCLUDE_DIRS})
message(${dir})
endforeach()
message("# /ITK_INCLUDE_DIRS")
message("")
message("# Adjust ER_LIB_SUFFIX if '${ER_LIB_SUFFIX}' is not what you're looking for...")
message("#")
message("# ITK_LIBRARIES - pass as input to the linker")
set(suff "-${ITK_VERSION_MAJOR}.${ITK_VERSION_MINOR}${ER_LIB_SUFFIX}")
foreach(lib ${ITK_LIBRARIES})
message(${lib}${suff})
endforeach()
message("# As one giant string:")
string(REPLACE ";" "${suff};" itk_libs "${ITK_LIBRARIES}")
set(itk_libs "${itk_libs}${suff}")
message("ITK_LIBRARIES='${itk_libs}'")
message("# /ITK_LIBRARIES")
message("")
message("# ITKCommon_DIR: Not an officially ITK-provided CMake variable.")
message("# ITK now uses imported targets to give per-target directory")
message("# settings. Presumably other libs are in this directory too...")
message("ITKCommon_DIR='${ITKCommon_DIR}'")
message("ITKCommon_EXTENSION='${ITKCommon_EXTENSION}'")
message("ITKCommon_LOCATION='${ITKCommon_LOCATION}'")
message("")
message("# ITK_LIBRARY_DIRS - from what I can see, this is always empty")
message("# in ITK 4.4 and later")
foreach(dir ${ITK_LIBRARY_DIRS})
message(${dir})
endforeach()
message("# /ITK_LIBRARY_DIRS")
message("")
message("# ITK CMake module path")
message("ITK_CMAKE_DIR='${ITK_CMAKE_DIR}'")
message("")
message("# Other possible variables of interest")
message("ITK_DIR='${ITK_DIR}'")
message("ITK_USE_FILE='${ITK_USE_FILE}'")
message("ITK_VERSION='${ITK_VERSION}'")
message("ITK_MODULES_ENABLED='${ITK_MODULES_ENABLED}'")
message("")
# Irrelevant for this project:
mark_as_advanced(CMAKE_INSTALL_PREFIX)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment