Using DGM library with CMake

Semantic Image Segmentation with Conditional Random Fields
User avatar
Creator
Posts: 157
Joined: Tue Dec 16, 2008, 20: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 (SOLUTION_NAME)

# OpenCV and DGM packages
find_package(OpenCV 3.4 REQUIRED core features2d highgui imgproc imgcodecs ml PATHS "$ENV{OPENCVDIR}/build")
find_package(DGM 1.6 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)
if(MSVC)
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")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")   
endif(MSVC)
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(PROJECT_NAME "source/main.cpp")

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

User avatar
Creator
Posts: 157
Joined: Tue Dec 16, 2008, 20:52
Location: Hannover, Germany
Contact:

Using DGM library v.1.7.0 with CMake

Postby Creator » Sun Jun 30, 2019, 20:02

An update of the CMakeLists.txt file for the newer version of the DGM library (v.1.7.0) with support of C++17:

Code: Select all

cmake_minimum_required (VERSION 3.1)

project (SOLUTION_NAME)

# OpenCV and DGM packages
find_package(OpenCV 4.0 REQUIRED core features2d highgui imgproc imgcodecs ml PATHS "$ENV{OPENCVDIR}/build")
find_package(DGM 1.7 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_STANDARD 17)
if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /wd5040")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS} /DEBUG /INCREMENTAL:NO /OPT:REF /OPT:ICF")
endif(MSVC)
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(PROJECT_NAME "source/main.cpp")

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


Return to “Direct Graphical Models”

Who is online

Users browsing this forum: No registered users and 16 guests