CMakeLists.txt 6.31 KB
Newer Older
1
cmake_minimum_required(VERSION 3.0)
Mathieu Faverge's avatar
Mathieu Faverge committed
2
project(VITE CXX C)
3

Mathieu Faverge's avatar
Mathieu Faverge committed
4 5 6 7
### The current version number
set (VITE_VERSION_MAJOR 1)
set (VITE_VERSION_MINOR 2)
set (VITE_VERSION_PATCH 0)
8

9 10 11
find_package(Git)
if(GIT_FOUND)
  execute_process(COMMAND ${GIT_EXECUTABLE} show --no-patch --format="%h %aI"
12
    OUTPUT_VARIABLE VITE_WC_INFO
13 14
    ERROR_VARIABLE  Git_info_error
    RESULT_VARIABLE Git_info_result
15 16
    OUTPUT_STRIP_TRAILING_WHITESPACE)

17 18 19
  if(NOT ${Git_info_result} EQUAL 0)
    set(VITE_WC_REVISION "")
    set(VITE_WC_DATE     "")
20
  else()
21 22 23 24
    string(REGEX REPLACE "^\"(.*) (.*)\"$"
      "\\1" VITE_WC_REVISION "${VITE_WC_INFO}")
    string(REGEX REPLACE "^\"(.*) (.*)\"$"
      "\\2" VITE_WC_DATE "${VITE_WC_INFO}")
25 26 27 28 29 30 31 32 33
  endif()
endif()

if (NOT ${VITE_WC_REVISION} STREQUAL "")
  set (VITE_VERSION "r${VITE_WC_REVISION}")
else()
  set (VITE_VERSION "${VITE_VERSION_MAJOR}.${VITE_VERSION_MINOR}.${VITE_VERSION_PATCH}")
endif()

34

35
if (NOT ${VITE_WC_DATE} STREQUAL "")
Mathieu Faverge's avatar
Mathieu Faverge committed
36
  set (VITE_DATE "\"${VITE_WC_DATE}\"")
37 38 39 40
else()
  if(UNIX)
    set(_vite_SAVED_LC_ALL "$ENV{LC_ALL}")
    set(ENV{LC_ALL} C)
41

42 43 44 45 46
    execute_process(COMMAND date +"%B %Y"
      OUTPUT_VARIABLE VITE_DATE
      ERROR_VARIABLE vite_date_error
      RESULT_VARIABLE vite_date_result
      OUTPUT_STRIP_TRAILING_WHITESPACE )
47

48 49 50 51 52
    # restore the previous LC_ALL
    set(ENV{LC_ALL} ${_vite_SAVED_LC_ALL})
  else()
    set(VITE_DATE "")
  endif()
53 54
endif()

55 56
message(STATUS "Current revision is ${VITE_VERSION} from ${VITE_DATE}")

Mathieu Faverge's avatar
Mathieu Faverge committed
57
if(COMMAND CMAKE_POLICY)
58
  # CMP0003: add the link paths to the link command as with cmake 2.4
Mathieu Faverge's avatar
Mathieu Faverge committed
59 60
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND CMAKE_POLICY)
61

Mathieu Faverge's avatar
Mathieu Faverge committed
62 63 64 65 66 67 68 69
### Misc options
option(BUILD_SHARED_LIBS
  "Build shared libraries" OFF)
option(BUILD_64bits
  "Build 64 bits mode" ON)
if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build, options are None, Debug, Release, RelWithDebInfo and MinSizeRel." FORCE)
endif(NOT CMAKE_BUILD_TYPE)
70

Mathieu Faverge's avatar
Mathieu Faverge committed
71 72 73 74 75 76
# cmake modules setup
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
include (CMakeDetermineSystem)
include (CheckCCompilerFlag)
include (CheckFunctionExists)
include (CheckSymbolExists)
77 78
include (CheckIncludeFile)
include (CheckIncludeFileCXX)
Mathieu Faverge's avatar
Mathieu Faverge committed
79
include (CheckIncludeFiles)
80
include (CheckLibraryExists)
81
include (CMakeDependentOption)
82

