Newer
Older
cmake_minimum_required (VERSION 3.1.0)
include (CheckIncludeFile)
include (CheckIncludeFileCXX)
include (CheckFunctionExists)
include(CheckLanguage)
project (ftl.utu.fi)
include(GNUInstallDirs)
include(CTest)
enable_testing()
option(WITH_NVPIPE "Use NvPipe for compression if available" ON)
option(WITH_OPTFLOW "Use NVIDIA Optical Flow if available" OFF)
option(WITH_FIXSTARS "Use Fixstars libSGM if available" ON)
option(USE_CPPCHECK "Apply cppcheck during build" ON)
option(BUILD_VISION "Enable the vision component" ON)
option(BUILD_RECONSTRUCT "Enable the reconstruction component" ON)
option(BUILD_RENDERER "Enable the renderer component" ON)
option(BUILD_GUI "Enable the GUI" ON)
option(BUILD_CALIBRATION "Enable the calibration component" OFF)
option(BUILD_TOOLS "Compile developer and research tools" ON)
option(BUILD_TESTS "Compile all unit and integration tests" ON)
option(ENABLE_PROFILER "Enable builtin performance profiling" OFF)
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
include(Findglog)
find_package( OpenCV REQUIRED COMPONENTS core imgproc highgui cudaimgproc calib3d imgcodecs videoio aruco cudaarithm cudastereo cudaoptflow face tracking quality)
find_package( Threads REQUIRED )
find_package( URIParser REQUIRED )
find_package( MsgPack REQUIRED )
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
message(STATUS "Found ccache: ${CCACHE_PROGRAM}")
endif()
if (WITH_OPTFLOW)
# TODO check that cudaoptflow.hpp exists (OpenCV built with correct contrib modules)
set(HAVE_OPTFLOW true)
endif()
# Enable if the old snapshot is still needed
#find_package( LibArchive )
#if (LibArchive_FOUND)
# set(HAVE_LIBARCHIVE true)
#endif()

