FindCamiTK.cmake 7.77 KB
Newer Older
promayon's avatar
promayon committed
1
2
3
4
#
# DO NOT EDIT THIS FILE OR YOU WILL DAMAGE ALL YOUR CONFIGURATION
#
# Try to find CamiTK
5
6
7
8
9
# This module can be used to find CamiTK.
# CamiTK can be either installed (CAMITK_IS_INSTALLED will be set to true) or
# not installed. In the latter this module will use the build directory
#
# Prior to calling find(CamiTK), you can set which version you like to use
promayon's avatar
promayon committed
10
11
#     set(CAMITK_VER_MAJ "1")
#     set(CAMITK_VER_MIN "4")
12
13
14
15
16
17
18
19
20
21
22
23
#
# Once this module has run, the following variables will be properly defined
#  CAMITK_FOUND - system has CamiTK
#  CAMITK_INSTALL_ROOT - root installation for CamiTK
#  CAMITK_INCLUDE_DIRECTORIES - the CamiTK include directories
#  CAMITK_LIBRARIES - link these to use CamiTK
#  ... 
#  and all the other goodies
#
# Once found it is then easy to just use the CamiTK macros
# to build your extensions

24
25
# we need at least version 3.1
if(NOT CAMITK_VER_MAJ AND NOT CAMITK_VER_MIN)
26
    set(CAMITK_VER_MAJ "3")
27
    set(CAMITK_VER_MIN "1")
28
29
30
31
32
endif()

# CamiTK short version name we are looking for
set(CAMITK_SHORT_VERSION_STRING "camitk-${CAMITK_VER_MAJ}.${CAMITK_VER_MIN}")

promayon's avatar
promayon committed
33
34
35
36
37
38
# CAMITK_MULTI_CEP is not set if find(CamiTK) is called by a single CamiTK Extension Project
# if there is a multitude of CEP, set CAMITK_MULTI_CEP to TRUE in the global CMakeLists.txt
if (NOT CAMITK_MULTI_CEP)

    # first check if we can use the build version directly
    find_path(CAMITK_ROOT_DIR_GUESS
39
40
          NAMES CamiTKAPI.h
          PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../camitk/core
promayon's avatar
promayon committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
    )
    set(CAMITK_ROOT_DIR_GUESS_TESTED TRUE CACHE BOOL "Is variable ${CAMITK_ROOT_DIR_GUESS} already tested?")

    if (CAMITK_ROOT_DIR_GUESS AND NOT CAMITK_ROOT_DIR_GUESS_TESTED)
      set(CAMITK_IS_INSTALLED FALSE)
      # if this directory was checkouted inside camitk-timc, CAMITK_INSTALL_ROOT could be already defined by CMake when camitk-timc/camitk was parsed/configured
      # in this case, DO NOT reset CAMITK_INSTALL_ROOT
      if (NOT CAMITK_INSTALL_ROOT)
        set(CAMITK_INSTALL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) # default install dir
      endif()
      # camitk is not installed yet, use build dir for include and libs
      set(CAMITK_BUILD_ROOT ${CMAKE_CURRENT_BINARY_DIR}/..) 
   else()
      set(CAMITK_IS_INSTALLED TRUE)
   endif()
else()
57
    set(CAMITK_IS_INSTALLED FALSE)
mat's avatar
mat committed
58
59
60
    if (NOT CAMITK_INSTALL_ROOT)
      set(CAMITK_INSTALL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) # default install dir
    endif()
61
62
    # camitk is not installed yet, use build dir for include and libs
    set(CAMITK_BUILD_ROOT ${CMAKE_CURRENT_BINARY_DIR}/..) 
promayon's avatar
promayon committed
63
    # This is a multi CEP, CAMITK_INSTALL_ROOT should be set
cfouard's avatar
cfouard committed
64
    message(STATUS "Find CamiTK inside multi CEP: ${CAMITK_INSTALL_ROOT}")
promayon's avatar
promayon committed
65
66
endif() # CAMITK_MULTI_CEP

67
68
69
70
71
72
73
74
75

if (NOT CAMITK_INSTALL_ROOT)
    # name of the camitk core lib (as defined in CamiTKVariables)
    set(CAMITK_CORE_LIB_TEMP "camitkcore")

    # directory structure from install dir to look for CamiTKAPI.h
    set(CAMITK_INCLUDE_DIR_SUFFIX_TEMP "include/${CAMITK_SHORT_VERSION_STRING}/${CAMITK_CORE_LIB_TEMP}")

    # find the caracteristic header using a (reasonably) long good list for the guess
mat's avatar
mat committed
76
    find_path(CAMITK_ROOT_DIR_GUESS
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
              NAMES CamiTKAPI.h
              PATHS "/usr"
                    "/usr/local"
                    "C:/Programs"
                    "C:/Programs/camitk"
                    "C:/Dev"
                    "C:/Dev/camitk"
                    $ENV{CAMITK_DIR}
                    "${CMAKE_CURRENT_SOURCE_DIR}/.."
                    "${CMAKE_CURRENT_SOURCE_DIR}/../camitk"
                    "${CMAKE_CURRENT_SOURCE_DIR}/../camitktimc"
                    "${CMAKE_CURRENT_SOURCE_DIR}/../camitk-timc"
              PATH_SUFFIXES "${CAMITK_INCLUDE_DIR_SUFFIX_TEMP}"
    )

mat's avatar
mat committed
92
    mark_as_advanced(CAMITK_ROOT_DIR_GUESS)
93
94
95
96

    set(CAMITK_VERSION "${CAMITK_VER_MAJ}.${CAMITK_VER_MIN}" CACHE STRING "The CamiTK version to find")

    # if guess is alright
