Skip to content

Commit

Permalink
Merge pull request #32 from pmoulon/develop_cmake_install
Browse files Browse the repository at this point in the history
Enhance Cmake usability - Removing local copy of Eigen
  • Loading branch information
laurentkneip authored Mar 24, 2017
2 parents 02697d3 + 7368e88 commit 2e2d219
Show file tree
Hide file tree
Showing 483 changed files with 145 additions and 111,017 deletions.
122 changes: 73 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
cmake_minimum_required(VERSION 2.4.6)
project(opengv)
cmake_minimum_required(VERSION 3.1.0)
project(opengv CXX)

set (OPENGV_VERSION_MAJOR 1)
set (OPENGV_VERSION_MINOR 0)

set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

# ==============================================================================
# Check and enable C++11 support if available
# ==============================================================================
include(CXX11)
check_for_cxx11_compiler(CXX11_COMPILER)
# If a C++11 compiler is available, then set the appropriate flags
IF(CXX11_COMPILER)
enable_cxx11()
ENDIF(CXX11_COMPILER)

# Set the build type. Options are:
#
# None (CMAKE_C_FLAGS or CMAKE_CXX_FLAGS used)
# Debug (CMAKE_C_FLAGS_DEBUG or CMAKE_CXX_FLAGS_DEBUG)
# Release (CMAKE_C_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELEASE)
# RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO
# RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO)
# MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL)

set(CMAKE_BUILD_TYPE Release)
Expand All @@ -33,30 +20,38 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib)

OPTION(BUILD_TESTS "Build tests" ON)
OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF)
OPTION(BUILD_PYTHON "Build Python extension" OFF)
OPTION(BUILD_POSITION_INDEPENDENT_CODE "Build position independent code (-fPIC)" ON)
OPTION(INSTALL_OPENGV "Install OpenGV on the system" OFF)

add_definitions (-Wall -march=native -O3) #TODO use correct c++11 def once everybody has moved to gcc 4.7 # for now I even removed std=gnu++0x
IF(MSVC)
set(BUILD_SHARED_LIBS OFF)
ELSE()
OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF)
OPTION(BUILD_POSITION_INDEPENDENT_CODE "Build position independent code (-fPIC)" ON)
ENDIF()

IF(MSVC)
add_compile_options(/wd4514 /wd4267 $<$<CONFIG:DEBUG>:/bigobj>)
ELSE()
add_definitions (-Wall -march=native -O3)
ENDIF()

IF(BUILD_POSITION_INDEPENDENT_CODE)
add_definitions( -fPIC )
ENDIF()

ADD_DEFINITIONS (
-Wall
-Wextra
#-Werror
-Wwrite-strings
-Wno-unused-parameter
-fno-strict-aliasing
)

# get eigen (under windows)
IF(WIN32)
set(ADDITIONAL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/third_party
${PROJECT_SOURCE_DIR}/third_party/eigen3
${PROJECT_SOURCE_DIR}/third_party/eigen3/unsupported )
ELSE()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/modules/")
find_package(Eigen REQUIRED)
set(ADDITIONAL_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIR}/unsupported )
ENDIF()

