Skip to content

Commit

Permalink
[build] CMake improvments. openMVG#1235
Browse files Browse the repository at this point in the history
- Use CMake OpenMVG:: namespace as an option.
- Extend command line build documentation for Visual Studio.
  • Loading branch information
mitjap authored and pmoulon committed Mar 4, 2018
1 parent 1881729 commit 07ca8b2
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 29 deletions.
22 changes: 22 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ $ git clone --recursive https://github.com/openMVG/openMVG.git
6. Change the target to Release.
7. Compile the libraries and binaries samples.

Another options is to build with cmake in console. I recommend launching `VS2015 x64 Native Tools Command Prompt` which has build environment already set up.

```shell
git clone --recursive https://github.com/openMVG/openMVG.git
mkdir openMVG-build
cd openMVG-build
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="c:/openMVG" -G "NMake Makefiles" ../openMVG/src/
cmake --build . --target install
```

Mac compilation
-------------------
<a name="macos"></a>
Expand Down Expand Up @@ -184,6 +194,18 @@ add_executable(main main.cpp)
target_link_libraries(main ${OPENMVG_LIBRARIES})
```

or with modern target-based approach (CMake 3.0+)

```
find_package(OpenMVG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main
PRIVATE
OpenMVG::openMVG_sfm
OpenMVG::openMVG_matching
)
```

Specify in CMake where OpenMVG has been installed by using the CMake OpenMVG_DIR variable
e.g. `-DOpenMVG_DIR:STRING="YourInstallPath"/share/openMVG/cmake`

Expand Down
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,10 @@ message("\n")

install(EXPORT openMVG-targets DESTINATION lib)
install(EXPORT openMVG-targets
DESTINATION share/openMVG/cmake FILE OpenMVGTargets.cmake)
FILE OpenMVGTargets.cmake
NAMESPACE OpenMVG::
DESTINATION share/openMVG/cmake
)

#Adapt build include paths to install path
set(OpenMVG_INCLUDE_DIRS
Expand Down
2 changes: 1 addition & 1 deletion src/cmakeFindModules/OpenMVGConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ macro(OPENMVG_REPORT_NOT_FOUND REASON_MSG)
# FindPackage() use the camelcase library name, not uppercase.
if (OPENMVG_FIND_QUIETLY)
message(STATUS "Failed to find OPENMVG - " ${REASON_MSG} ${ARGN})
else (OPENMVG_FIND_REQUIRED)
elseif (OPENMVG_FIND_REQUIRED)
message(FATAL_ERROR "Failed to find OPENMVG - " ${REASON_MSG} ${ARGN})
else()
# Neither QUIETLY nor REQUIRED, use SEND_ERROR which emits an error
Expand Down
3 changes: 2 additions & 1 deletion src/openMVG/features/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ target_include_directories(openMVG_features
$<BUILD_INTERFACE:${EIGEN_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CEREAL_INCLUDE_DIRS}>
#$<INSTALL_INTERFACE:include/openMVG/>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/openMVG>
#$<INSTALL_INTERFACE:include/openMVG/dependencies>
)
target_link_libraries(openMVG_features PRIVATE fast)
Expand Down
5 changes: 4 additions & 1 deletion src/openMVG/geodesy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

add_library(openMVG_geodesy INTERFACE)
target_link_libraries(openMVG_geodesy INTERFACE openMVG_numeric)
target_link_libraries(openMVG_geodesy
INTERFACE
openMVG_numeric
)
install(TARGETS openMVG_geodesy DESTINATION lib EXPORT openMVG-targets)

UNIT_TEST(openMVG_geodesy geodesy "openMVG_geodesy")
11 changes: 9 additions & 2 deletions src/openMVG/geometry/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ add_library(openMVG_geometry ${geometry_files_header} ${geometry_files_cpp})
set_target_properties(openMVG_geometry PROPERTIES SOVERSION ${OPENMVG_VERSION_MAJOR} VERSION "${OPENMVG_VERSION_MAJOR}.${OPENMVG_VERSION_MINOR}")

target_link_libraries(openMVG_geometry
PUBLIC openMVG_numeric
PRIVATE openMVG_linearProgramming)
PUBLIC
openMVG_numeric
PRIVATE
openMVG_linearProgramming
)
target_include_directories(openMVG_geometry
PUBLIC
$<INSTALL_INTERFACE:include>
)

install(TARGETS openMVG_geometry DESTINATION lib EXPORT openMVG-targets)

Expand Down
19 changes: 12 additions & 7 deletions src/openMVG/image/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ file(GLOB_RECURSE REMOVEFILESUNITTEST *_test.cpp)
list(REMOVE_ITEM image_files_cpp ${REMOVEFILESUNITTEST})

add_library(openMVG_image ${image_files_header} ${image_files_cpp})
target_link_libraries(
openMVG_image
PUBLIC openMVG_numeric
PRIVATE
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
${TIFF_LIBRARIES})
target_link_libraries(openMVG_image
PUBLIC
openMVG_numeric
PRIVATE
${JPEG_LIBRARIES}
${PNG_LIBRARIES}
${TIFF_LIBRARIES}
)
target_include_directories(openMVG_image
PUBLIC
$<INSTALL_INTERFACE:include>
)
set_target_properties(openMVG_image PROPERTIES SOVERSION ${OPENMVG_VERSION_MAJOR} VERSION "${OPENMVG_VERSION_MAJOR}.${OPENMVG_VERSION_MINOR}")
install(TARGETS openMVG_image DESTINATION lib EXPORT openMVG-targets)

Expand Down
5 changes: 4 additions & 1 deletion src/openMVG/linearProgramming/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ install(TARGETS openMVG_linearProgramming DESTINATION lib EXPORT openMVG-targets
set_target_properties(openMVG_linearProgramming PROPERTIES SOVERSION ${OPENMVG_VERSION_MAJOR} VERSION "${OPENMVG_VERSION_MAJOR}.${OPENMVG_VERSION_MINOR}")

target_link_libraries(openMVG_linearProgramming
PUBLIC openMVG_numeric
PUBLIC
openMVG_numeric
PRIVATE
${CLP_LIBRARIES} # clp + solver wrapper
${COINUTILS_LIBRARY} # container tools
Expand All @@ -23,6 +24,8 @@ target_include_directories(openMVG_linearProgramming
${CLP_INCLUDE_DIRS}
${COINUTILS_INCLUDE_DIRS}
${OSI_INCLUDE_DIRS}
PUBLIC
$<INSTALL_INTERFACE:include>
)

set(UNIT_TEST_LIBS openMVG_linearProgramming)
Expand Down
17 changes: 13 additions & 4 deletions src/openMVG/matching/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,23 @@ add_library(openMVG_matching
${matching_files_header}
${matching_files_cpp})
target_include_directories(openMVG_matching
PUBLIC $<BUILD_INTERFACE:${FLANN_INCLUDE_DIRS}>
PUBLIC
$<BUILD_INTERFACE:${FLANN_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/openMVG>
)
target_link_libraries(openMVG_matching
PRIVATE stlplus
PUBLIC openMVG_features Threads::Threads)
PRIVATE
stlplus
PUBLIC
openMVG_features
Threads::Threads
)
if (NOT DEFINED OpenMVG_USE_INTERNAL_FLANN)
target_link_libraries(openMVG_matching
PUBLIC ${FLANN_LIBRARIES})
PUBLIC
${FLANN_LIBRARIES}
)
endif()
set_target_properties(openMVG_matching PROPERTIES SOVERSION ${OPENMVG_VERSION_MAJOR} VERSION "${OPENMVG_VERSION_MAJOR}.${OPENMVG_VERSION_MINOR}")
set_property(TARGET openMVG_matching PROPERTY FOLDER OpenMVG/OpenMVG)
Expand Down
6 changes: 4 additions & 2 deletions src/openMVG/matching_image_collection/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ target_link_libraries(openMVG_matching_image_collection
PUBLIC
openMVG_matching
openMVG_multiview)
target_include_directories(openMVG_matching_image_collection PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/include/openMVG/>
target_include_directories(openMVG_matching_image_collection
PUBLIC
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/openMVG>
)
set_target_properties(openMVG_matching_image_collection PROPERTIES SOVERSION ${OPENMVG_VERSION_MAJOR} VERSION "${OPENMVG_VERSION_MAJOR}.${OPENMVG_VERSION_MINOR}")
set_property(TARGET openMVG_matching_image_collection PROPERTY FOLDER OpenMVG)
Expand Down
14 changes: 8 additions & 6 deletions src/openMVG/multiview/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@ add_library(openMVG_multiview
${multiview_files_cpp})
set_property(TARGET openMVG_multiview PROPERTY FOLDER OpenMVG)
install(TARGETS openMVG_multiview DESTINATION lib EXPORT openMVG-targets)
target_link_libraries(
openMVG_multiview
target_link_libraries(openMVG_multiview
PUBLIC
openMVG_numeric
PRIVATE
openMVG_graph
${CERES_LIBRARIES})
target_include_directories(
openMVG_multiview
${CERES_LIBRARIES}
)
target_include_directories(openMVG_multiview
PRIVATE
${CERES_INCLUDE_DIRS})
${CERES_INCLUDE_DIRS}
PUBLIC
$<INSTALL_INTERFACE:include>
)
set_target_properties(openMVG_multiview PROPERTIES SOVERSION ${OPENMVG_VERSION_MAJOR} VERSION "${OPENMVG_VERSION_MAJOR}.${OPENMVG_VERSION_MINOR}")

add_library(openMVG_multiview_test_data ${MULTIVIEWTESTDATA})
Expand Down
8 changes: 5 additions & 3 deletions src/openMVG/numeric/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ list(REMOVE_ITEM numeric_files_cpp ${REMOVEFILESUNITTEST})
add_library(openMVG_numeric
${numeric_files_header}
${numeric_files_cpp})
target_include_directories(openMVG_numeric PUBLIC
$<BUILD_INTERFACE:${EIGEN_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
target_include_directories(openMVG_numeric
PUBLIC
$<BUILD_INTERFACE:${EIGEN_INCLUDE_DIRS}>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>
)
if (DEFINED OpenMVG_USE_INTERNAL_EIGEN)
target_include_directories(openMVG_numeric PUBLIC
Expand Down
3 changes: 3 additions & 0 deletions src/openMVG/sfm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ target_link_libraries(openMVG_sfm
target_include_directories(openMVG_sfm
PRIVATE
${CERES_INCLUDE_DIRS}
PUBLIC
$<INSTALL_INTERFACE:include>
$<INSTALL_INTERFACE:include/openMVG>
)
set_target_properties(openMVG_sfm PROPERTIES SOVERSION ${OPENMVG_VERSION_MAJOR} VERSION "${OPENMVG_VERSION_MAJOR}.${OPENMVG_VERSION_MINOR}")

Expand Down

0 comments on commit 07ca8b2

Please sign in to comment.