Using DGM library with CMake

Semantic Image Segmentation with Conditional Random Fields
User avatar
Creator
Posts: 125
Joined: Tue Dec 16, 2008, 21:52
Location: Hannover, Germany
Contact:

Using DGM library with CMake

Postby Creator » Wed Apr 19, 2017, 20:23

The easiest way to include the DGM library into your project is to use the find_package(DGM) command in your CMakeLists.txt file, e.g.:

Code: Select all

find_package(DGM 1.5 REQUIRED PATHS "$ENV{DGMDIR}/build/install")

where "$ENV{DGMDIR}/build/install" is the path to the directory, containing the DGMConfig.cmake file. DGMDIR here is the system variable, pointing to the directory with the DGM library.
The find_package(DGM) command will set the DGM_INCLUDE_DIRS and DGM_LIBRARIES variables, which should be used as follows:

Code: Select all

# Properties -> C/C++ -> General -> Additional Include Directories
include_directories(${DGM_INCLUDE_DIRS})

and

Code: Select all

# Properties -> Linker -> Input -> Additional Dependencies
target_link_libraries(your_project ${DGM_LIBRARIES})

The example of a complete CMakeLists.txt file:

Code: Select all

cmake_minimum_required (VERSION 3.1)

project (SparseCoding)

# OpenCV and DGM packages
find_package(OpenCV 3 REQUIRED core features2d highgui imgproc imgcodecs ml PATHS "$ENV{OPENCVDIR}/build")
find_package(DGM 1.5 REQUIRED PATHS "$ENV{DGMDIR}/build/install")

# Turn on the ability to create folders to organize projects (.vcproj)
# It creates "CMakePredefinedTargets" folder by default and adds CMake defined projects like INSTALL.vcproj and ZERO_CHECK.vcproj
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Sets
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi")   
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

# Properties -> C/C++ -> General -> Additional Include Directories
include_directories(${OpenCV_INCLUDE_DIRS} ${DGM_INCLUDE_DIRS})

#definitions
add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS)

add_executable(sc_train "source/sc_train.cpp")
add_executable(sc_test  "source/sc_test.cpp")

# Properties -> Linker -> Input -> Additional Dependencies
target_link_libraries(sc_train ${OpenCV_LIBS} ${DGM_LIBRARIES})
target_link_libraries(sc_test ${OpenCV_LIBS} ${DGM_LIBRARIES})

Return to “Direct Graphical Models”

Who is online

Users browsing this forum: No registered users and 1 guest