OpenWalnut.cmake 24.3 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
#---------------------------------------------------------------------------
#
# Project: OpenWalnut ( http://www.openwalnut.org )
#
# Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
# For more information see http:#www.openwalnut.org/copying
#
# This file is part of OpenWalnut.
#
# OpenWalnut is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenWalnut is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with OpenWalnut. If not, see <http:#www.gnu.org/licenses/>.
#
#---------------------------------------------------------------------------

INCLUDE( OpenWalnutUtils )

27 28 29 30 31
# name of the core lib. Used when linking modules or other GUI
SET( OW_LIB_OPENWALNUT "openwalnut" )

# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
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
# This is executed on inclusion. It sets up everything needed. Beginning with compiler and OpenWalnut options and the third-party dependencies.
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# guard against in-source builds
IF( ${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR} )
  MESSAGE( FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. (you may need to remove CMakeCache.txt" )
ENDIF()

# the build types
IF( NOT CMAKE_BUILD_TYPE )
    SET( CMAKE_BUILD_TYPE Release
         CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo"
         FORCE
       )
ENDIF( NOT CMAKE_BUILD_TYPE )

# guard against typos in build-type strings
STRING( TOLOWER "${CMAKE_BUILD_TYPE}" cmake_build_type_tolower)
IF( NOT cmake_build_type_tolower STREQUAL "debug" AND
    NOT cmake_build_type_tolower STREQUAL "release" AND
    NOT cmake_build_type_tolower STREQUAL "relwithdebinfo" AND
    NOT cmake_build_type_tolower STREQUAL "")
  MESSAGE( SEND_ERROR "Unknown build type \"${CMAKE_BUILD_TYPE}\". Allowed values are Debug, Release, RelWithDebInfo  and \"\" (case-insensitive).")
ENDIF()

# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# External Building Support (find OpenWalnut if needed)
61 62 63
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# 1: some needed path setup for version headers. This is needed for searching OW.
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# where to put the header
SET( OW_VERSION_HEADER_DIRECTORY_RELATIVE "versionHeader" )

# this is the name of the INTERNAL OpenWalnut version header. It is needed for searching OW. Do not mix this up with the version header filename
# you use for the toolbox (external module building).
SET( OW_INTERNAL_VERSION_HEADER_FILENAME "core/WVersion.h" )

# ---------------------------------------------------------------------------------------------------------------------------------------------------
# 2: start build system and either search OW or use it internally.
# ---------------------------------------------------------------------------------------------------------------------------------------------------

79 80 81
MESSAGE( STATUS "----------------------------------------------------------------------" )
MESSAGE( STATUS "Welcome! This is OpenWalnut Build System." )

82 83 84 85 86
# if this is included for external module building, find OpenWalnut.
IF( NOT ${OW_EXTERNAL_MODULE} )
    # to allow non-core code to access core and ext absolutely
    INCLUDE_DIRECTORIES( ${PROJECT_SOURCE_DIR} )
ELSE()
87
    MESSAGE( STATUS "Searching OpenWalnut ..." )   
88

89 90 91 92 93 94 95 96 97 98 99 100
    FIND_PATH( OPENWALNUT_INCLUDE_DIR core/kernel/WKernel.h ${OPENWALNUT_INCLUDEDIR} $ENV{OPENWALNUT_INCLUDEDIR} /usr/include/openwalnut /usr/local/include/openwalnut )
    FIND_LIBRARY( OPENWALNUT_LIBRARIES NAMES ${OW_LIB_OPENWALNUT} lib${OW_LIB_OPENWALNUT} HINTS 
                  ${OPENWALNUT_LIBDIR}
                  $ENV{OPENWALNUT_LIBDIR} 
                  /usr/lib
                  /usr/local/lib
                  /usr
                  /usr/local
                  /usr/local/openwalnut
                  /usr/local/OpenWalnut
                  $ENV{PROGRAMFILES}/OpenWalnut )

101 102 103 104 105 106 107 108 109 110 111
    # find the version header. There are two possibilities here: 
    # 1: we find it inside the include dir -- this is the case if we found an installed OW
    # 2: we find it inside the lib/../versionHeader dir -- this is the case if we found a local build of OW
    # NOTE: this relies on OPENWALNUT_INCLUDE_DIR which is filled above. If it is empty, no OW was found so it is not bad to not find the version
    # header.
    FIND_PATH( OPENWALNUT_VERSIONHEADER_DIR ${OW_INTERNAL_VERSION_HEADER_FILENAME} 
                # 1: we search in the hopefully found include dir:    
                ${OPENWALNUT_INCLUDE_DIR}
                # 2: we search in the build dir
                "$ENV{OPENWALNUT_LIBDIR}/../${OW_VERSION_HEADER_DIRECTORY_RELATIVE}" 
             )
112
    SET( OPENWALNUT_FOUND FALSE )
113 114 115

    # do not confuse the user with this
    MARK_AS_ADVANCED( FORCE OPENWALNUT_INCLUDE_DIR )
116
    MARK_AS_ADVANCED( FORCE OPENWALNUT_VERSIONHEADER_DIR )
117 118 119
    MARK_AS_ADVANCED( FORCE OPENWALNUT_LIBRARIES )
    MARK_AS_ADVANCED( FORCE OPENWALNUT_FOUND )

120 121 122 123
    # provide some output
    IF( OPENWALNUT_INCLUDE_DIR )
      MESSAGE( STATUS "Found OpenWalnut include files in ${OPENWALNUT_INCLUDE_DIR}." )
    ENDIF()
124 125 126
    IF( OPENWALNUT_VERSIONHEADER_DIR )
      MESSAGE( STATUS "Found OpenWalnut version header in ${OPENWALNUT_VERSIONHEADER_DIR}." )
    ENDIF()
127 128 129 130 131
    IF( OPENWALNUT_LIBRARIES )
      MESSAGE( STATUS "Found OpenWalnut libs in ${OPENWALNUT_LIBRARIES}." )
    ENDIF()

    # really found?
132
    IF( OPENWALNUT_INCLUDE_DIR AND OPENWALNUT_LIBRARIES AND OPENWALNUT_VERSIONHEADER_DIR )
133 134 135
        SET( OPENWALNUT_FOUND TRUE )
        MESSAGE( STATUS "Found OpenWalnut." )
    ELSE()
136
        MESSAGE( FATAL_ERROR "Could not find OpenWalnut. You can use the environment variables OPENWALNUT_INCLUDEDIR and  OPENWALNUT_LIBDIR to point to your OpenWalnut installation." )
137 138 139 140
    ENDIF()

    # include
    INCLUDE_DIRECTORIES( ${OPENWALNUT_INCLUDE_DIR} )
141
    INCLUDE_DIRECTORIES( ${OPENWALNUT_VERSIONHEADER_DIR} )
142 143 144
    SET( OW_LIB_OPENWALNUT ${OPENWALNUT_LIBRARIES} )
ENDIF()

145
# ---------------------------------------------------------------------------------------------------------------------------------------------------
146
# 3: version header setup for the external module or OpenWalnut (depending on OW_EXTERNAL_MODULE)
147 148 149 150 151 152 153
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# Generate needed headers
# NOTE: add a line ADD_DEPENDENCIES( XYZ OW_generate_version_header ) to your target XYZ if you need the header!

# Call the file differently depending on internal or external build
IF( NOT ${OW_EXTERNAL_MODULE} )
154 155 156
    # if we build OW, we want the version header to be placed in core later on. We use the internal version header filename directly
    SET( OW_VERSION_HEADER_FILENAME ${OW_INTERNAL_VERSION_HEADER_FILENAME} )
    SET( OW_VERSION_HEADER_PREFIX "W" )
157 158 159 160
ELSE()
    # if this is for external use, the module might want to use its own version header
    # if we build OW, we want the version header to be placed in core later on
    SET( OW_VERSION_HEADER_FILENAME "WToolboxVersion.h" )
161
    SET( OW_VERSION_HEADER_PREFIX "WTOOLBOX" )
162 163 164
ENDIF()

# the complete header filename:
165
SET( OW_VERSION_HEADER_DIRECTORY ${PROJECT_BINARY_DIR}/${OW_VERSION_HEADER_DIRECTORY_RELATIVE} )
166 167 168 169 170
SET( OW_VERSION_HEADER ${OW_VERSION_HEADER_DIRECTORY}/${OW_VERSION_HEADER_FILENAME} )

# to allow all those targets to find the header:
INCLUDE_DIRECTORIES( ${OW_VERSION_HEADER_DIRECTORY} )
# Setup the target
171
SETUP_VERSION_HEADER( ${OW_VERSION_HEADER} ${OW_VERSION_HEADER_PREFIX} )
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

# Set the OW version string. This can be used by others for setting target versions during compilation.
GET_VERSION_STRING( OW_VERSION OW_LIB_VERSION )
IF( NOT ${OW_EXTERNAL_MODULE} )
    MESSAGE( STATUS "OW Version: \"${OW_VERSION}\"; OW Lib Version: \"${OW_LIB_VERSION}\"." )
ELSE()
    MESSAGE( STATUS "OW Toolbox Version: \"${OW_VERSION}\"; OW Toolbox Lib Version: \"${OW_LIB_VERSION}\"." )
ENDIF()

# We need a SOVERSION too. This somehow describes the API compatibility. We use the major number here.
SPLIT_VERSION_STRING( ${OW_LIB_VERSION} OW_VERSION_MAJOR OW_VERSION_MINOR OW_VERSION_PATCH )
SET( OW_SOVERSION ${OW_VERSION_MAJOR} )

MESSAGE( STATUS "----------------------------------------------------------------------" )

187 188 189 190 191 192 193 194 195 196
# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# This is mandatory. Defines the target paths for building all elements in OpenWalnut
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# mimic layout of install dir for build:
# these dirs are the same for all parts of OW
SET( OW_LIBRARY_DIR_RELATIVE "lib" )
SET( OW_ARCHIVE_DIR_RELATIVE "lib" )
197
SET( OW_MODULE_DIR_RELATIVE "lib/openwalnut" )
198 199 200 201 202 203 204 205 206

# Add Multiarch support:
IF( OW_PACKAGE_MULTIARCH )
    SET( OW_LIBRARY_DIR_RELATIVE "lib/${OW_PACKAGE_MULTIARCHLIBPATH}" )
    SET( OW_ARCHIVE_DIR_RELATIVE "lib/${OW_PACKAGE_MULTIARCHLIBPATH}" )
    SET( OW_MODULE_DIR_RELATIVE "lib/${OW_PACKAGE_MULTIARCHLIBPATH}/openwalnut" )
ENDIF()

SET( OW_LIBRARY_DIR ${PROJECT_BINARY_DIR}/${OW_LIBRARY_DIR_RELATIVE} )
207 208
SET( OW_ARCHIVE_DIR ${PROJECT_BINARY_DIR}/${OW_ARCHIVE_DIR_RELATIVE} )
SET( OW_MODULE_DIR ${PROJECT_BINARY_DIR}/${OW_MODULE_DIR_RELATIVE} )
209 210 211

SET( OW_RUNTIME_DIR_RELATIVE "bin" )
SET( OW_RUNTIME_DIR ${PROJECT_BINARY_DIR}/${OW_RUNTIME_DIR_RELATIVE} )
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
SET( OW_MAN_DIR_RELATIVE "share/man" )
SET( OW_MAN_DIR "${PROJECT_BINARY_DIR}/share/man" )

# One could also define this for every part of OW, but it does not make sense. It is "share" because it is shared among the different parts
SET( OW_SHARE_DIR_RELATIVE "share/openwalnut" )
SET( OW_SHARE_DIR ${PROJECT_BINARY_DIR}/${OW_SHARE_DIR_RELATIVE} )

# where to find the doxygen config
SET( OW_DOXYGEN_DIR ${PROJECT_SOURCE_DIR}/../doc/developer )

# set our paths for install targets
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${OW_RUNTIME_DIR} )
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${OW_LIBRARY_DIR} )
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${OW_ARCHIVE_DIR} )

# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# Basic Build Setup Helpers
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# This method configures the needed compiler flags and system specific options. You probably do not need to call this explciitly. It is done in
# BUILD_SYSTEM_SETUP
FUNCTION( BUILD_SYSTEM_COMPILER )
    # Unfortunately libstdc++'s header files don't work with mingw in ansi mode (basically libstdc++'s fault)
    IF( CMAKE_HOST_SYSTEM MATCHES "Windows" )
238
        SET( CMAKE_CXX_FLAGS "-frtti -pedantic -std=c++11 -Wall -Wno-long-long -Wextra " CACHE STRING "" FORCE )
239
    ELSE()
240
        SET( CMAKE_CXX_FLAGS "-frtti -pedantic -std=c++11 -Wall -Wno-long-long -Wextra " CACHE STRING "" FORCE )
241 242 243 244 245 246 247 248 249 250 251
    ENDIF()

    # Darwin's ld isn't GNU and doesn't like the following
    IF( NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" )
        ## The following allows us to prevent cyclic dependencies even on linux
        SET( CMAKE_SHARED_LINKER_FLAGS "-Wl,--no-undefined -Wl,--allow-shlib-undefined,--as-needed" CACHE STRING "" FORCE )
        SET( CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed" CACHE STRING "" FORCE )
    ENDIF()
    SET( CMAKE_CXX_FLAGS_RELEASE "-O3" CACHE STRING "" FORCE )
    SET( CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG -O0" CACHE STRING "" FORCE )
    SET( CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -DDEBUG -O2" CACHE STRING "" FORCE )
252 253 254 255 256 257 258 259 260 261

    # Allow injection of other flags
    # NOTE: do not set these variables somewhere in cmake. They are intended to be used when calling CMake from the command line.
    # Utilize this to append build flags from external systems (like dpkg-buildflags).
    SET( CMAKE_EXE_LINKER_FLAGS "${OW_LD_FLAGS_INJECT} ${CMAKE_EXE_LINKER_FLAGS}" CACHE STRING "" FORCE )
    SET( CMAKE_MODULE_LINKER_FLAGS "${OW_LD_FLAGS_INJECT} ${CMAKE_MODULE_LINKER_FLAGS}" CACHE STRING "" FORCE )
    SET( CMAKE_SHARED_LINKER_FLAGS "${OW_LD_FLAGS_INJECT} ${CMAKE_SHARED_LINKER_FLAGS}" CACHE STRING "" FORCE )
    SET( CMAKE_CXX_FLAGS "${OW_CXX_FLAGS_INJECT} ${CMAKE_CXX_FLAGS}" CACHE STRING "" FORCE )
    SET( CMAKE_C_FLAGS "${OW_C_FLAGS_INJECT} ${CMAKE_C_FLAGS}" CACHE STRING "" FORCE )

262 263 264 265 266 267
    # This can be useful for debugging
    # MESSAGE( STATUS "CMAKE_EXE_LINKER_FLAGS = ${CMAKE_EXE_LINKER_FLAGS}" )
    # MESSAGE( STATUS "CMAKE_MODULE_LINKER_FLAGS = ${CMAKE_MODULE_LINKER_FLAGS}" )
    # MESSAGE( STATUS "CMAKE_SHARED_LINKER_FLAGS = ${CMAKE_SHARED_LINKER_FLAGS}" )
    # MESSAGE( STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}" )
    # MESSAGE( STATUS "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}" )
268

269
    # Supress compilation warnings from includes residing in system paths, see #230 for further details.
270
    SET( CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem" CACHE STRING "" FORCE )
271

272 273
ENDFUNCTION( BUILD_SYSTEM_COMPILER )

274 275 276
# GCC 4.7 requires us to explicitly link against libstdc++ and libm. CMake offers a variable for this called "CMAKE_STANDARD_LIBRARIES".
# Unfortunately, this variable is empty. We fill it here and hopefully this is fixed in the near future.
LIST( APPEND CMAKE_STANDARD_LIBRARIES "stdc++" "m" )
277

278 279 280 281 282
# ---------------------------------------------------------------------------------------------------------------------------------------------------
# Compiler setup
# ---------------------------------------------------------------------------------------------------------------------------------------------------

BUILD_SYSTEM_COMPILER()
283
ADD_DEFINITIONS( ${OW_CPP_FLAGS_INJECT} )
284 285

# ---------------------------------------------------------------------------------------------------------------------------------------------------
286
# Platform specific options
287 288 289 290 291
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# sorry, linking not available properly on windows, Cygwin supports this but we do not want special rules for thousands of environments.
# ==> keep it clean
IF( NOT CMAKE_HOST_SYSTEM MATCHES "Windows" )
292
    OPTION( OW_LINK_SHADERS "If turned on, shaders will not be copied but will be linked. This is a nice option for developers." ON )
293 294 295 296 297 298 299 300 301
ENDIF()

# Provide several options to control some aspects of resource copy.
OPTION( OW_PACKAGE_BUILD "Enable this to get fine-grained control over several resources and files getting installed. This is very handy for package building." OFF )
IF( OW_PACKAGE_BUILD )
    SET( OW_PACKAGE_PACKAGER "cpack" CACHE STRING "Package builder. Set this to enable packager-specific options during install." )

    OPTION( OW_PACKAGE_NOCOPY_LICENSE "Disable to copy our licensing information. Enabling this can be useful for package maintainer since several packaging systems have their own licence mechanism (i.e. Debian)." OFF )
    OPTION( OW_PACKAGE_NOCOPY_COREFONTS "Enable this if you have liberation fonts installed on your system. They will be linked. If disabled, our fonts are copied." OFF )
302 303

    OPTION( OW_PACKAGE_MULTIARCH "Enable if the build should comply to the multiarch standard of the given OW_PACKAGE_PACKAGER. Right now, only Debian multiarch is formally supported." OFF )
304 305 306 307 308 309 310 311 312
ENDIF()

# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# REQUIRED third party libs
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------------------------------------------------------------------
313
# Boost, see http://www.boost.org/
314 315 316 317 318 319
#
# To see, which boost libs we currently use, you may run the following command # in the src directory on a linux box to make some investigations:
# grep -i include `find . -type f` | grep boost | awk '{print $2}' | sort | uniq

# Setup boost options
SET( Boost_USE_MULTITHREAD ON )
320
OPTION( BUILD_PYTHON_INTERPRETER OFF )
321 322

# find the boost packages
323 324 325 326 327
IF( BUILD_PYTHON_INTERPRETER )
    FIND_PACKAGE( Boost 1.46.0 REQUIRED program_options thread filesystem date_time system signals regex python )
ELSE()
    FIND_PACKAGE( Boost 1.46.0 REQUIRED program_options thread filesystem date_time system signals regex )
ENDIF() #BUILD_SCRIPTENGINE
328 329

# include the boost headers
330
INCLUDE_DIRECTORIES( SYSTEM ${Boost_INCLUDE_DIR} )
331 332 333 334 335 336 337 338

# avoid filesystem 2 stuff
ADD_DEFINITIONS( "-DBOOST_FILESYSTEM_VERSION=3" )

# -----------------------------------------------------------------------------------------------------------------------------------------------
# OpenGL, at least 1.2
# See http://www.opengl.org

339 340 341 342 343 344 345
# Find OpenGL or OpenGL ES on Android
IF( ANDROID )
  # on Android, we rely on the fact the the GLES headers reside in the correct NDK search paths
  # -> so we do not add the include dir directly. We only set the variables needed to fake a found OpenGL:
  SET( OPENGL_FOUND ON )
  # link against GLES 2
  SET( OPENGL_LIBRARIES "GLESv2" )
346
  SET( OPENGL_gl_LIBRARY "GLESv2" )
347 348 349
ELSE()
  FIND_PACKAGE( OpenGL REQUIRED )
  # include the OpenGL header paths
350
  INCLUDE_DIRECTORIES( SYSTEM ${OPENGL_INCLUDE_DIR} )
351
ENDIF()
352 353 354 355 356 357 358

# -----------------------------------------------------------------------------------------------------------------------------------------------
# OpenSceneGraph, at least 2.8.0
# See http://www.openscenegraph.org

# find the needed packages
SET( MIN_OSG_VERSION 2.8.0 )
359
FIND_PACKAGE( OpenSceneGraph ${MIN_OSG_VERSION} REQUIRED osgWidget osgViewer osgText osgSim osgGA osgDB osgUtil )
360
IF( OPENSCENEGRAPH_FOUND )
361
    INCLUDE_DIRECTORIES( SYSTEM ${OPENSCENEGRAPH_INCLUDE_DIRS} )
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383

    # is the OSG linked statically? If yes, we need to take care that all the osgdb plugins are linked too.
    STRING( REGEX MATCH "osgDB\\.a" OPENSCENEGRAPH_STATIC "${OPENSCENEGRAPH_LIBRARIES}" )
    IF( OPENSCENEGRAPH_STATIC )
      MESSAGE( STATUS "Found static OpenSceneGraph! Adding all osgDB plugins." )
      ADD_DEFINITIONS( -DOSG_LIBRARY_STATIC )

      # we need to find the path. Unfortunately, the OSG find scripts do not provide these info
      LIST( GET OPENSCENEGRAPH_LIBRARIES 0, firstElement )
      GET_FILENAME_COMPONENT( firstElementPath ${firstElement} PATH )

      # hopefully all static osgdb plugins reside in this directory
      FILE( GLOB plugInLibs "${firstElementPath}/*osgdb_*.a" )
      LIST( SORT plugInLibs )
      SET( OPENSCENEGRAPH_OSGDB_LIBS "" )
      FOREACH( plugIn ${plugInLibs} )
        LIST( APPEND OPENSCENEGRAPH_OSGDB_LIBS ${plugIn} )
      ENDFOREACH()

      # The osgDB plugins need to be linked BEFORE osg and osgDB
      LIST( INSERT OPENSCENEGRAPH_LIBRARIES 0 ${OPENSCENEGRAPH_OSGDB_LIBS} )
    ENDIF()
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
ENDIF()

# NOTE: sorry but this is needed since those vars spam the ccmake. The user should find the important options fast!

# Remove all of them
MARK_AS_ADVANCED( FORCE OSG_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OSG_LIBRARY )
MARK_AS_ADVANCED( FORCE OSG_LIBRARY_DEBUG )
MARK_AS_ADVANCED( FORCE OSGDB_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OSGDB_LIBRARY )
MARK_AS_ADVANCED( FORCE OSGDB_LIBRARY_DEBUG )
MARK_AS_ADVANCED( FORCE OSGGA_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OSGGA_LIBRARY )
MARK_AS_ADVANCED( FORCE OSGGA_LIBRARY_DEBUG )
MARK_AS_ADVANCED( FORCE OSGSIM_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OSGSIM_LIBRARY )
MARK_AS_ADVANCED( FORCE OSGSIM_LIBRARY_DEBUG )
MARK_AS_ADVANCED( FORCE OSGUTIL_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OSGUTIL_LIBRARY )
MARK_AS_ADVANCED( FORCE OSGUTIL_LIBRARY_DEBUG )
MARK_AS_ADVANCED( FORCE OSGTEXT_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OSGTEXT_LIBRARY )
MARK_AS_ADVANCED( FORCE OSGTEXT_LIBRARY_DEBUG )
MARK_AS_ADVANCED( FORCE OSGWIDGET_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OSGWIDGET_LIBRARY )
MARK_AS_ADVANCED( FORCE OSGWIDGET_LIBRARY_DEBUG )
MARK_AS_ADVANCED( FORCE OSGVIEWER_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OSGVIEWER_LIBRARY )
MARK_AS_ADVANCED( FORCE OSGVIEWER_LIBRARY_DEBUG )

MARK_AS_ADVANCED( FORCE OPENTHREADS_INCLUDE_DIR )
MARK_AS_ADVANCED( FORCE OPENTHREADS_LIBRARY )
MARK_AS_ADVANCED( FORCE OPENTHREADS_LIBRARY_DEBUG )

# -----------------------------------------------------------------------------------------------------------------------------------------------
# Eigen3, at least 3.0.0
# See http://eigen.tuxfamily.org

422
FIND_PACKAGE( Eigen3 REQUIRED )
423
IF( EIGEN3_FOUND )
424
    INCLUDE_DIRECTORIES( SYSTEM ${EIGEN3_INCLUDE_DIR} )
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445

    # NOTE: this is included in ext. But we need to set several definitions to make this work on 32 Bit machines due to alignment problems
    SET( EIGEN3_DEFINES -DEIGEN_DONT_VECTORIZE -DEIGEN_DONT_ALIGN -DEIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT )
    ADD_DEFINITIONS( ${EIGEN3_DEFINES} )
ENDIF()

# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# Unit Testing
#
#  - We use cxxtest. See http://cxxtest.tigris.org
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# Try to find it
FIND_PACKAGE( CxxTest QUIET )

# If it is found, and OW_USE_TESTS is on, build the tests and activate CMake's test mechanisms
IF( CXXTEST_FOUND )
  # To enable testing
  OPTION( OW_USE_TESTS "This enables compilation of tests" ON )
446 447
  INCLUDE_DIRECTORIES( SYSTEM ${CXXTEST_INCLUDE_DIRS} )
  INCLUDE_DIRECTORIES( SYSTEM ${CXXTEST_INCLUDE_DIR} ) # NOTE: old FindCXXTest versions used this name
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
  IF( OW_USE_TESTS )
    SET( OW_COMPILE_TESTS ON ) #We need this variable because this is tested more often.
    # Package settings:
    SET( CXXTEST_USE_PYTHON 1 )
    # Activate CTest and "test" target
    ENABLE_TESTING()

    # we want a more verbose testing too.
    ADD_CUSTOM_TARGET( vtest
                       COMMAND $(MAKE) test ARGS="-V"
                       COMMENT "Runs the test in verboseness to see what actually went wrong"
                     )
  ELSE()
    SET( OW_COMPILE_TESTS OFF )
  ENDIF()
ELSE()
  SET( OW_COMPILE_TESTS OFF )
ENDIF()

# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# Documentation
#  - Call doxygen here
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

IF( EXISTS ${OW_DOXYGEN_DIR}/doxygenConfig )
    #let doxygen do the work
    ADD_CUSTOM_TARGET( doc
                       COMMAND doxygen ${OW_DOXYGEN_DIR}/doxygenConfig
                       WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/..
                       COMMENT "Build doxygen documentation"
                       VERBATIM
                     )
482
ENDIF()
483

484 485 486
# On Windows, we want the common doc (README, AUTHORS and COPYING) to be in the root install dir too:
IF( CMAKE_HOST_SYSTEM MATCHES "Windows" )
    SETUP_COMMON_DOC( "." "COMMON_DOC_ON_WINDOWS" )
487 488 489 490 491 492 493 494 495 496 497 498
ENDIF()

# ---------------------------------------------------------------------------------------------------------------------------------------------------
#
# Style
#  - We use brainlint for this
#
# ---------------------------------------------------------------------------------------------------------------------------------------------------

# SETUP_STYLECHECKER adds targets for each lib which then add theirself to this target
ADD_CUSTOM_TARGET( stylecheck )