mat's avatar
mat committed
97
98
    if (CAMITK_ROOT_DIR_GUESS) 
      string(REGEX REPLACE "${CAMITK_INCLUDE_DIR_SUFFIX_TEMP}" "" CAMITK_INSTALL_ROOT_TEMP ${CAMITK_ROOT_DIR_GUESS})
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      set(CAMITK_INSTALL_ROOT ${CAMITK_INSTALL_ROOT_TEMP} CACHE PATH "${CAMITK_SHORT_VERSION_STRING} install root" FORCE)
    else()
      set(CAMITK_INSTALL_ROOT "" CACHE PATH "${CAMITK_SHORT_VERSION_STRING} install root")
    endif()
endif()

if(NOT ${CAMITK_INSTALL_ROOT} EQUAL "")

  # advertise the success
  message(STATUS "Found ${CAMITK_SHORT_VERSION_STRING}: ${CAMITK_INSTALL_ROOT}")
  set(CAMITK_FOUND TRUE)

  # Check dependencies
  find_package(Qt4 REQUIRED)
  include(${QT_USE_FILE})
  set (QT_USE_QT3SUPPORT OFF)

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

  # set CamiTK build variables
121
122
123
124
  if (CAMITK_IS_INSTALLED)
    set (CAMITK_BIN_DIR     ${CAMITK_INSTALL_ROOT}/bin                                     CACHE PATH "CamiTK bin dir." FORCE)
    set (CAMITK_LIB_DIR     ${CAMITK_INSTALL_ROOT}/lib/${CAMITK_SHORT_VERSION_STRING}      CACHE PATH "CamiTK lib dir." FORCE)
    set (CAMITK_INCLUDE_DIR ${CAMITK_INSTALL_ROOT}/include/${CAMITK_SHORT_VERSION_STRING}  CACHE PATH "CamiTK include dir." FORCE)
mat's avatar
mat committed
125
    set (CAMITK_TESTDATA_DIR ${CAMITK_INSTALL_ROOT}/share/${CAMITK_SHORT_VERSION_STRING}/testdata    CACHE PATH "CamiTK share dir. for test data" FORCE)
126
127
128
129
130
  else()
    # use build directory to get includes and lib
    set (CAMITK_BIN_DIR      ${CAMITK_BUILD_ROOT}/bin            CACHE PATH "CamiTK bin dir." FORCE)
    set (CAMITK_LIB_DIR      ${CAMITK_BUILD_ROOT}/lib            CACHE PATH "CamiTK lib dir." FORCE)
    set (CAMITK_INCLUDE_DIR  ${CAMITK_BUILD_ROOT}/include        CACHE PATH "CamiTK include dir." FORCE)
mat's avatar
mat committed
131
    set (CAMITK_TESTDATA_DIR ${CAMITK_BUILD_ROOT}/share/testdata CACHE PATH "CamiTK share dir. for test data" FORCE)
132
  endif()
mat's avatar
mat committed
133
  mark_as_advanced(CAMITK_BIN_DIR CAMITK_LIB_DIR CAMITK_INCLUDE_DIR CAMITK_TESTDATA_DIR)
134
135

  # Needed due to installation reason
mat's avatar
mat committed
136
  link_directories(${CAMITK_INSTALL_ROOT}/lib)
137
138
  
  # update module path
139
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CAMITK_LIB_DIR}/cmake ${CAMITK_INSTALL_ROOT}/share/cmake ${CAMITK_INSTALL_ROOT}/share/${CAMITK_SHORT_VERSION_STRING}/cmake ${CMAKE_CURRENT_SOURCE_DIR}/../camitk/cmake/modules)
140
141
142
143

  # include useful modules
  include(CamiTKVariables)
  include(CamiTKMacros)
144
  include(CamiTKTestMacros)
145
146
  # include package generation
  include(CamiTKExtensionPackaging)
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

  # set install path
  set (CMAKE_INSTALL_PREFIX ${CAMITK_INSTALL_ROOT} CACHE PATH "Path to install dir (deduced from CAMITK_INSTALL_ROOT)" FORCE)

  # check the following to define the proper output variables for an external extension
  # during compilation, set where everything (lib, exe, shared) goes
  set (EXTENSION_BUILD_DIR    ${CMAKE_BINARY_DIR})
  set (EXTENSION_BIN_DIR      ${EXTENSION_BUILD_DIR}/bin      CACHE PATH "CamiTK extension bin dir."     FORCE)
  set (EXTENSION_LIB_DIR      ${EXTENSION_BUILD_DIR}/lib      CACHE PATH "CamiTK extension lib dir."     FORCE)
  set (EXTENSION_INCLUDE_DIR  ${EXTENSION_BUILD_DIR}/include  CACHE PATH "CamiTK extension include dir." FORCE)
  set (EXTENSION_TESTDATA_DIR  ${EXTENSION_BUILD_DIR}/share/testdata  CACHE PATH "CamiTK share dir. for test data" FORCE)
  # the "normal" user does not need to see this
  mark_as_advanced(EXTENSION_BUILD_DIR EXTENSION_BIN_DIR EXTENSION_LIB_DIR EXTENSION_INCLUDE_DIR EXTENSION_TESTDATA_DIR)

  # Setup CMake Variable
  set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${EXTENSION_BIN_DIR} CACHE PATH "Single directory for all runtimes." FORCE)
  set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${EXTENSION_BIN_DIR} CACHE PATH "Single directory for all dynamic/shared libs." FORCE)
  set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${EXTENSION_LIB_DIR} CACHE PATH "Single directory for all archives." FORCE)

  # no need to see this
  mark_as_advanced ( CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY)

else()
  message(FATAL_ERROR "Cannot find CamiTK core, please set the CAMITK_INSTALL_ROOT variable")
endif()