FindCamiTK.cmake 5.74 KB
Newer Older
1
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# - 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
#     set(CAMITK_VER_MAJ "2")
#     set(CAMITK_VER_MIN "1")
#
# 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

# we need at least version 2.1
if(NOT CAMITK_VER_MAJ)
    set(CAMITK_VER_MAJ "2")
    set(CAMITK_VER_MIN "1")
endif()

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

# first check if we can use the build version directly
find_path(CAMITK_ROOT_DIR_GUESS
          NAMES CamiTKAPI.h
          PATHS ${CMAKE_CURRENT_SOURCE_DIR}/../camitk/core
)
if (CAMITK_ROOT_DIR_GUESS)
    set(CAMITK_IS_INSTALLED FALSE)
    set(CAMITK_INSTALL_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/..) # default install dir
else()
    set(CAMITK_IS_INSTALLED TRUE)
endif()

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
    find_path(CAMITK_ROOT_DIR_GUESS
              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}"
    )

    mark_as_advanced(CAMITK_ROOT_DIR_GUESS)

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

    # if guess is alright
    if (CAMITK_ROOT_DIR_GUESS) 
      string(REGEX REPLACE "${CAMITK_INCLUDE_DIR_SUFFIX_TEMP}" "" CAMITK_INSTALL_ROOT_TEMP ${CAMITK_ROOT_DIR_GUESS})
      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
  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)
  set (CAMITK_TESTDATA_DIR ${CAMITK_INSTALL_ROOT}/share/${CAMITK_SHORT_VERSION_STRING}/testdata    CACHE PATH "CamiTK share dir. for test data" FORCE)
  mark_as_advanced(CAMITK_BIN_DIR CAMITK_LIB_DIR CAMITK_INCLUDE_DIR CAMITK_TESTDATA_DIR)

  # Needed due to installation reason
  link_directories(${CAMITK_INSTALL_ROOT}/lib)
  
  # update module path
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CAMITK_LIB_DIR}/cmake ${CAMITK_INSTALL_ROOT}/camitk/cmake/modules)

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