Mathieu Faverge's avatar
Mathieu Faverge committed
83
### Required Packages
François Trahay's avatar
François Trahay committed
84
# Try to find Qt5 : http://forum.openscenegraph.org/viewtopic.php?t=11431
85
option(USE_QT5
Mathieu Faverge's avatar
Mathieu Faverge committed
86
  "Use QT5 instead of QT4" ON)
87 88 89 90 91 92 93 94 95 96

if (USE_QT5)
  # QUIET option disables messages if the package cannot be found.
  find_package(Qt5Widgets QUIET)
  if(Qt5Widgets_FOUND)
    # CMake 2.8.8 or greater required for qt5 use
    if("${CMAKE_VERSION}" VERSION_GREATER 2.8.7)
      set(USE_QT5 ON)
    endif()
  endif()
François Trahay's avatar
François Trahay committed
97 98

  set(CMAKE_AUTOMOC ON)
99 100 101 102 103 104
  find_package(Qt5Core    REQUIRED)
  find_package(Qt5Xml     REQUIRED)
  find_package(Qt5Widgets REQUIRED)
  find_package(Qt5OpenGL  REQUIRED)
#  find_package(Qt5UiTools REQUIRED)

François Trahay's avatar
François Trahay committed
105
else(USE_QT5) # Try Qt4
106

François Trahay's avatar
François Trahay committed
107 108 109 110
  find_package(Qt4 COMPONENTS QtCore QtGui QtXml REQUIRED)
  set(QT_USE_QTUITOOLS ON)
  set(QT_USE_QTOPENGL ON)
  include(${QT_USE_FILE})
111

François Trahay's avatar
François Trahay committed
112
endif(USE_QT5)
113

114 115
find_package(OpenGL)
#find_package(GLU)
116

Mathieu Faverge's avatar
Mathieu Faverge committed
117
### Optimization options
118
option(VITE_ENABLE_SERIALIZATION
Mathieu Faverge's avatar
Mathieu Faverge committed
119
  "Enable the support of Boost Serialization." OFF)
120
option(VITE_ENABLE_VBO
121
  "Enable the support of VBO." ON)
122
option(VITE_ENABLE_MT_PARSERS
123
  "Enable multi-threading in parsers." OFF)
124

125 126 127
### Debug options
option(VITE_DBG_MEMORY_USAGE
  "Enable statistic on memory usage." OFF)
128 129
cmake_dependent_option(VITE_DBG_MEMORY_TRACE
  "Enable trace generation of memory usage (requires MEMORY_USAGE)." OFF "VITE_DBG_MEMORY_USAGE" OFF)
130

Mathieu Faverge's avatar
Mathieu Faverge committed
131
### Trace format options
132
option(VITE_ENABLE_OTF
Mathieu Faverge's avatar
Mathieu Faverge committed
133
  "Enable the support of OTF file format." OFF)
François Trahay's avatar
François Trahay committed
134 135
option(VITE_ENABLE_OTF2
  "Enable the support of OTF2 file format." OFF)
136
option(VITE_ENABLE_TAU
Mathieu Faverge's avatar
Mathieu Faverge committed
137 138 139 140 141 142 143 144 145 146 147 148 149
  "Enable the support of TAU file format." OFF)

# timeval, timespec, realtime clocks, etc
include(CheckStructHasMember)
check_struct_has_member("struct timespec" tv_nsec time.h HAVE_TIMESPEC_TV_NSEC)
if( NOT HAVE_TIMESPEC_TV_NSEC )
  add_definitions(-D_GNU_SOURCE)
  check_struct_has_member("struct timespec" tv_nsec time.h HAVE_TIMESPEC_TV_NSEC)
endif( NOT HAVE_TIMESPEC_TV_NSEC )
check_library_exists(rt clock_gettime "" HAVE_CLOCK_GETTIME)
if( HAVE_CLOCK_GETTIME )
  set(EXTRA_LIBS "${EXTRA_LIBS};rt")