Sebastian Hahta
committed
if (WITH_OPENVR)
## OpenVR API path
find_library(OPENVR_LIBRARIES
NAMES
openvr_api
)
set(OPENVR_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../headers)
if (OPENVR_LIBRARIES)
message(STATUS "Found OpenVR: ${OPENVR_LIBRARIES}")
set(HAVE_OPENVR true)
endif()
if (WITH_FIXSTARS)
find_package( LibSGM )
if(${CMAKE_VERSION} VERSION_GREATER "3.12.0")
cmake_policy(SET CMP0074 NEW)
endif()
set(CMAKE_CXX_STANDARD 17) # For PCL/VTK https://github.com/PointCloudLibrary/pcl/issues/2686
# Readline library is not required on Windows
# May also entirely remove dependence on this... it should be optional at least.
if (NOT WIN32)
find_library( READLINE_LIBRARY NAMES readline libreadline )
if (NOT READLINE_LIBRARY)
message(FATAL "Readline library missing")
else()
message(STATUS "Found Readline: ${READLINE_LIBRARY}")
endif()
endif()
find_library( REALSENSE_LIBRARY NAMES realsense2 librealsense2 PATHS ${REALSENSE_DIR} PATH_SUFFIXES lib/x64)
if (REALSENSE_LIBRARY)
set(HAVE_REALSENSE TRUE)
add_library(realsense UNKNOWN IMPORTED)
#set_property(TARGET nanogui PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NANOGUI_EXTRA_INCS})
set_property(TARGET realsense PROPERTY IMPORTED_LOCATION ${REALSENSE_LIBRARY})
message(STATUS "Found Realsense SDK: ${REALSENSE_LIBRARY}")
if(WIN32)
# Find include
find_path(REALSENSE_INCLUDE_DIRS
NAMES librealsense2/rs.hpp
PATHS "C:/Program Files/Intel RealSense SDK 2.0" "C:/Program Files (x86)/Intel RealSense SDK 2.0" ${REALSENSE_DIR}
PATH_SUFFIXES include
)
set_property(TARGET realsense PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${REALSENSE_INCLUDE_DIRS})
endif()
else()
set(REALSENSE_LIBRARY "")
# Disable building extras we won't need (pure C++ project)
set(NANOGUI_BUILD_SHARED OFF CACHE BOOL " " FORCE)
set(NANOGUI_BUILD_EXAMPLE OFF CACHE BOOL " " FORCE)
set(NANOGUI_BUILD_PYTHON OFF CACHE BOOL " " FORCE)
set(NANOGUI_INSTALL OFF CACHE BOOL " " FORCE)
# Add the configurations from nanogui
add_subdirectory(ext/nanogui)
# For reliability of parallel build, make the NanoGUI targets dependencies
set_property(TARGET glfw glfw_objects nanogui PROPERTY FOLDER "dependencies")
find_library( NVPIPE_LIBRARY NAMES NvPipe libNvPipe PATHS ${NVPIPE_DIR} PATH_SUFFIXES lib)
if (NVPIPE_LIBRARY)
set(HAVE_NVPIPE TRUE)
add_library(nvpipe UNKNOWN IMPORTED)
#set_property(TARGET nanogui PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NANOGUI_EXTRA_INCS})
set_property(TARGET nvpipe PROPERTY IMPORTED_LOCATION ${NVPIPE_LIBRARY})
message(STATUS "Found NvPipe: ${NVPIPE_LIBRARY}")
if(WIN32)
# Find include
find_path(NVPIPE_INCLUDE_DIRS
NAMES NvPipe.h
PATHS "C:/Program Files/NvPipe" "C:/Program Files (x86)/NvPipe" ${NVPIPE_DIR}
PATH_SUFFIXES include
)
set_property(TARGET nvpipe PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NVPIPE_INCLUDE_DIRS})
endif()
else()
set(NVPIPE_LIBRARY "")
add_library(nvpipe INTERFACE)
endif()
# Portaudio v19 library
find_library( PORTAUDIO_LIBRARY NAMES portaudio PATHS ${PORTAUDIO_DIR} PATH_SUFFIXES lib)
if (PORTAUDIO_LIBRARY)
set(HAVE_PORTAUDIO TRUE)
add_library(portaudio UNKNOWN IMPORTED)
#set_property(TARGET nanogui PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${NANOGUI_EXTRA_INCS})
set_property(TARGET portaudio PROPERTY IMPORTED_LOCATION ${PORTAUDIO_LIBRARY})
message(STATUS "Found Portaudio: ${PORTAUDIO_LIBRARY}")
if(WIN32)
# Find include
find_path(PORTAUDIO_INCLUDE_DIRS
NAMES portaudio.h
PATHS "C:/Program Files/Portaudio" "C:/Program Files (x86)/Portaudio" ${PORTAUDIO_DIR}
PATH_SUFFIXES include
)
set_property(TARGET portaudio PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PORTAUDIO_INCLUDE_DIRS})
endif()
else()
set(PORTAUDIO_LIBRARY "")
add_library(portaudio INTERFACE)
message(WARNING "Portaudio not found - sound disabled")
endif()
find_program( NODE_NPM NAMES npm )
if (NODE_NPM)
message(STATUS "Found NPM: ${NODE_NPM}")
endif()
check_language(CUDA)
if (CUDA_TOOLKIT_ROOT_DIR)
enable_language(CUDA)
set(CMAKE_CUDA_FLAGS "")
set(CMAKE_CUDA_FLAGS_DEBUG "--gpu-architecture=compute_61 -g -DDEBUG -D_DEBUG")
set(CMAKE_CUDA_FLAGS_RELEASE "--gpu-architecture=compute_61")
include_directories(${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
# Some kind of fix for nvcc and -pthread problem on Linux
set_property(TARGET Threads::Threads
PROPERTY INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler -pthread>
"$<$<NOT:$<COMPILE_LANGUAGE:CUDA>>:-pthread>")
# Incase find_package failed, manually look for msgpack
check_include_file_cxx("msgpack.hpp" MSGPACK_FOUND)
if (NOT MSGPACK_FOUND)
message(ERROR "Msgpack is required")
endif()
if(WIN32)
# Find include
find_path(MSGPACK_INCLUDE_DIRS
NAMES msgpack.hpp
PATHS "C:/Program Files/msgpack" "C:/Program Files (x86)/msgpack"
PATH_SUFFIXES include
)
endif()
# TODO(nick) Create imported target.
include_directories(${MSGPACK_INCLUDE_DIRS})
# Only need libuuid on Linux, Windows has its own
check_include_file("uuid/uuid.h" UUID_FOUND)
if (NOT UUID_FOUND)
message(ERROR "UUID library is required")
endif()
find_library(UUID_LIBRARIES NAMES uuid libuuid)
# For screen capture
if (WIN32)
message(STATUS "Screen capture not supported")
else()
find_package(X11)
if (X11_FOUND)
if (X11_XShm_FOUND)
message(STATUS "Using X11 for screen capture")
set(HAVE_X11 TRUE)
else()
message(STATUS "No X11 Shared memory extension")
endif()
else()
message(STATUS "No X11, screen capture disabled")
endif()
endif()
# For ftl2mkv
check_include_file("libavformat/avformat.h" HAVE_AVFORMAT)

Nicolas Pope
committed
# Check for optional opencv components
set(CMAKE_REQUIRED_INCLUDES ${OpenCV_INCLUDE_DIRS})
check_include_file_cxx("opencv2/viz.hpp" HAVE_VIZ)
check_include_file_cxx("opencv2/cudastereo.hpp" HAVE_OPENCVCUDA)
if (USE_CPPCHECK)
find_program(CPPCHECK_FOUND cppcheck)
if (CPPCHECK_FOUND)
message(STATUS "Found cppcheck: will perform source checks")
set(CMAKE_CXX_CPPCHECK "cppcheck" "-D__align__(A)" "-DCUDARTAPI" "--enable=warning,performance,style" "--inline-suppr" "--std=c++14" "--suppress=*:*catch.hpp" "--suppress=*:*elas*" "--suppress=*:*nanogui*" "--suppress=*:*json.hpp" "--quiet")
endif()
# include_directories(${PROJECT_SOURCE_DIR}/common/cpp/include)
if (WIN32) # TODO(nick) Should do based upon compiler (VS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++17")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /DFTL_DEBUG /Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -msse3 -Werror=return-type")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG -pg -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -mfpmath=sse")
SET(CMAKE_USE_RELATIVE_PATHS ON)
add_subdirectory(components/net)
add_subdirectory(components/rgbd-sources)
add_subdirectory(components/operators)
add_subdirectory(applications/calibration)
#add_subdirectory(applications/groupview)
#add_subdirectory(applications/player)
#add_subdirectory(applications/recorder)
#add_subdirectory(applications/merger)
if (HAVE_AVFORMAT)
add_subdirectory(applications/ftl2mkv)
endif()
set(HAVE_RENDER)
endif()
if (BUILD_VISION)
if (BUILD_CALIBRATION)
find_package( cvsba REQUIRED )
add_subdirectory(applications/calibration-multi)
endif()
if (HAVE_NANOGUI)
add_subdirectory(applications/gui)
endif()
### Generate Build Configuration Files =========================================
configure_file(${CMAKE_SOURCE_DIR}/components/common/cpp/include/ftl/config.h.in
${CMAKE_SOURCE_DIR}/components/common/cpp/include/ftl/config.h
configure_file(${CMAKE_SOURCE_DIR}/components/common/cpp/src/config.cpp.in
${CMAKE_SOURCE_DIR}/components/common/cpp/src/config.cpp
# For issue #17
# https://gitlab.kitware.com/cmake/cmake/issues/16915#note_456382
if ( TARGET Qt5::Core )
get_property( core_options TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_OPTIONS )
string( REPLACE "-fPIC" "" new_core_options "${core_options}" )
set_property( TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_OPTIONS ${new_core_options} )
set_property( TARGET Qt5::Core PROPERTY INTERFACE_POSITION_INDEPENDENT_CODE "ON" )
set( CMAKE_CXX_COMPILE_OPTIONS_PIE "-fPIC" )
endif()
if (WIN32) # TODO(nick) Should do based upon compiler (VS)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${VS_STARTUP_PROJECT})
set_property(TARGET ftl-vision PROPERTY VS_DEBUGGER_WORKING_DIRECTORY ${VS_DEBUG_WORKING_DIRECTORY})
endif()