Link shared library with cmake - c++

I have the following project structure:
libs is the directory where the standalone library I'm writing lives.
src is where I consume the library
My three CMakeLists.txt files are the following:
The main entry point:
cmake_minimum_required(VERSION 3.4)
add_subdirectory(src)
add_subdirectory(libs)
The libs/CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(Fibula)
message(STATUS "Fibula: v2.0.0")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -framework OpenGl -lsfml-graphics -lsfml-audio -lsfml-window -lsfml-system -lGLEW -std=c++14 -Wall -pedantic")
set(FIBULA_INCLUDE_DIR "include")
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_LIST_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_LIST_DIR})
include_directories(${FIBULA_INCLUDE_DIR})
# This stuff needed to put every include file into needed directory when we do make install
file(GLOB BRIDGE ${FIBULA_INCLUDE_DIR}/Bridge/*.hpp)
file(GLOB CORE ${FIBULA_INCLUDE_DIR}/Core/*.hpp)
file(GLOB EVENTS ${FIBULA_INCLUDE_DIR}/Events/*.hpp)
file(GLOB GRAPHICS ${FIBULA_INCLUDE_DIR}/Graphics/*.hpp)
file(GLOB GRAPHICS_TILEMAP ${FIBULA_INCLUDE_DIR}/Graphics/TileMap/*.hpp)
file(GLOB_RECURSE SOURCE_LIST src/*.cpp)
set(HEADER_LIST
${BRIDGE}
${CORE}
${EVENTS}
${GRAPHICS}
${GRAPHICS_TILEMAP}
)
# GLM
find_package(GLM REQUIRED)
if (NOT GLM_FOUND)
message(SEND_ERROR "Failed to find GLM")
return()
else ()
include_directories(${GLM_INCLUDE_DIRS})
endif ()
# GLEW
find_package(GLEW REQUIRED)
if (NOT GLEW_FOUND)
message(SEND_ERROR "Failed to find GLEW")
return()
else ()
include_directories(${GLEW_INCLUDE_DIRS})
endif ()
# SFML
find_package(SFML 2.2 REQUIRED)
if (NOT SFML_FOUND)
message(SEND_ERROR "Failed to find SFML 2")
return()
else ()
include_directories(${SFML_INCLUDE_DIRS})
endif ()
add_library(Fibula SHARED ${SOURCE_LIST} ${HEADER_LIST})
target_link_libraries(Fibula
${GLM_LIBRARIES}
${GLEW_LIBRARIES}
${SFML_LIBARIES}
)
# When we do 'make install' it will put .so file into lib directory and include files into include directory
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${PROJECT_NAME})
install(FILES ${BRIDGE} DESTINATION include/${PROJECT_NAME}/Bridge/)
install(FILES ${CORE} DESTINATION include/${PROJECT_NAME}/Core/)
install(FILES ${EVENTS} DESTINATION include/${PROJECT_NAME}/Events/)
install(FILES ${GRAPHICS} DESTINATION include/${PROJECT_NAME}/Graphics/)
install(FILES ${GRAPHICS_TILEMAP} DESTINATION include/${PROJECT_NAME}/Graphics/TileMap/)
add_custom_target(install_${PROJECT_NAME}
make install
DEPENDS ${PROJECT_NAME}
COMMENT "Installing ${PROJECT_NAME}")
And the src/CMakeLists.txt:
cmake_minimum_required(VERSION 3.4)
project(demo-game)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake_modules")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall")
find_library(FIBULA_LIBRARY
NAMES Fibula
HINTS "${CMAKE_CURRENT_LIST_DIR}/../libs/include/")
include_directories(
"${CMAKE_CURRENT_LIST_DIR}/../libs/include"
Core
)
file(GLOB SOURCE_LIST
*.cpp
../../src/Core/*.cpp
)
add_executable(demo-game ${SOURCE_LIST})
target_link_libraries(demo-game Fibula)
add_custom_target(valgrind)
When I try to include my library as:
#include <Fibula/Core/Kernel.hpp>
I get the following error:

Related

CMake undefined symbol: pthread_create compiling dynamic library

My project was working fine before but I changed it to be compiled as a dynamic library in order to have it perform self-update, like so:
Launcher -> Executable
Server -> Library (Core project, multi-threaded with std::thread)
Updater -> Library
Now, on Linux (Debian Bullseye), I get a runtime error undefined symbol: pthread_create when the launcher tries to dlopen the Server library. Windows equivalent works fine.
I've tried splitting my big CMakeLists in several subprojects, thinking it could be a CMake bug, but that was of course not the problem.
I've included below a simplified version of the parent CMakeLists and the subproject CMakeLists for the Server and the launcher.
Parent:
################################
# Project settings
################################
cmake_minimum_required (VERSION 3.8)
set(TARGET_NAME "Server")
set(SERVER_VERSION "1.0.0")
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
project(${TARGET_NAME} VERSION ${SERVER_VERSION} DESCRIPTION "My Server")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
################################
# Sources
################################
configure_file(
${CMAKE_SOURCE_DIR}/src/Resource.h
${CMAKE_CURRENT_BINARY_DIR}/src/Resource.h
COPYONLY)
configure_file(
${CMAKE_SOURCE_DIR}/src/Resource.rc.in
${CMAKE_CURRENT_BINARY_DIR}/src/Resource.rc
#ONLY)
set_source_files_properties("../Server.ico" PROPERTIES LANGUAGE RC)
include_directories("includes")
################################
# Subprojects
################################
add_subdirectory("src/Server")
add_subdirectory("src/Launcher")
add_subdirectory("src/Updater")
Server lib Subproject:
################################
# Project settings
################################
cmake_minimum_required (VERSION 3.8)
set(TARGET_NAME "Server-Core")
if (LIB)
set(EXE_NAME "ServerCore")
else ()
set(EXE_NAME "Server")
endif ()
project(${TARGET_NAME} VERSION ${SERVER_VERSION} DESCRIPTION "My Server")
################################
# Sources
################################
configure_file(
Server.hh.in
Server.hh
#ONLY)
include_directories(. "${CMAKE_BINARY_DIR}/src/Server/")
file(GLOB_RECURSE SRC "*.hh" "*.hpp" "*.cpp" "${CMAKE_BINARY_DIR}/src/*.hh")
if (LIB)
add_library(${TARGET_NAME} SHARED ${SRC})
elseif (WIN32)
add_executable(${TARGET_NAME} ${SRC} ${CMAKE_BINARY_DIR}/src/Resource.rc)
else ()
add_executable(${TARGET_NAME} ${SRC})
endif ()
################################
# Libs
################################
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${TARGET_NAME} Threads::Threads)
if(WIN32)
target_link_libraries(${TARGET_NAME} wsock32 ws2_32)
target_link_libraries(${TARGET_NAME} Crypt32)
target_link_libraries(${TARGET_NAME} ${CMAKE_SOURCE_DIR}/libs/libssl.lib)
target_link_libraries(${TARGET_NAME} ${CMAKE_SOURCE_DIR}/libs/libcrypto.lib)
elseif(UNIX)
target_link_libraries(${TARGET_NAME} -static-libgcc -static-libstdc++)
target_link_libraries(${TARGET_NAME} ${CMAKE_SOURCE_DIR}/libs/libssl.a)
target_link_libraries(${TARGET_NAME} ${CMAKE_SOURCE_DIR}/libs/libcrypto.a)
endif()
################################
# Compiler settings
################################
set_target_properties(${TARGET_NAME} PROPERTIES VERSION ${SERVER_VERSION})
set_target_properties(${TARGET_NAME} PROPERTIES PREFIX "")
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD 20)
set_property(TARGET ${TARGET_NAME} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${TARGET_NAME} PROPERTY OUTPUT_NAME ${EXE_NAME})
if(MSVC)
target_compile_options(${TARGET_NAME} PUBLIC /std:c++latest)
target_compile_options(${TARGET_NAME} PUBLIC /Zc:__cplusplus)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
endif()
Launcher subproject:
################################
# Project settings
################################
cmake_minimum_required (VERSION 3.8)
set(LAUNCHER_TARGET "Launcher")
set(LAUNCHER_EXE_NAME "Server")
set(LAUNCHER_VERSION "1.0.0")
project(${LAUNCHER_TARGET} VERSION ${LAUNCHER_VERSION} DESCRIPTION "My Server")
################################
# Sources
################################
if (LIB)
file(GLOB_RECURSE SRC "*.hh" "*.hpp" "*.cpp"
"../Server/Utils/DynamicLibrary/DynamicLibraryWindows.cpp" "../Server/Utils/DynamicLibrary/DynamicLibraryLinux.cpp"
"../Server/Utils/DynamicLibrary/IDynamicLibrary.cpp")
if (WIN32)
add_executable(${LAUNCHER_TARGET} ${SRC} ${CMAKE_BINARY_DIR}/src/Resource.rc)
else ()
add_executable(${LAUNCHER_TARGET} ${SRC})
endif ()
endif ()
################################
# Libs
################################
if (UNIX)
if (LIB)
target_link_libraries(${LAUNCHER_TARGET} ${CMAKE_DL_LIBS})
endif ()
endif ()
################################
# Compiler settings
################################
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${LAUNCHER_TARGET} Threads::Threads)
if (LIB)
set_target_properties(${LAUNCHER_TARGET} PROPERTIES VERSION ${LAUNCHER_VERSION})
set_property(TARGET ${LAUNCHER_TARGET} PROPERTY CXX_STANDARD 20)
set_property(TARGET ${LAUNCHER_TARGET} PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET ${LAUNCHER_TARGET} PROPERTY OUTPUT_NAME ${LAUNCHER_EXE_NAME})
endif ()
I'm using CMake 3.16.3 and gcc 9.3.0
What did I do wrong? I'm still not extremely comfortable with CMake
I have been able to fix the problem by adding
target_link_libraries(${TARGET} pthread)
after
target_link_libraries(${TARGET} Threads::Threads)
for the Launcher, when compiling for Linux.
And I need to include <thread> in the launcher and have a piece of code such as
std::thread t([](){});
t.join();
This is extremely weird

How to set CMakeLists.txt to properly import AntTweakBar library?

I am modifying a C++ application to demonstrate ambient occlusion based on OpenGL, GLFW and GLAD libraries. I would like to use AntTweakBar library as well, but I don't know how to modify cMakeLists.txt to properly import it. I have tried a lot of different versions to import this library, which is in the root of the project anyway.
Below you can see my cmakelists.txt.
cmake_minimum_required(VERSION 2.8)
cmake_policy(VERSION 2.8)
project(LearnOpenGL)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
link_directories(${CMAKE_SOURCE_DIR}/lib)
list(APPEND CMAKE_CXX_FLAGS "-std=c++11")
# find the required packages
find_package(GLM REQUIRED)
message(STATUS "GLM included at ${GLM_INCLUDE_DIR}")
find_package(GLFW3 REQUIRED)
message(STATUS "Found GLFW3 in ${GLFW3_INCLUDE_DIR}")
find_package(ASSIMP REQUIRED)
message(STATUS "Found ASSIMP in ${ASSIMP_INCLUDE_DIR}")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
find_package(OpenGL REQUIRED)
add_definitions(${OPENGL_DEFINITIONS})
find_package(X11 REQUIRED)
# note that the order is important for setting the libs
# use pkg-config --libs $(pkg-config --print-requires --print-requires-private glfw3) in a terminal to confirm
set(LIBS ${GLFW3_LIBRARY} X11 Xrandr Xinerama Xi Xxf86vm Xcursor GL dl pthread ${ASSIMP_LIBRARY})
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl")
configure_file(configuration/root_directory.h.in configuration/root_directory.h)
include_directories(${CMAKE_BINARY_DIR}/configuration)
# first create relevant static libraries requried for other projects
add_library(GLAD "src/glad.c")
set(LIBS ${LIBS} GLAD)
FIND_PATH(ANT_TWEAK_BAR_INCLUDE_PATH AntTweakBar.h
PATHS
${CMAKE_BINARY_DIR}/AntTweakBar/include)
FIND_LIBRARY( ANT_TWEAK_BAR_LIBRARY AntTweakBar
PATHS
${CMAKE_BINARY_DIR}/AntTweakBar/lib
)
#reate a project file
file(GLOB SOURCE
"src/*.h"
"src/*.cpp"
"src/*.vs"
"src/*.fs"
"src/*.gs"
)
set(NAME "SSAO")
add_executable(${NAME} ${SOURCE})
target_link_libraries(${NAME} ${LIBS} ${ANT_TWEAK_BAR_LIBRARY})
set_target_properties(${NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin/")
include_directories(${CMAKE_SOURCE_DIR}/includes)
include_directories(${ANT_TWEAK_BAR_INCLUDE_PATH})
This is an example how i import static googletest libraries 'libgtest.a' and 'libgmock.a' to a project using cmake as build configuration generator.
For shared libraries you need to replace STATIC by SHARED in add_library.
cmake_minimum_required(VERSION 2.8)
project(gtest_sample1)
include_directories(../googletest/include)
include_directories(../googlemock/include)
add_library(gtest STATIC IMPORTED)
set_property(TARGET gtest PROPERTY IMPORTED_LOCATION /home/mschmid/projects/googletest-master/gtest/libgtest.a)
add_library(gmock STATIC IMPORTED)
set_property(TARGET gmock PROPERTY IMPORTED_LOCATION /home/mschmid/projects/googletest-master/gmock/libgmock.a)
add_executable(gtest_sample1 main.cpp)
target_link_libraries(gtest_sample1 gtest gmock pthread)

Cmake shared library - include doesn't exist

I am trying to write a cmake file to create a shared library and use it in the executable file in my project. In the main I include heades as <pattern_follower/header_file_name.h>, but when I run make install it says pattern_follower/header_file_name.h does not exist.
cmake_minimum_required(VERSION 2.8)
project(pattern_follower)
add_definitions(-std=c++14)
file(GLOB SOURCES src/*)
file(GLOB HEADERS include/*)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS_RELEASE} -Wall -O4 -march=native -Wfatal-errors")
find_package(OpenCV REQUIRED)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(${PROJECT_NAME} SHARED ${SOURCES})
target_link_libraries( ${PROJECT_NAME} ${OpenCV_LIBS})
add_executable(${PROJECT_NAME}-main main.cpp)
set_target_properties(${PROJECT_NAME}-main PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
target_link_libraries( ${PROJECT_NAME}-main ${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME} DESTINATION lib)
install(TARGETS ${PROJECT_NAME}-main DESTINATION bin)
install(DIRECTORY include DESTINATION include/${PROJECT_NAME})

include_directories and CMAKE_INSTALL_FULL_INCLUDEDIR

I am building two C++ libraries(2 CMake projects). library2 depends on library1. I am installing my first library header files at ${CMAKE_INSTALL_INCLUDEDIR}/mylibraries. Now to include library1 header files in my library2, I am doing include_directories(${CMAKE_INSTALL_FULL_INCLUDEDIR}/mylibraries) in the library2's CMakeLists.txt.
But the make is failing with no such file or directory error.
library1.h no such file or directory from library2.cpp
library1's CmakeLists.txt
cmake_minimum_required (VERSION 3.5)
include(GNUInstallDirs)
project (logger)
set (VERSION_MAJOR 1)
set (VERSION_MINOR 0)
set (Umbrella "ferryfair")
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
configure_file(
"${PROJECT_SOURCE_DIR}/pkgconfig.pc.in"
"${PROJECT_BINARY_DIR}/pkgconfig.pc"
)
set (GCC_COVERAGE_COMPILE_FLAGS "-std=c++14")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
file(GLOB HEADERS *.h)
file(GLOB SOURCES *.cpp)
include_directories(${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_INSTALL_FULL_INCLUDEDIR}/${Umbrella})
add_library(${PROJECT_NAME}Static STATIC ${SOURCES} ${HEADERS})
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
set_target_properties(${PROJECT_NAME}Static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
set_target_properties(${PROJECT_NAME}
PROPERTIES
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}
SOVERSION ${VERSION_MAJOR}
)
set_target_properties(${PROJECT_NAME}Static
PROPERTIES
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}
SOVERSION ${VERSION_MAJOR}
)
target_link_libraries(${PROJECT_NAME}Static ferrybase)
target_link_libraries(${PROJECT_NAME} ferrybase)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS ${PROJECT_NAME}Static DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${Umbrella})
install(FILES "${PROJECT_BINARY_DIR}/config.h"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${Umbrella}
RENAME ${PROJECT_NAME}Config.h)
install(FILES "${PROJECT_BINARY_DIR}/pkgconfig.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
RENAME "${PROJECT_NAME}.pc")
install(FILES "${PROJECT_BINARY_DIR}/pkgconfig.pc"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig
RENAME "${PROJECT_NAME}.pc")
library2's CMakeLists.txt
cmake_minimum_required (VERSION 3.5)
include(GNUInstallDirs)
project (FFJSON)
IF (DEFINED _DEBUG)
ADD_DEFINITIONS(-D_DEBUG=${_DEBUG})
ENDIF()
set (VERSION_MAJOR 1)
set (VERSION_MINOR 0)
set (Umbrella "ferryfair")
IF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Mac OS X specific code
SET(macOS ON)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# configure a header file to pass some of the CMake settings
# to the source code
configure_file (
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
configure_file(
"${PROJECT_SOURCE_DIR}/pkgconfig.pc.in"
"${PROJECT_BINARY_DIR}/pkgconfig.pc"
)
set (GCC_COVERAGE_COMPILE_FLAGS "-std=c++14")
set (GCC_COVERAGE_LINK_FLAGS "-Wl,-unresolved-symbols=ignore-in-shared-libs")
IF (DEFINED _DEBUG)
set (GCC_COVERAGE_COMPILE_FLAGS "${GCC_COVERAGE_COMPILE_FLAGS} -g -O0")
set (GCC_COVERAGE_LINK_FLAGS "${GCC_COVERAGE_LINK_FLAGS} -g -O0")
ENDIF()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}")
set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS}")
file(GLOB HEADERS *.h)
file(GLOB SOURCES *.cpp)
include_directories(${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_INSTALL_FULL_INCLUDEDIR}/${Umbrella})
add_library(${PROJECT_NAME}Static STATIC ${SOURCES} ${HEADERS})
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADERS})
set_target_properties(${PROJECT_NAME}Static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
set_target_properties(${PROJECT_NAME}
PROPERTIES
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}
SOVERSION ${VERSION_MAJOR}
)
set_target_properties(${PROJECT_NAME}Static
PROPERTIES
VERSION ${VERSION_MAJOR}.${VERSION_MINOR}
SOVERSION ${VERSION_MAJOR}
)
target_link_libraries(${PROJECT_NAME}Static logger ferrybase)
target_include_directories(TestFFJSON PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/${Umbrella}>
)
add_executable(IteratorIncrement tests/iteratorincrement.cpp)
target_link_libraries(IteratorIncrement FFJSON logger ferrybase)
target_include_directories(IteratorIncrement PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/${Umbrella}>
)
add_test(test1 TestFFJSON)
add_test(test2 IteratorIncrement)
ENDIF()
Its weird! ridiculous! pathetic!
executing cmake twice fixed the issue. Its an another entry into accidental discoveries.

configure code blocks according to two cmake file

I am new to opencv i am trying to find the feature points in face in opencv 3.0 . I am using CLM framework .The examples in the frame work build perfectly when i build it using cmake . I found a CMakelists.txt in the root directory of the frame work and in the example folder . Can anyone help me to configure code blocks according to these 2 cmake file or help me to make a single cmake file to execte my project.
CMakelists.txt [in root folder]
cmake_minimum_required (VERSION 2.6)
project (CLM_framework)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
if(WIN32)
include_directories(lib/3rdParty/OpenCV3.0/include)
include_directories(lib/3rdParty/OpenCV3.0/include/opencv)
if(MSVC_VERSION == 1600)
link_directories( ${PROJECT_SOURCE_DIR}/lib/3rdParty/OpenCV3.0/x86/v100/lib )
endif(MSVC_VERSION)
if(MSVC_VERSION == 1700)
link_directories( ${PROJECT_SOURCE_DIR}/lib/3rdParty/OpenCV3.0/x86/v110/lib )
endif(MSVC_VERSION)
set(OpenCVLibraries
debug opencv_world300d
optimized opencv_world300
)
if (MSVC)
if(MSVC_VERSION == 1600)
file(GLOB files "lib/3rdParty/OpenCV3.0/x86/v100/bin/*.dll")
endif(MSVC_VERSION)
if(MSVC_VERSION == 1700)
file(GLOB files "lib/3rdParty/OpenCV3.0/x86/v110/bin/*.dll")
endif(MSVC_VERSION)
foreach(file ${files})
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Release)
endforeach()
foreach(file ${files})
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Debug)
endforeach()
endif(MSVC)
endif(WIN32)
if(UNIX)
find_package( OpenCV 3.0 REQUIRED )
find_package( Boost REQUIRED COMPONENTS filesystem system)
MESSAGE("Boost information:")
MESSAGE(" Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
MESSAGE(" Boost_LIBRARIES: ${Boost_LIBRARIES}")
MESSAGE(" Boost_LIBRARY_DIRS: ${Boost_LIBRARY_DIRS}")
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS}/boost)
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
endif(UNIX)
find_package(TBB REQUIRED)
# Move CLM model
file(GLOB files "lib/local/CLM/model/*.txt")
foreach(file ${files})
if (MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Debug/model)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Release/model)
else(MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model)
endif(MSVC)
endforeach()
file(GLOB files "lib/local/CLM/model/detection_validation/*.txt")
foreach(file ${files})
if (MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Debug/model/detection_validation)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Release/model/detection_validation)
else(MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model/detection_validation)
endif(MSVC)
endforeach()
file(GLOB files "lib/local/CLM/model/patch_experts/*.txt")
foreach(file ${files})
if (MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Debug/model/patch_experts)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Release/model/patch_experts)
else(MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model/patch_experts)
endif(MSVC)
endforeach()
file(GLOB files "lib/local/CLM/model/pdms/*.txt")
foreach(file ${files})
if (MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Debug/model/pdms)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Release/model/pdms)
else(MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/model/pdms)
endif(MSVC)
endforeach()
# Move OpenCV classifiers
file(GLOB files "lib/3rdParty/OpenCV3.0/classifiers/*.xml")
foreach(file ${files})
if (MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Debug/classifiers)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/Release/classifiers)
else(MSVC)
file(COPY ${file} DESTINATION ${CMAKE_BINARY_DIR}/bin/classifiers)
endif(MSVC)
endforeach()
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
if (GCC_VERSION VERSION_LESS 4.7)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -msse -msse2 -msse3")
else ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -msse -msse2 -msse3")
endif ()
else ()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -msse -msse2 -msse3")
endif ()
# Boost
if(WIN32)
include_directories(lib/3rdParty/boost)
include_directories(lib/3rdParty/boost/boost)
link_directories( ${PROJECT_SOURCE_DIR}/lib/3rdParty/boost/lib )
else()
INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIR})
endif()
# dlib
include_directories(lib/3rdParty/dlib/include)
# dlib library
add_subdirectory(lib/3rdParty/dlib)
# CLM library (ordering matters)
add_subdirectory(lib/local/CLM)
add_subdirectory(lib/local/FaceAnalyser)
# executables
add_subdirectory(exe/SimpleCLMImg)
add_subdirectory(exe/SimpleCLM)
add_subdirectory(exe/MultiTrackCLM)
add_subdirectory(exe/FeatureExtraction)
CMakelists.txt [in exe/MultiTrackCLM]
# Local libraries
include_directories(${CLM_SOURCE_DIR}/include)
include_directories(../../lib/local/CLM/include)
add_executable(MultiTrackCLM MultiTrackCLM.cpp)
target_link_libraries(MultiTrackCLM CLM)
target_link_libraries(MultiTrackCLM dlib)
if(WIN32)
target_link_libraries(MultiTrackCLM ${OpenCVLibraries})
endif(WIN32)
if(UNIX)
target_link_libraries(MultiTrackCLM ${OpenCV_LIBS} ${Boost_LIBRARIES} ${TBB_LIBRARIES})
endif(UNIX)
install (TARGETS MultiTrackCLM DESTINATION ${CMAKE_BINARY_DIR}/bin)