FindCamiTK.cmake 7.62 KB
Newer Older
1
2
3
4
5
6
# - Try to find CamiTK
# 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
7
8
#     set(CAMITK_VER_MAJ "1")
#     set(CAMITK_VER_MIN "4")
9
10
11
12
13
14
15
16
17
18
19
20
#
# 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

21
22
# we need at least version 3.1
if(NOT CAMITK_VER_MAJ AND NOT CAMITK_VER_MIN)
23
    set(CAMITK_VER_MAJ "3")
24
    set(CAMITK_VER_MIN "1")
25
26
27
28
29
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
30
31
32
33
34
35
# 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
36
37
          NAMES CamiTKAPI.h
          PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../camitk/core
promayon's avatar
promayon committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
    )
    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()
54
    set(CAMITK_IS_INSTALLED FALSE)
mat's avatar
mat committed
55
56
57
    if (NOT CAMITK_INSTALL_ROOT)
      set(CAMITK_INSTALL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) # default install dir
    endif()
58
59
    # 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
60
    # This is a multi CEP, CAMITK_INSTALL_ROOT should be set
cfouard's avatar
cfouard committed
61
    message(STATUS "Find CamiTK inside multi CEP: ${CAMITK_INSTALL_ROOT}")
promayon's avatar
promayon committed
62
63
endif() # CAMITK_MULTI_CEP

64
65
66
67
68
69
70
71
72

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
73
    find_path(CAMITK_ROOT_DIR_GUESS
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
              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
89
    mark_as_advanced(CAMITK_ROOT_DIR_GUESS)
90
91
92
93

    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
94
95
    if (CAMITK_ROOT_DIR_GUESS) 
      string(REGEX REPLACE "${CAMITK_INCLUDE_DIR_SUFFIX_TEMP}" "" CAMITK_INSTALL_ROOT_TEMP ${CAMITK_ROOT_DIR_GUESS})
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
      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
118
119
120
121
  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
122
    set (CAMITK_TESTDATA_DIR ${CAMITK_INSTALL_ROOT}/share/${CAMITK_SHORT_VERSION_STRING}/testdata    CACHE PATH "CamiTK share dir. for test data" FORCE)
123
124
125
126
127
  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
128
    set (CAMITK_TESTDATA_DIR ${CAMITK_BUILD_ROOT}/share/testdata CACHE PATH "CamiTK share dir. for test data" FORCE)
129
  endif()
mat's avatar
mat committed
130
  mark_as_advanced(CAMITK_BIN_DIR CAMITK_LIB_DIR CAMITK_INCLUDE_DIR CAMITK_TESTDATA_DIR)
131
132

  # Needed due to installation reason
mat's avatar
mat committed
133
  link_directories(${CAMITK_INSTALL_ROOT}/lib)
134
135
  
  # update module path
136
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CAMITK_LIB_DIR}/cmake ${CAMITK_INSTALL_ROOT}/camitk/cmake/modules ${CMAKE_CURRENT_SOURCE_DIR}/../camitk/cmake/modules  ${CAMITK_INSTALL_ROOT}/share/${CAMITK_SHORT_VERSION_STRING}/cmake)
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166

  # include useful modules
  include(CamiTKVariables)
  include(CamiTKMacros)

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