endif( HAVE_CLOCK_GETTIME )
150

Mathieu Faverge's avatar
Mathieu Faverge committed
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
# stdlib, stdio, string, getopt, etc
check_include_files(stdarg.h HAVE_STDARG_H)
check_function_exists(va_copy HAVE_VA_COPY)
if (NOT HAVE_VA_COPY)
  check_function_exists(__va_copy HAVE_UNDERSCORE_VA_COPY)
endif (NOT HAVE_VA_COPY)
check_function_exists(asprintf HAVE_ASPRINTF)
check_function_exists(vasprintf HAVE_VASPRINTF)
check_include_files(getopt.h HAVE_GETOPT_H)
check_include_files(unistd.h HAVE_UNISTD_H)
check_function_exists(getopt_long HAVE_GETOPT_LONG)
check_include_files(errno.h HAVE_ERRNO_H)
check_include_files(stddef.h HAVE_STDDEF_H)
check_function_exists(getrusage HAVE_GETRUSAGE)
check_include_files(limits.h HAVE_LIMITS_H)
check_include_files(string.h HAVE_STRING_H)
167

Mathieu Faverge's avatar
Mathieu Faverge committed
168 169
#
# Find optional packages
170
#
171

172 173
# Search for Boost
#    Components : filesystem, iostreams, programoptions, python, regex,
Mathieu Faverge's avatar
Mathieu Faverge committed
174 175
#                 serialization, signals, system, thread, wave
if(VITE_ENABLE_SERIALIZATION)
François Trahay's avatar
François Trahay committed
176
  find_package( Boost COMPONENTS serialization thread iostreams system)
Mathieu Faverge's avatar
Mathieu Faverge committed
177 178 179
endif(VITE_ENABLE_SERIALIZATION)

if(VITE_ENABLE_VBO)
180
  find_package(GLEW REQUIRED)
181
  include_directories(${GLEW_INCLUDE_PATH})
182 183 184 185
  if (GLM_INC)
    include_directories(${GLM_INC})
    list(APPEND CMAKE_REQUIRED_INCLUDES ${GLM_INC})
  endif()
186 187
  check_include_file_cxx(glm/glm.hpp HAVE_GLM_H)
  if (NOT HAVE_GLM_H)
188
    message(FATAL_ERROR "libglm-dev package is required, you might specify the include directory where to find glm/glm.hpp through -DGLM_INC=/path/to/glm")
189
  endif()
Mathieu Faverge's avatar
Mathieu Faverge committed
190 191 192 193 194 195
endif(VITE_ENABLE_VBO)

if(VITE_ENABLE_OTF)
  find_package(OTF)
endif(VITE_ENABLE_OTF)

François Trahay's avatar
François Trahay committed
196 197 198 199
if(VITE_ENABLE_OTF2)
  find_package(OTF2)
endif(VITE_ENABLE_OTF2)

Mathieu Faverge's avatar
Mathieu Faverge committed
200 201 202
if(VITE_ENABLE_TAU)
  find_package(TAU)
endif(VITE_ENABLE_TAU)
203

204
if(VITE_ENABLE_MT_PARSERS)
Mathieu Faverge's avatar
Mathieu Faverge committed
205
  add_definitions(-DMT_PARSING)
206 207
endif()

208 209 210 211 212 213 214 215
if(VITE_DBG_MEMORY_USAGE)
  add_definitions(-DMEMORY_USAGE)
endif()

if(VITE_DBG_MEMORY_TRACE)
  add_definitions(-DMEMORY_TRACE)
endif()

216 217 218
# Configuration header
configure_file (
  "${CMAKE_CURRENT_SOURCE_DIR}/src/common/ViteConfig.hpp.in"
219
  "${CMAKE_CURRENT_BINARY_DIR}/src/common/ViteConfig.hpp")
220

Mathieu Faverge's avatar
Mathieu Faverge committed
221
add_subdirectory(src)
222
add_subdirectory(plugins)
Mathieu Faverge's avatar
Mathieu Faverge committed
223 224

include(CPackLists.txt)