Skip to content

Commit 2e2d219

Browse files
authored
Merge pull request #32 from pmoulon/develop_cmake_install
Enhance Cmake usability - Removing local copy of Eigen
2 parents 02697d3 + 7368e88 commit 2e2d219

File tree

483 files changed

+145
-111017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

483 files changed

+145
-111017
lines changed

CMakeLists.txt

Lines changed: 73 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
1-
cmake_minimum_required(VERSION 2.4.6)
2-
project(opengv)
1+
cmake_minimum_required(VERSION 3.1.0)
2+
project(opengv CXX)
33

44
set (OPENGV_VERSION_MAJOR 1)
55
set (OPENGV_VERSION_MINOR 0)
66

7-
set(CMAKE_MODULE_PATH
8-
${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
9-
10-
# ==============================================================================
11-
# Check and enable C++11 support if available
12-
# ==============================================================================
13-
include(CXX11)
14-
check_for_cxx11_compiler(CXX11_COMPILER)
15-
# If a C++11 compiler is available, then set the appropriate flags
16-
IF(CXX11_COMPILER)
17-
enable_cxx11()
18-
ENDIF(CXX11_COMPILER)
19-
207
# Set the build type. Options are:
218
#
229
# None (CMAKE_C_FLAGS or CMAKE_CXX_FLAGS used)
2310
# Debug (CMAKE_C_FLAGS_DEBUG or CMAKE_CXX_FLAGS_DEBUG)
2411
# Release (CMAKE_C_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELEASE)
25-
# RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO
12+
# RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO)
2613
# MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL)
2714

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

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

41-
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
25+
IF(MSVC)
26+
set(BUILD_SHARED_LIBS OFF)
27+
ELSE()
28+
OPTION(BUILD_SHARED_LIBS "Build shared libraries" OFF)
29+
OPTION(BUILD_POSITION_INDEPENDENT_CODE "Build position independent code (-fPIC)" ON)
30+
ENDIF()
31+
32+
IF(MSVC)
33+
add_compile_options(/wd4514 /wd4267 $<$<CONFIG:DEBUG>:/bigobj>)
34+
ELSE()
35+
add_definitions (-Wall -march=native -O3)
36+
ENDIF()
4237

4338
IF(BUILD_POSITION_INDEPENDENT_CODE)
4439
add_definitions( -fPIC )
4540
ENDIF()
4641

42+
ADD_DEFINITIONS (
43+
-Wall
44+
-Wextra
45+
#-Werror
46+
-Wwrite-strings
47+
-Wno-unused-parameter
48+
-fno-strict-aliasing
49+
)
4750

48-
# get eigen (under windows)
49-
IF(WIN32)
50-
set(ADDITIONAL_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/third_party
51-
${PROJECT_SOURCE_DIR}/third_party/eigen3
52-
${PROJECT_SOURCE_DIR}/third_party/eigen3/unsupported )
53-
ELSE()
54-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/modules/")
55-
find_package(Eigen REQUIRED)
56-
set(ADDITIONAL_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIR}/unsupported )
57-
ENDIF()
58-
59-
include_directories(${ADDITIONAL_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include)
51+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/modules/")
52+
find_package(Eigen REQUIRED)
53+
set(ADDITIONAL_INCLUDE_DIRS ${EIGEN_INCLUDE_DIRS} ${EIGEN_INCLUDE_DIR}/unsupported)
54+
include_directories(${PROJECT_SOURCE_DIR}/include)
6055

6156
set( OPENGV_SOURCE_FILES
6257
src/absolute_pose/modules/main.cpp
@@ -177,18 +172,19 @@ set( OPENGV_HEADER_FILES
177172
include/opengv/relative_pose/MANoncentralRelativeMulti.hpp
178173
include/opengv/point_cloud/MAPointCloud.hpp )
179174

180-
IF(WIN32)
181-
add_library( opengv ${OPENGV_SOURCE_FILES} ${OPENGV_HEADER_FILES} )
182-
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 )
183-
ELSE()
184-
add_library( opengv ${OPENGV_SOURCE_FILES} ${OPENGV_HEADER_FILES} )
185-
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 )
186-
target_link_libraries(random_generators opengv)
187-
ENDIF()
188-
175+
add_library( opengv ${OPENGV_SOURCE_FILES} ${OPENGV_HEADER_FILES} )
176+
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 )
177+
set_target_properties( opengv random_generators PROPERTIES
178+
CXX_STANDARD 11
179+
CXX_STANDARD_REQUIRED ON
180+
DEBUG_POSTFIX d )
181+
target_include_directories( opengv PUBLIC ${ADDITIONAL_INCLUDE_DIRS} )
182+
target_include_directories( random_generators PRIVATE ${ADDITIONAL_INCLUDE_DIRS} )
183+
target_link_libraries( random_generators opengv )
189184

