Skip to content

Instantly share code, notes, and snippets.

@cfoch
Created December 25, 2018 19:12
Show Gist options
  • Save cfoch/61575be592ed65dfa1941c58867e6429 to your computer and use it in GitHub Desktop.
Save cfoch/61575be592ed65dfa1941c58867e6429 to your computer and use it in GitHub Desktop.
# The examples need a few additional dependencies (e.g. boost filesystem, program_options, and OpenCV highgui):
include_directories("/home/cfoch/dev/env/eos-prefix/include")
include_directories("/home/cfoch/dev/env/eos-prefix/3rdparty/toml11")
include_directories("/home/cfoch/dev/env/eos-prefix/3rdparty/eigen")
include_directories("/home/cfoch/dev/env/eos-prefix/3rdparty/eigen3-nnls/src")
include_directories("/home/cfoch/dev/env/eos-prefix/3rdparty/glm")
include_directories("/home/cfoch/dev/env/eos-prefix/3rdparty/cereal/include")
include_directories("/home/cfoch/dev/env/eos-prefix/3rdparty/nanoflann/include")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_BUILD_TYPE Release)
# Check installed version in order to include the correct OpenCV libraries:
# First call find_package without a version to find any OpenCV. OpenCV_VERSION_MAJOR is then defined.
find_package(OpenCV REQUIRED core)
if("${OpenCV_VERSION_MAJOR}$" EQUAL 2)
message(STATUS "OpenCV 2.x detected")
find_package(OpenCV 2.4.3 REQUIRED)
elseif("${OpenCV_VERSION_MAJOR}$" EQUAL 3)
message(STATUS "OpenCV 3.x detected - including imgcodecs for compatibility")
find_package(OpenCV 3 REQUIRED)
endif()
# add_subdirectory(/usr/include/dlib /usr/lib64)
find_package(dlib REQUIRED)
# include_directories(${dlib_INCLUDE_DIRS})
# link_directories(${DLIB_LIBRARY_DIRS})
# include_directories(${dlib_INCLUDE_DIRS})
# link_directories(${DLIB_LIBRARY_DIRS})
# This allows us to compile in RelWithDebInfo. It'll use the Release-version of OpenCV:
set_target_properties(${OpenCV_LIBS} PROPERTIES MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE)
if(MSVC)
# The standard find_package for boost on Win finds the dynamic libs, so for dynamic linking to boost we need to #define:
add_definitions(-DBOOST_ALL_NO_LIB) # Don't use the automatic library linking by boost with VS (#pragma ...). Instead, we specify everything here in cmake.
add_definitions(-DBOOST_ALL_DYN_LINK) # Link against the dynamic boost lib - needs to match with the version that find_package finds.
add_definitions(-D_HAS_AUTO_PTR_ETC) # Boost 1.65.1 still does not work with VS C++17 mode, this is the workaround
endif()
find_package(Boost 1.50.0 COMPONENTS system filesystem program_options REQUIRED)
message(STATUS "Boost found at ${Boost_INCLUDE_DIRS}")
add_executable(dlib-example dlib-example.cpp)
# target_link_libraries(dlib-example "$<$<CXX_COMPILER_ID:GNU>:-pthread>$<$<CXX_COMPILER_ID:Clang>:-pthreads>")
target_link_libraries(dlib-example ${OpenCV_LIBS})
# target_include_directories(dlib-example PUBLIC ${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
target_link_libraries(dlib-example dlib::dlib)
add_executable(fit-model fit-model.cpp)
target_link_libraries(fit-model ${OpenCV_LIBS} ${Boost_LIBRARIES})
target_link_libraries(fit-model "$<$<CXX_COMPILER_ID:GNU>:-pthread>$<$<CXX_COMPILER_ID:Clang>:-pthreads>")
target_link_libraries(fit-model dlib::dlib)
#set_source_files_properties(foo.cpp PROPERTIES COMPILE_FLAGS -std=c++14)
target_include_directories(fit-model PUBLIC ${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment