Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Modify CMakeLists.txt to use opencv4 and can be use more convenient. #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

build
install
83 changes: 46 additions & 37 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# ----------------------------------------------------------------------------
# Basic Configuration
# ----------------------------------------------------------------------------
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
CMAKE_MINIMUM_REQUIRED(VERSION 3.15)

set(CMAKE_CXX_STANDARD 11)

PROJECT(DBoW3)
set(PROJECT_VERSION "0.0.1")
string(REGEX MATCHALL "[0-9]" PROJECT_VERSION_PARTS "${PROJECT_VERSION}")
list(GET PROJECT_VERSION_PARTS 0 PROJECT_VERSION_MAJOR)
list(GET PROJECT_VERSION_PARTS 1 PROJECT_VERSION_MINOR)
list(GET PROJECT_VERSION_PARTS 2 PROJECT_VERSION_PATCH)

PROJECT(DBoW3 VERSION 0.0.1)
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")

message("LIB_INSTALL_DIR: ${LIB_INSTALL_DIR}")
# set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "Install path prefix, prepended onto install directories." FORCE)
set(LIB_INSTALL_DIR CMAKE_INSTALL_PREFIX)
message(STATUS "LIB_INSTALL_DIR: ${LIB_INSTALL_DIR}")

#------------------------------------------------------
# Build type
Expand All @@ -40,9 +38,6 @@ else()
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}/cmake/ /usr/${LIB_INSTALL_DIR}/cmake )
endif()



#
OPTION(BUILD_UTILS "Set to OFF to not build utils" ON)
OPTION(USE_CONTRIB "Set to ON if contrib are installed" OFF)
OPTION(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON)
Expand All @@ -54,12 +49,15 @@ find_package(OpenCV REQUIRED)
IF(USE_CONTRIB)
add_definitions(-DUSE_CONTRIB)
ENDIF()
if(NOT OpenCV_VERSION VERSION_LESS "3.0")
ADD_DEFINITIONS(-DOPENCV_VERSION_3)
SET(OPENCV_VERSION_3 ON)
ELSE()
SET(OPENCV_VERSION_3 OFF)
ENDIF()

ADD_DEFINITIONS(-DOPENCV_VERSION_3)
SET(OPENCV_VERSION_3 ON)
# if(NOT OpenCV_VERSION VERSION_LESS "3.0")
# ADD_DEFINITIONS(-DOPENCV_VERSION_3)
# SET(OPENCV_VERSION_3 ON)
# ELSE()
# SET(OPENCV_VERSION_3 OFF)
# ENDIF()

include_directories(${OpenCV_INCLUDE_DIRS})

Expand All @@ -76,24 +74,6 @@ IF (INSTALL_DOC)
INCLUDE("${PROJECT_SOURCE_DIR}/generateDoc.cmake")
GENERATE_DOCUMENTATION(${PROJECT_SOURCE_DIR}/dox.in)
ENDIF()

# ----------------------------------------------------------------------------
# Uninstall target, for "make uninstall"
# ----------------------------------------------------------------------------
CONFIGURE_FILE( "${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

# ----------------------------------------------------------------------------
# create configuration file from .in file (If you use windows take care with paths)
# ----------------------------------------------------------------------------

CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/config.cmake.in" "${PROJECT_BINARY_DIR}/Find${PROJECT_NAME}.cmake")
CONFIGURE_FILE("${PROJECT_SOURCE_DIR}/config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake")
INSTALL(FILES "${PROJECT_BINARY_DIR}/Find${PROJECT_NAME}.cmake" DESTINATION ${LIB_INSTALL_DIR}/cmake/ )
INSTALL(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" DESTINATION ${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME} )




# ----------------------------------------------------------------------------
# Program Optimization and debug (Extracted from OpenCV)
Expand Down Expand Up @@ -206,8 +186,6 @@ ELSE() # MSVC
ENDIF()#END OF COMPILER SPECIFIC OPTIONS
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS_RELEASE}")
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} ${EXTRA_C_FLAGS_DEBUG}")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=c++11")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=c++11")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELEASE} ${CMAKE_C_FLAGS_DEBUG}")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_CXX_FLAGS_DEBUG}")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EXTRA_EXE_LINKER_FLAGS}")
Expand All @@ -228,6 +206,37 @@ IF (BUILD_TESTS)
ADD_SUBDIRECTORY(tests)
ENDIF()