190185
IF (BUILD_TESTS)
191186
enable_testing()
187+
include_directories( ${ADDITIONAL_INCLUDE_DIRS} )
192188

193189
add_executable( test_absolute_pose test/test_absolute_pose.cpp )
194190
target_link_libraries( test_absolute_pose opengv random_generators )
@@ -298,18 +294,46 @@ IF (BUILD_TESTS)
298294
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
299295
COMMAND test_Sturm)
300296

301-
ENDIF()
297+
set_target_properties(
298+
test_absolute_pose
299+
test_absolute_pose_sac
300+
test_noncentral_absolute_pose
301+
test_noncentral_absolute_pose_sac
302+
test_multi_noncentral_absolute_pose_sac
303+
test_relative_pose
304+
test_relative_pose_rotationOnly
305+
test_relative_pose_rotationOnly_sac
306+
test_relative_pose_sac
307+
test_noncentral_relative_pose
308+
test_noncentral_relative_pose_sac
309+
test_multi_noncentral_relative_pose_sac
310+
test_eigensolver_sac
311+
test_triangulation
312+
test_eigensolver
313+
test_point_cloud
314+
test_point_cloud_sac
315+
test_Sturm
316+
317+
PROPERTIES
318+
CXX_STANDARD 11
319+
CXX_STANDARD_REQUIRED ON
320+
DEBUG_POSTFIX d )
321+
302322

303-
IF (INSTALL_OPENGV)
304-
install(
305-
TARGETS opengv
306-
ARCHIVE DESTINATION lib
307-
LIBRARY DESTINATION lib
308-
COMPONENT library
309-
)
310323
ENDIF()
311324

