Skip to content

Commit 30c2c9f

Browse files
committed
Improve CMake strucutre
Now the library can be easily installed and used in other projects.
1 parent ad5d9cf commit 30c2c9f

File tree

15 files changed

+753
-49993
lines changed

15 files changed

+753
-49993
lines changed

CMakeLists.txt

Lines changed: 113 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,127 @@
11
cmake_minimum_required (VERSION 2.6)
22
project (FMM)
33

4-
# Set a default build type for single-configuration
4+
# set a default build type for single-configuration
55
# CMake generators if no build type is set.
6-
IF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
7-
SET(CMAKE_BUILD_TYPE Release)
8-
ENDIF(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
6+
if(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
7+
set(CMAKE_BUILD_TYPE Release)
8+
endif(NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
9+
10+
set(BUILD_EXAMPLES true CACHE STRING "True (default) to build examples")
11+
if(BUILD_EXAMPLES)
12+
message(STATUS "Examples are being built (NOT installed).")
13+
endif(BUILD_EXAMPLES)
914

1015
# Select flags.
11-
SET(CMAKE_CXX_FLAGS "-std=c++11")
12-
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
13-
SET(CMAKE_CXX_FLAGS_RELEASE "-Ofast -fno-finite-math-only")
14-
SET(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wno-unused-local-typedefs -g")
16+
set(CMAKE_CXX_FLAGS "-std=c++11")
17+
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g")
18+
set(CMAKE_CXX_FLAGS_RELEASE "-Ofast -fno-finite-math-only")
19+
set(CMAKE_CXX_FLAGS_DEBUG "-Wall -Wno-unused-local-typedefs -g")
20+
21+
# Finding Boost
22+
find_package(Boost REQUIRED COMPONENTS system filesystem program_options)
23+
if(Boost_FOUND)
24+
include_directories(${Boost_INCLUDE_DIRS})
25+
else()
26+
message(FATAL_ERROR "Boost NOT FOUND. Please install it following the instructions on the README file.")
27+
endif()
28+
29+
# Finding CImg
30+
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
31+
find_package(CImg)
32+
if(CImg_FOUND)
33+
include_directories(${CIMG_INCLUDE_DIRS})
34+
else()
35+
message(FATAL_ERROR "CImg NOT FOUND. Please install it following the instructions on the README file.")
36+
endif()
1537

1638
# Self-made includes
17-
include_directories (${FMM_SOURCE_DIR}/console)
18-
include_directories (${FMM_SOURCE_DIR}/ndgridmap)
19-
include_directories (${FMM_SOURCE_DIR}/fmm)
20-
include_directories (${FMM_SOURCE_DIR}/fmm/fmdata)
21-
include_directories (${FMM_SOURCE_DIR}/fm2)
22-
include_directories (${FMM_SOURCE_DIR}/io)
23-
include_directories (${FMM_SOURCE_DIR}/gradientdescent)
39+
include_directories (
40+
${Boost_INCLUDE_DIRS}
41+
${CImg_INCLUDE_DIRS}
42+
console
43+
ndgridmap
44+
fmm
45+
fmm/fmdata
46+
fm2
47+
io
48+
gradientdescent
49+
thirdparty
50+
)
51+
52+
# Create main library
53+
add_library(fastmarching SHARED
54+
console/console.cpp
55+
ndgridmap/cell.cpp
56+
fmm/fmdata/fmcell.cpp
57+
)
58+
59+
# Linking
60+
target_link_libraries(fastmarching
61+
${Boost_LIBRARIES}
62+
${CImg_SYSTEM_LIBS}
63+
)
64+
65+
# Add benchmarking capabilities
66+
add_executable (fmmbenchmark benchmark/fmm_benchmark.cpp)
67+
68+
target_link_libraries (fmmbenchmark fastmarching)
69+
70+
# Create main example
71+
if(BUILD_EXAMPLES)
72+
add_executable(fmm main.cpp)
73+
target_link_libraries(fmm fastmarching)
74+
add_subdirectory(examples)
75+
endif(BUILD_EXAMPLES)
76+
77+
# Install section
78+
# We are not using CMakePackageConfigHelpers because CIMG variables are lists
79+
# and those functions do not manage them properly.
80+
configure_file(
81+
cmake/FMConfig.cmake.in
82+
${CMAKE_BINARY_DIR}/FMConfig.cmake
83+
)
84+
85+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FMConfig.cmake
86+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/FM
87+
)
88+
89+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FMConfig.cmake
90+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/FM
91+
)
92+
93+
install(TARGETS fastmarching
94+
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
95+
)
96+
97+
install(TARGETS fmmbenchmark
98+
DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
99+
)
24100

101+
install(DIRECTORY scripts DESTINATION ${CMAKE_INSTALL_PREFIX}/share/FM)
25102

26-
# Third party internal includes
27-
include_directories (${FMM_SOURCE_DIR}/thirdparty)
103+
install(DIRECTORY benchmark/cfg DESTINATION ${CMAKE_INSTALL_PREFIX}/share/FM)
28104

105+
install(DIRECTORY ${CMAKE_SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_PREFIX}/include
106+
FILES_MATCHING
107+
PATTERN "*.hpp"
108+
PATTERN "*.h"
109+
REGEX "/build$" EXCLUDE
110+
REGEX ".git$" EXCLUDE
111+
REGEX "/examples$" EXCLUDE
112+
REGEX "/doc$" EXCLUDE
113+
REGEX "/data$" EXCLUDE
114+
REGEX "/cfg$" EXCLUDE
115+
REGEX "/cmake$" EXCLUDE
116+
REGEX "/scripts$" EXCLUDE
117+
)
29118

30-
# External dependencies
31-
include_directories (~/boost_1_55_0)
32119

33-
add_executable (fmm main.cpp
34-
console/console.cpp
35-
ndgridmap/cell.cpp
36-
fmm/fmdata/fmcell.cpp
37-
)
120+
# Uninstall target
121+
configure_file(
122+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
123+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
124+
IMMEDIATE @ONLY)
38125

39-
# Linking CImg dependencies.
40-
target_link_libraries (fmm X11 pthread )
126+
add_custom_target(uninstall
127+
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)

README.md

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
N-Dimensional Fast Marching Method V1.0
22

33
**Authors:**
4-
- [Javier V. Gomez](http://jvgomez.github.io) javvgomez _at_ gmail.com
4+
- [Javier V. Gomez](http://jvgomez.github.io) javvgomez _at_ gmail.com
55
- Jose Pardeiro jose.pardeiro _at_ gmail.com
66
- Pablo Gely
77

@@ -62,30 +62,26 @@ Go into the HTML folder and open index.html
6262

6363
This code uses C\++11 so a compiler g++ 4.8 or equivalent is required. With GCC 4.7 some runtime problems can occur.
6464

65-
### Linking CImg dependencies.
66-
If you want to compile code that uses the CImg library, you will need to add the following line to the CMakeLists.txt
65+
Additional dependencies: Boost, imagemafick and CImg.
6766

68-
target_link_libraries (fmm X11 pthread)
69-
70-
The code provides a copy of the CImg library. This will take care of loading and savig images. Depending on the extension used, you will need to install another libraries as said in the main page of CImg: http://cimg.sourceforge.net/
71-
72-
The example code uses png, therefore examples of libraries to be installed are libpng, Magick++, ImageMagick, etc.
73-
74-
### Boost dependencies
75-
When using Ubuntu, you should install Boost libraries (tested with 1.55+):
76-
77-
sudo apt-get install libboost-all-dev
67+
$ sudo apt-get install imagemagick libboost-all-dev cimg-dev
7868

7969
## Building the code
8070
To build the code:
8171

8272
$ cd build
8373
$ cmake .. -DCMAKE_BUILD_TYPE=Release (Release, RelWithDebInf or Debug, Release by default)
84-
$ make
74+
$ make -j8 (or the number of cores you want to use during compilation)
75+
$ sudo make install (only if you want to install the library)
8576
$ ./fmm -map1 ../data/testimg.png -map2 ../data/map.png -vel ../data/velocities.png
8677

8778
This main shows most of the utilities implemented so far.
8879

80+
To uninstall:
81+
82+
$ sudo make uninstall
83+
84+
8985
## Folder structure
9086

9187
Although there are a lot of folders, they are quite simple. It is organized this way because I'm focusing on an upload to Biicode (www.biicode.com)
@@ -105,34 +101,50 @@ Although there are a lot of folders, they are quite simple. It is organized this
105101
+ scripts: matlab scripts to parse outputs and automatic benchmarking bash script.
106102
+ thirdparty: others' software included.
107103

104+
### Installation
105+
Default installation folder is` /usr/local` for Linux distributions (or equivalent on other OS). Libraries are installed in subfolder `lib`, together with CMake modules. All the includes are installed under `include` subfolder. Additionally, in the `share` subfolder the helper scripts and some samples of benchmark configurations files are installed. Finally, the benchmark binary is installed in `bin`.
106+
107+
In order to change the default installation folder you can do:
108+
109+
$ cmake ../.. -DCMAKE_INSTALL_PREFIX=<your folder>
110+
111+
112+
In this case, you will have to adapt your environment variables so that the libraries and CMake modules are found.
113+
114+
108115
## KNOWN ISSUES
109116

110117
- Gradient Descent for FM2* could fail if very narrow passages are in the way of the path.
111118
- It seems that UFMM can fail in maps with random (or similar) velocity changes.
112119

113120
## TODO
114121

115-
At the top of each file there are specific TODO comments. Here are some others:
122+
At the top of each file there are specific TODO comments. Here are some others.
116123

117-
- Mix SFMM and UFMM (researchy TODO).
124+
### Code TODOs
125+
- Remove relative file dependencies (#include "../../fmm", filename = "../../data", CMakeLists.txt deps, etc).
118126
- MapLoader, GridWriter... get a naming convention. MapReader or GridSaver for instance.
119-
- Improve untidy queue implementation with hash maps (specially remove element in increase_priority()).
120-
- Upload as a unique biicode block.
121127
- printRunInfo implementation missing for most of the solvers.
122128
- Unify GridWriter and GridPlotter functions parameter order: (grid, name)
123-
- Review and update nDGridMap.pdf
124129
- Fix Doxygen warnings.
125130
- Convert all scripts to python (or similar) so that they keep completely open source.
126-
- Improve the way FM2 and its versions deal with the grid when running multiple times on the same grid. Concretely, avoid recomputation of velocities map.
127131
- Reimplement FM2Dir from scratch. Currently in data/alpha folder.
128-
- Restructure the folder and the CMake files in order to properly have examples and that stuff.
129132
- Substitute arg parsing with boost_options.
130-
- Remove relative file dependencies (#include "../../fmm", filename = "../../data", CMakeLists.txt deps, etc).
131133
- Implement a grid copy constructor and assignment operator, etc.
132134
- Most of the unsigned int should be replaced by size_t to be type-correct.
133135
- Use smart pointers (specially for grid).
134136
- Create a testing framework.
135137
- BenchmarkCFG::configure, parse ctorParams_ with a variadic templated function, something like:` parseParams<int, bool>(param1, param2)`, `parseParams<string,double,bool>(p1,p2,p3)`.
136-
- For most methods, neighbors for same cell are computed many times. Store them like FMT to save some computation time.
137138
- GridPlotter code can be refactorized so that the same code is not repeated many times.
138139
- Review template template parameters, perhaps it can be simplified (specially for benchmark): `template <grid_t>` to `template <nDGridMap <cell_t, ndims>>` so we can use cell_t without doing `template <grid_t, cell_t>` (redundant).
140+
- Unify names: one thing is Fast Methods, other Fast Marching, etc.
141+
142+
### Algorithmic TODOs
143+
- Improve untidy queue implementation with hash maps (specially remove element in increase_priority()).
144+
- Mix SFMM and UFMM (researchy TODO).
145+
- Improve the way FM2 and its versions deal with the grid when running multiple times on the same grid. Concretely, avoid recomputation of velocities map.
146+
- For most methods, neighbors for same cell are computed many times. Store them like FMT to save some computation time.
147+
148+
### Documentation TODOs
149+
- Review and update nDGridMap.pdf
150+
- Link thesis and papers.

benchmark/CMakeLists.txt

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

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#### v0.7 (trunk) ChangeLog
22
- Benchmarking can save only a grid per solver or grid for all runs with option savegrid=1 or `savegrid=2`
33
- Benchmarking CFG files now accept .grid textfiles under the option `text=<path_to_text_grid>`
4+
- Added install and uninstall CMake targets.
45

56
#### v0.6 ChangeLog
67
- solveEikonal made more stable, but a bit less efficient.

cmake/FMConfig.cmake.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set(FM_FOUND 1)
2+
3+
set(FM_INCLUDE_DIRS
4+
@Boost_INCLUDE_DIRS@
5+
@CImg_INCLUDE_DIRS@
6+
@CMAKE_INSTALL_PREFIX@/include
7+
)
8+
9+
set(FM_LIBRARIES
10+
@CMAKE_INSTALL_PREFIX@/lib/${CMAKE_SHARED_LIBRARY_PREFIX}fastmarching${CMAKE_SHARED_LIBRARY_SUFFIX}
11+
@CImg_SYSTEM_LIBS@
12+
@Boost_LIBRARIES@
13+
)

0 commit comments

Comments
 (0)