# ----------------------------------------------------------------------------
# generate the config file that is includes the exports
# ----------------------------------------------------------------------------

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
${PROJECT_NAME}ConfigVersion.cmake
VERSION
${PROJECT_VERSION}
COMPATIBILITY
SameMajorVersion
)
configure_package_config_file(
${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

# ----------------------------------------------------------------------------
# Uninstall target, for "make uninstall"
# ----------------------------------------------------------------------------
CONFIGURE_FILE( "cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
ADD_CUSTOM_TARGET(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

# ----------------------------------------------------------------------------
# display status message for important variables
Expand Down
10 changes: 10 additions & 0 deletions cmake/DBoW3Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
set(@PROJECT_NAME@_VERSION @PROJECT_VERSION@)

@PACKAGE_INIT@

set_and_check(@PROJECT_NAME@_INCLUDE_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../include")
cmake_path(SET @PROJECT_NAME@_INCLUDE_DIR NORMALIZE "${@PROJECT_NAME@_INCLUDE_DIR}")

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")

check_required_components(@PROJECT_NAME@)
File renamed without changes.
15 changes: 9 additions & 6 deletions src/BowVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

#include <map>
#include <vector>
#include <string>
#include <iostream>

#include "exports.h"
#if _WIN32
#include <cstdint>
Expand Down Expand Up @@ -60,7 +63,7 @@ class DBOW_API BowVector:
{
public:

/**
/**
* Constructor
*/
BowVector(void);
Expand All @@ -69,15 +72,15 @@ class DBOW_API BowVector:
* Destructor
*/
~BowVector(void);

/**
* Adds a value to a word value existing in the vector, or creates a new
* word with the given value
* @param id word id to look for
* @param v value to create the word with, or to add to existing word
*/
void addWeight(WordId id, WordValue v);

/**
* Adds a word with a value to the vector only if this does not exist yet
* @param id word id to look for
Expand All @@ -86,18 +89,18 @@ class DBOW_API BowVector:
void addIfNotExist(WordId id, WordValue v);

/**
* L1-Normalizes the values in the vector
* L1-Normalizes the values in the vector
* @param norm_type norm used
*/
void normalize(LNorm norm_type);

/**
* Prints the content of the bow vector
* @param out stream
* @param v
*/
friend std::ostream& operator<<(std::ostream &out, const BowVector &v);

/**
* Saves the bow vector as a vector in a matlab file
* @param filename
Expand Down
56 changes: 43 additions & 13 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,58 @@ FILE(GLOB srcs ${srcs_base} )


ADD_LIBRARY(${PROJECT_NAME} ${srcs} ${hdrs})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} )
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR} )

SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES # create *nix style library versions + symbolic links
DEFINE_SYMBOL DBOW_DSO_EXPORTS
DEFINE_SYMBOL DBOW_DSO_EXPORTS
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_SOVERSION}
CLEAN_DIRECT_OUTPUT 1 # allow creating static and shared libs without conflicts
OUTPUT_NAME "${PROJECT_NAME}${PROJECT_DLLVERSION}" # avoid conflicts between library and binary target names
OUTPUT_NAME "${PROJECT_NAME}${PROJECT_DLLVERSION}"
DEBUG_POSTFIX "d" # avoid conflicts between library and binary target names
)

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${REQUIRED_LIBRARIES} )

INSTALL(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION bin COMPONENT main # Install the dll file in bin directory
LIBRARY DESTINATION ${LIB_INSTALL_DIR} PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE COMPONENT main
ARCHIVE DESTINATION ${LIB_INSTALL_DIR} COMPONENT main) # Install the dll.a file in lib directory



INSTALL(FILES ${hdrs_base}
DESTINATION include/${PROJECT_NAME}
COMPONENT main)
target_include_directories(
${PROJECT_NAME}
PUBLIC
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src>
)

include(GNUInstallDirs)
install(
TARGETS
${PROJECT_NAME}
EXPORT
${PROJECT_NAME}Targets
LIBRARY DESTINATION
${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION
${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION
${CMAKE_INSTALL_LIBDIR}
INCLUDES DESTINATION
include
PUBLIC_HEADER DESTINATION
include
)

install(
EXPORT
${PROJECT_NAME}Targets
FILE
${PROJECT_NAME}Targets.cmake
NAMESPACE
${PROJECT_NAME}::
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

install(
FILES
${hdrs_base}
DESTINATION
include/${PROJECT_NAME}
)
10 changes: 7 additions & 3 deletions src/FeatureVector.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
#define __D_T_FEATURE_VECTOR__

#include "BowVector.h"

#include <map>
#include <vector>
#include <string>
#include <iostream>

#include "exports.h"
namespace DBoW3 {

Expand All @@ -26,12 +30,12 @@ class DBOW_API FeatureVector:
* Constructor
*/
FeatureVector(void);

/**
* Destructor
*/
~FeatureVector(void);

/**
* Adds a feature to an existing node, or adds a new node with an initial
* feature
Expand All @@ -46,7 +50,7 @@ class DBOW_API FeatureVector:
* @param v feature vector
*/
friend std::ostream& operator<<(std::ostream &out, const FeatureVector &v);

};

} // namespace DBoW3
Expand Down