325+
install(
326+
TARGETS opengv
327+
EXPORT opengv-export
328+
RUNTIME DESTINATION bin
329+
ARCHIVE DESTINATION lib
330+
LIBRARY DESTINATION lib
331+
COMPONENT library
332+
)
333+
target_include_directories(opengv PUBLIC "${CMAKE_INSTALL_PREFIX}/include")
312334
install(DIRECTORY include/ DESTINATION include/ FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp")
335+
install(EXPORT opengv-export DESTINATION CMake FILE opengv-config.cmake)
336+
313337

314338
if (BUILD_PYTHON)
315339
add_subdirectory( python )

cmake/CXX11.cmake

Lines changed: 0 additions & 35 deletions
This file was deleted.

cmake/CheckCXXCompilerFlag.cmake

Lines changed: 0 additions & 44 deletions
This file was deleted.

doc/addons/01_installation.dox

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,28 @@ http://git-scm.com/
4444
sudo apt-get install build-essential
4545
\endverbatim
4646
*
47-
* <li>Install cmake and eigen3, those tools are required by the library. Type:
47+
* <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:
4848
*
4949
\verbatim
50-
sudo apt-get install cmake libeigen3-dev
50+
sudo apt-get install cmake
5151
\endverbatim
5252
*
53-
* 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.
53+
*
54+
* <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).
55+
*
56+
\verbatim
57+
sudo apt-get install cmake libeigen3-dev
58+
\endverbatim
5459
*
5560
* <li>Go to the top-level directory of OpenGV. Type:
5661
*
5762
\verbatim
5863
mkdir build && cd build && cmake .. && make
64+
\endverbatim
65+
*
66+
* 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:
67+
\verbatim
68+
mkdir build && cd build && cmake .. -DEIGEN_INCLUDE_DIR:STRING="EigenIncludePath" && make
5969
\endverbatim
6070
*
6171
* <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.
@@ -102,7 +112,7 @@ msbuild opengv.sln /p:Configuration=Release
102112
*
103113
* 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.
104114
*
105-
* <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.
115+
* <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".
106116
* </ul>
107117
*
108118
* \section sec_installation_35 Installation under OSX
@@ -117,7 +127,17 @@ msbuild opengv.sln /p:Configuration=Release
117127
*
118128
* \section sec_installation_36 Installing OpenGV on the host OS
119129
*
120-
* 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.
130+
* Installation on the host OS (including the headers) can be activated by simply launching the install target.
131+
* 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.
132+
* 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.
133+
\verbatim
134+
cmake ../opengv
135+
-DEIGEN_INCLUDE_DIR="EigenIncludePath"
136+
-DBUILD_TESTS=ON
137+
-DCMAKE_INSTALL_PREFIX="YourInstallPath"
138+
make
139+
make install #sudo not required since we use a local installation
140+
\endverbatim
121141
*
122142
* \section sec_installation_4 Installing the Matlab-wrapper (Windows-version)
123143
*
@@ -139,7 +159,7 @@ http://jimdavid.blogspot.com.au/2012/12/matlab-2012b-mex-setup-with-vs2012.html
139159
* <li>Once this is done, you can compile the mex-file by going to the opengv/matlab folder and typing in the console
140160
*
141161
\verbatim
142-
mex -I../include -I../third_party -I../third_party/eigen3 -L../build/lib/Release -lopengv opengv.cpp
162+
mex -I../include -I../EigenIncludePath -L../build/lib/Release -lopengv opengv.cpp
143163
\endverbatim
144164
*
145165
* <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
@@ -170,7 +190,7 @@ export LD_LIBRARY_PATH=<path to OpenGV>/build/lib:$LD_LIBRARY_PATH
170190
* <li>Go to the opengv/matlab-folder inside Matlab, and issue the command
171191
*
172192
\verbatim
173-
mex -I../include -I../third_party -I../third_party/eigen3 -L../build/lib -lopengv opengv.cpp -cxx
193+
mex -I../include -I../EigenIncludePath -L../build/lib -lopengv opengv.cpp -cxx
174194
\endverbatim
175195
*
176196
* Note the lib directory does not contain a Release subfolder under linux, and that the -cxx option has to be added.
@@ -184,4 +204,22 @@ mex -I../include -I../third_party -I../third_party/eigen3 -L../build/lib -lopeng
184204
*
185205
* 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.
186206
*
207+
* \section sec_installation_8 Using the OpenGV inside your cmake c++ project
208+
*
209+
* Once your have a system or local install of opengv you can use it in your own project.
210+
* In your cmake file, add the search for the opengv library:
211+
\verbatim
212+
find_package(opengv REQUIRED)
213+
if (opengv_FOUND)
214+
add_executable(main_opengv_demo main.cpp)
215+
target_link_libraries(main_opengv_demo opengv)
216+
endif (opengv_FOUND)
217+
\endverbatim
218+
*
219+
* 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:
220+
\verbatim
221+
cmake ../myproject
222+
-DCMAKE_BUILD_TYPE=RELEASE
223+
-Dopengv_DIR:STRING=/home/Foo/Documents/Dev/opengv_Build/install/CMake/
224+
\endverbatim
187225
*/

python/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ include_directories(${PYTHON_INCLUDE_DIRS})
99
find_package(NumPy REQUIRED)
1010
include_directories(${NUMPY_INCLUDE_DIRS})
1111

12-
1312
add_library( pyopengv SHARED pyopengv.cpp )
1413
target_link_libraries(pyopengv opengv)
1514

16-
1715
set_target_properties(pyopengv PROPERTIES
1816
PREFIX ""
1917
SUFFIX ".so"

0 commit comments

Comments
 (0)