include_directories(${ADDITIONAL_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/modules/")
find_package(Eigen REQUIRED)
set(ADDITIONAL_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIR}/unsupported)
include_directories(${PROJECT_SOURCE_DIR}/include)

set( OPENGV_SOURCE_FILES
src/absolute_pose/modules/main.cpp
Expand Down Expand Up @@ -177,18 +172,19 @@ set( OPENGV_HEADER_FILES
include/opengv/relative_pose/MANoncentralRelativeMulti.hpp
include/opengv/point_cloud/MAPointCloud.hpp )

IF(WIN32)
add_library( opengv ${OPENGV_SOURCE_FILES} ${OPENGV_HEADER_FILES} )
add_library( random_generators test/random_generators.cpp test/random_generators.hpp test/experiment_helpers.cpp test/experiment_helpers.hpp test/time_measurement.cpp test/time_measurement.hpp )
ELSE()
add_library( opengv ${OPENGV_SOURCE_FILES} ${OPENGV_HEADER_FILES} )
add_library( random_generators test/random_generators.cpp test/random_generators.hpp test/experiment_helpers.cpp test/experiment_helpers.hpp test/time_measurement.cpp test/time_measurement.hpp )
target_link_libraries(random_generators opengv)
ENDIF()

add_library( opengv ${OPENGV_SOURCE_FILES} ${OPENGV_HEADER_FILES} )
add_library( random_generators test/random_generators.cpp test/random_generators.hpp test/experiment_helpers.cpp test/experiment_helpers.hpp test/time_measurement.cpp test/time_measurement.hpp )
set_target_properties( opengv random_generators PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
DEBUG_POSTFIX d )
target_include_directories( opengv PUBLIC ${ADDITIONAL_INCLUDE_DIRS} )
target_include_directories( random_generators PRIVATE ${ADDITIONAL_INCLUDE_DIRS} )
target_link_libraries( random_generators opengv )

IF (BUILD_TESTS)
enable_testing()
include_directories( ${ADDITIONAL_INCLUDE_DIRS} )

add_executable( test_absolute_pose test/test_absolute_pose.cpp )
target_link_libraries( test_absolute_pose opengv random_generators )
Expand Down Expand Up @@ -298,18 +294,46 @@ IF (BUILD_TESTS)
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND test_Sturm)

ENDIF()
set_target_properties(
test_absolute_pose
test_absolute_pose_sac
test_noncentral_absolute_pose
test_noncentral_absolute_pose_sac
test_multi_noncentral_absolute_pose_sac
test_relative_pose
test_relative_pose_rotationOnly
test_relative_pose_rotationOnly_sac
test_relative_pose_sac
test_noncentral_relative_pose
test_noncentral_relative_pose_sac
test_multi_noncentral_relative_pose_sac
test_eigensolver_sac
test_triangulation
test_eigensolver
test_point_cloud
test_point_cloud_sac
test_Sturm

PROPERTIES
CXX_STANDARD 11
CXX_STANDARD_REQUIRED ON
DEBUG_POSTFIX d )


IF (INSTALL_OPENGV)
install(
TARGETS opengv
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
COMPONENT library
)
ENDIF()

install(
TARGETS opengv
EXPORT opengv-export
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
COMPONENT library
)
target_include_directories(opengv PUBLIC "${CMAKE_INSTALL_PREFIX}/include")
install(DIRECTORY include/ DESTINATION include/ FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
install(EXPORT opengv-export DESTINATION CMake FILE opengv-config.cmake)


if (BUILD_PYTHON)
add_subdirectory( python )
Expand Down
35 changes: 0 additions & 35 deletions cmake/CXX11.cmake

This file was deleted.

44 changes: 0 additions & 44 deletions cmake/CheckCXXCompilerFlag.cmake

This file was deleted.

52 changes: 45 additions & 7 deletions doc/addons/01_installation.dox
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,28 @@ http://git-scm.com/
sudo apt-get install build-essential
\endverbatim
*
* <li>Install cmake and eigen3, those tools are required by the library. Type:
* <li>Install cmake. CMake is a cross-platform, open-source build system used for pretty much anything in the compilation process for the compilation/linking of the library. Type:
*
\verbatim
sudo apt-get install cmake libeigen3-dev
sudo apt-get install cmake
\endverbatim
*
* CMake is a cross-platform, open-source build system used for pretty much anything in the compilation process but the compilation/linking itself. Eigen3 is a powerful linear algebra library used for all computations in OpenGV.
*
* <li>Install eigen3. Eigen3 is a powerful linear algebra library used for all computations in OpenGV. You can either use an installed version of a local install (unzipped version of Eigen3 downloaded from Eigen website).
*
\verbatim
sudo apt-get install cmake libeigen3-dev
\endverbatim
*
* <li>Go to the top-level directory of OpenGV. Type:
*
\verbatim
mkdir build && cd build && cmake .. && make
\endverbatim
*
* If a message like "Could NOT find Eigen (missing: EIGEN_INCLUDE_DIR EIGEN_VERSION_OK)" appears. It's certainly because that you does not have Eigen3 installed on your computer system path. You can specify to cmake the path where Eigen is located by adding:
\verbatim
mkdir build && cd build && cmake .. -DEIGEN_INCLUDE_DIR:STRING="EigenIncludePath" && make
\endverbatim
*
* <li>Done. The default configuration does not build the tests or python-wrappers, please set the according variables in CMakeLists.txt to ON if you desire the tests or python-wrappers to be built as well.
Expand Down Expand Up @@ -102,7 +112,7 @@ msbuild opengv.sln /p:Configuration=Release
*
* inside the build directory. While there is not a single warning under Linux, there are thousands of warnings under Windows :) If anyone knows the reason, please let us know.
*
* <li>Note that we included third-party stuff like eigen in the sub-folder third_party. It is cleaner to get a fresh download of those dependencies on your computer, and reset the INCLUDE-directories in the CMakeLists.txt file. You should absolutely do so if you already have a version of these dependencies installed on your system.
* <li>Note that we Eigen dependency is not longer included. It is better to get a fresh download of Eigen on your computer, and specify to cmake the Eigen include path with -DEIGEN_INCLUDE_DIR="path".
* </ul>
*
* \section sec_installation_35 Installation under OSX
Expand All @@ -117,7 +127,17 @@ msbuild opengv.sln /p:Configuration=Release
*
* \section sec_installation_36 Installing OpenGV on the host OS
*
* At least under Linux and OSX, the installation on the host OS (including the headers) can be activated by simply setting INSTALL_OPENGV to ON.
* Installation on the host OS (including the headers) can be activated by simply launching the install target.
* By using "sudo make install" on Linux and OSX and by compiling the install target on the opengv Visual Studio solution in Windows. Sudo is required for system install.
* You can choose to have a local installation path by setting the cmake variable CMAKE_INSTALL_PREFIX to the path of your choice by using -DCMAKE_INSTALL_PREFIX:STRING="YourInstallPath" in the cmake command line.
\verbatim
cmake ../opengv
-DEIGEN_INCLUDE_DIR="EigenIncludePath"
-DBUILD_TESTS=ON
-DCMAKE_INSTALL_PREFIX="YourInstallPath"
make
make install #sudo not required since we use a local installation
\endverbatim
*
* \section sec_installation_4 Installing the Matlab-wrapper (Windows-version)
*
Expand All @@ -139,7 +159,7 @@ http://jimdavid.blogspot.com.au/2012/12/matlab-2012b-mex-setup-with-vs2012.html
* <li>Once this is done, you can compile the mex-file by going to the opengv/matlab folder and typing in the console
*
\verbatim
mex -I../include -I../third_party -I../third_party/eigen3 -L../build/lib/Release -lopengv opengv.cpp
mex -I../include -I../EigenIncludePath -L../build/lib/Release -lopengv opengv.cpp
\endverbatim
*
* <li>An additional note on 64-bit Windows/Matlab systems: If you have a Matlab version that is 64-bit, you will have to also compile OpenGV in 64-bit. You will have to follow
Expand Down Expand Up @@ -170,7 +190,7 @@ export LD_LIBRARY_PATH=<path to OpenGV>/build/lib:$LD_LIBRARY_PATH
* <li>Go to the opengv/matlab-folder inside Matlab, and issue the command
*
\verbatim
mex -I../include -I../third_party -I../third_party/eigen3 -L../build/lib -lopengv opengv.cpp -cxx
mex -I../include -I../EigenIncludePath -L../build/lib -lopengv opengv.cpp -cxx
\endverbatim
*
* Note the lib directory does not contain a Release subfolder under linux, and that the -cxx option has to be added.
Expand All @@ -184,4 +204,22 @@ mex -I../include -I../third_party -I../third_party/eigen3 -L../build/lib -lopeng
*
* The compliation of the Python wrappers can be enabled by setting the option BUILD_PYTHON to ON. Note that the python wrappers depend additionally on boost, and that the wrapper currently only allows access to the central methods.
*
* \section sec_installation_8 Using the OpenGV inside your cmake c++ project
*
* Once your have a system or local install of opengv you can use it in your own project.
* In your cmake file, add the search for the opengv library:
\verbatim
find_package(opengv REQUIRED)
if (opengv_FOUND)
add_executable(main_opengv_demo main.cpp)
target_link_libraries(main_opengv_demo opengv)
endif (opengv_FOUND)
\endverbatim
*
* Then run cmake for your project (if you are using a local install of opengv, you can specify where the library is located by using -Dopengv_DIR:
\verbatim
cmake ../myproject
-DCMAKE_BUILD_TYPE=RELEASE
-Dopengv_DIR:STRING=/home/Foo/Documents/Dev/opengv_Build/install/CMake/
\endverbatim
*/
2 changes: 0 additions & 2 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ include_directories(${PYTHON_INCLUDE_DIRS})
find_package(NumPy REQUIRED)
include_directories(${NUMPY_INCLUDE_DIRS})


add_library( pyopengv SHARED pyopengv.cpp )
target_link_libraries(pyopengv opengv)


set_target_properties(pyopengv PROPERTIES
PREFIX ""
SUFFIX ".so"
Expand Down
Loading

0 comments on commit 2e2d219

Please sign in to comment.