|
| 1 | +project(4dface) |
| 2 | +cmake_minimum_required(VERSION 2.8.10) |
| 3 | +set(4dface_VERSION_MAJOR 0) |
| 4 | +set(4dface_VERSION_MINOR 1) |
| 5 | +set(4dface_VERSION_PATCH 0) |
| 6 | +set(4dface_VERSION ${4dface_VERSION_MAJOR}.${4dface_VERSION_MINOR}.${4dface_VERSION_PATCH}) |
| 7 | + |
| 8 | +# Check if a supported compiler is used and add c++14 flag: |
| 9 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 10 | + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9) |
| 11 | + message(FATAL_ERROR "Need at least gcc 4.9 to compile.") |
| 12 | + endif() |
| 13 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") |
| 14 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthread") |
| 15 | +elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") |
| 16 | + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19) |
| 17 | + message(FATAL_ERROR "Visual Studio 2015 or newer is required.") |
| 18 | + endif() |
| 19 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj") |
| 20 | +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 21 | + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.6) |
| 22 | + message(FATAL_ERROR "Clang below version 3.6 will most likely not work. Please upgrade your compiler.") |
| 23 | + endif() |
| 24 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") |
| 25 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pthreads") |
| 26 | +else() # no GNU, no MSVC, no Clang |
| 27 | + message(WARNING "You are using an unsupported compiler. Compilation has only been tested with MSVC, GCC and Clang.") |
| 28 | + include(CheckCXXCompilerFlag) |
| 29 | + check_cxx_compiler_flag(-std=c++14 HAS_CXX14_FLAG) |
| 30 | + if(HAS_CXX14_FLAG) |
| 31 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") |
| 32 | + else() |
| 33 | + message(FATAL_ERROR "Your compiler doesn't support the '-std=c++14' flag.") |
| 34 | + endif() |
| 35 | +endif() |
| 36 | + |
| 37 | +# Build a CPack driven installer package: |
| 38 | +include(InstallRequiredSystemLibraries) # Includes any runtime libraries that are needed by the project for the current platform |
| 39 | +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE") |
| 40 | +set(CPACK_PACKAGE_VERSION_MAJOR "${4dface_VERSION_MAJOR}") |
| 41 | +set(CPACK_PACKAGE_VERSION_MINOR "${4dface_VERSION_MINOR}") |
| 42 | +set(CPACK_PACKAGE_VERSION_PATCH "${4dface_VERSION_PATCH}") |
| 43 | +include(CPack) |
| 44 | + |
| 45 | +# Find dependencies: |
| 46 | +find_package(OpenCV 2.4.3 REQUIRED core imgproc highgui objdetect) # in 3.0: require videoio? Plus the thing Michael fixed for eos? |
| 47 | +message(STATUS "OpenCV include dir found at ${OpenCV_INCLUDE_DIRS}") |
| 48 | +message(STATUS "OpenCV library dir found at ${OpenCV_LIB_DIR}") |
| 49 | +set_target_properties(${OpenCV_LIBS} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE) |
| 50 | + |
| 51 | +# Find the directory to OpenCV's face detector: |
| 52 | +if(NOT OpenCV_haarcascades_DIR) |
| 53 | + # This will fail for system-packaged OpenCV |
| 54 | + list(GET OpenCV_INCLUDE_DIRS 0 OpenCV_first_include_dir) |
| 55 | + set(OpenCV_haarcascades_DIR "${OpenCV_first_include_dir}/../share/OpenCV/haarcascades") |
| 56 | +endif() |
| 57 | +if(NOT EXISTS "${OpenCV_haarcascades_DIR}/haarcascade_frontalface_alt2.xml") |
| 58 | + message(FATAL_ERROR "Could not find OpenCV's face detector haarcascade_frontalface_alt2.xml in ${OpenCV_haarcascades_DIR}. Please set OpenCV_haarcascades_DIR to the directory with that file.") |
| 59 | +endif() |
| 60 | + |
| 61 | +find_package(Boost 1.48.0 COMPONENTS system filesystem program_options REQUIRED) |
| 62 | +if(Boost_FOUND) |
| 63 | + message(STATUS "Boost found at ${Boost_INCLUDE_DIRS}") |
| 64 | +else(Boost_FOUND) |
| 65 | + message(FATAL_ERROR "Boost not found") |
| 66 | +endif() |
| 67 | + |
| 68 | +set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) |
| 69 | +find_package(Eigen3 REQUIRED) |
| 70 | +message(STATUS "Eigen3 found: ${EIGEN3_FOUND}") |
| 71 | +message(STATUS "Eigen3 include dir found at ${EIGEN3_INCLUDE_DIR}") |
| 72 | +message(STATUS "Eigen3 version: ${EIGEN3_VERSION}") |
| 73 | + |
| 74 | +# Paths to our own includes, inside the git submodules: |
| 75 | +set(eos_DIR "${CMAKE_SOURCE_DIR}/external/eos") # These are used later to gather the required data files |
| 76 | +set(superviseddescent_DIR "${CMAKE_SOURCE_DIR}/external/superviseddescent") |
| 77 | + |
| 78 | +set(eos_INCLUDE_DIR "${eos_DIR}/include") |
| 79 | +set(superviseddescent_INCLUDE_DIR "${superviseddescent_DIR}/include") |
| 80 | +set(cereal_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/external/eos/3rdparty/cereal-1.1.1/include") |
| 81 | +set(glm_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/external/eos/3rdparty/glm-0.9.7.0") |
| 82 | + |
| 83 | +# The new model is not in the repository, download it manually for now: |
| 84 | +if(NOT EXISTS "face_landmarks_model_rcr_68.bin") |
| 85 | + message(STATUS "Downloading face_landmarks_model_rcr_68.bin (84.6 MB)...") |
| 86 | + file(DOWNLOAD http://www.patrikhuber.ch/files/models/face_landmarks_model_rcr_68.bin ${CMAKE_BINARY_DIR}/face_landmarks_model_rcr_68.bin INACTIVITY_TIMEOUT 15 STATUS status SHOW_PROGRESS) |
| 87 | + list(GET status 0 DOWNLOAD_STATUS) # first element is status code, second is the error message |
| 88 | + list(GET status 1 DOWNLOAD_ERROR_MSG) |
| 89 | + if(NOT ${DOWNLOAD_STATUS} EQUAL 0) |
| 90 | + message(FATAL_ERROR "Error downloading the file: ${DOWNLOAD_STATUS}; ${DOWNLOAD_ERROR_MSG}. Please delete the file if it has been created and re-run cmake or download the file manually and put it into the root of the build directory.") |
| 91 | + else() |
| 92 | + message(STATUS "face_landmarks_model_rcr_68.bin successfully downloaded.") |
| 93 | + endif() |
| 94 | +endif() |
| 95 | + |
| 96 | +# Add header includes: |
| 97 | +include_directories(${Boost_INCLUDE_DIRS}) |
| 98 | +include_directories(${OpenCV_INCLUDE_DIRS}) |
| 99 | +include_directories(${EIGEN3_INCLUDE_DIR}) |
| 100 | +include_directories(${superviseddescent_INCLUDE_DIR}) |
| 101 | +include_directories(${eos_INCLUDE_DIR}) |
| 102 | +include_directories(${cereal_INCLUDE_DIR}) |
| 103 | +include_directories(${glm_INCLUDE_DIR}) |
| 104 | + |
| 105 | +add_executable(4dface apps/4dface.cpp apps/helpers.hpp) |
| 106 | +target_link_libraries(4dface ${OpenCV_LIBS} ${Boost_LIBRARIES}) |
| 107 | + |
| 108 | +# install targets: |
| 109 | +install(TARGETS 4dface DESTINATION bin) |
| 110 | +install(FILES ${eos_DIR}/share/sfm_shape_3448.bin DESTINATION share) |
| 111 | +install(FILES ${eos_DIR}/share/ibug2did.txt DESTINATION share) |
| 112 | +install(FILES ${eos_DIR}/share/model_contours.json DESTINATION share) |
| 113 | +install(FILES ${eos_DIR}/share/expression_blendshapes_3448.bin DESTINATION share) |
| 114 | +install(FILES ${CMAKE_BINARY_DIR}/face_landmarks_model_rcr_68.bin DESTINATION share) |
| 115 | +install(FILES ${OpenCV_haarcascades_DIR}/haarcascade_frontalface_alt2.xml DESTINATION share) |
0 commit comments