File tree Expand file tree Collapse file tree 2 files changed +20
-9
lines changed
Expand file tree Collapse file tree 2 files changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -7,14 +7,11 @@ project(tinyopt-example VERSION 0.0.1
77# Compiler flags
88set (CMAKE_CXX_STANDARD 20)
99
10- # Import Eigen (Mandatory)
11- find_package (Eigen3 REQUIRED NO_MODULE)
12-
1310# Find Tinyopt, fetch it if not found
1411find_package (Tinyopt)
1512
1613if (NOT Tinyopt_FOUND)
17- message ("Tinyopt not found locally, fetching it" )
14+ message ("Tinyopt not found locally, fetching it... " )
1815 include (FetchContent)
1916 FetchContent_Declare(
2017 tinyopt
@@ -29,4 +26,4 @@ endif()
2926
3027# Header-only library
3128add_executable (example src/example.cpp)
32- target_link_libraries (example PUBLIC Eigen3::Eigen tinyopt)
29+ target_link_libraries (example PUBLIC tinyopt)
Original file line number Diff line number Diff line change @@ -7,26 +7,40 @@ Minimal Tinyopt project
77## CMakeLists.txt
88
99``` cmake
10- set(CMAKE_CXX_STANDARD 20)
10+ set(CMAKE_CXX_STANDARD 20) # Minimum is c++17
1111
12- find_package(Eigen3 REQUIRED NO_MODULE)
1312find_package(Tinyopt)
1413
1514add_executable(example src/example.cpp)
16- target_link_libraries(example PUBLIC Eigen3::Eigen tinyopt)
15+ target_link_libraries(example PUBLIC tinyopt)
1716```
1817
18+ ### Alternative using ` git submodule `
19+
20+ The provided CMakeLists.txt is fetching Tinyopt if it's not found locally but you can also
21+ install it using git submodules, e.g.
22+ ``` shell
23+ git submodule add https://github.com/julien-michot/tinyopt.git third_party/tinyopt
24+ git submodule init
25+ git submodule update --init --recursive
26+ ```
27+ and add it to the project:
28+
29+ ``` cmake
30+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/third_party/tinyopt)
31+ ```
1932
2033## Example.cpp
2134
2235Here is an example of usage of 'tinyopt' where we compute the square root of 2.
2336
2437``` cpp
2538#include < tinyopt/tinyopt.h>
39+ using namespace tinyopt ::nlls; // Default Non-Linear Least Square Optimizer
2640
2741int main(int, char ** argv) {
2842 double x = 1;
29- tinyopt:: Optimize(x, [ ] (const auto &x) { return x * x - 2.0; });
43+ Optimize(x, [ ] (const auto &x) { return x * x - 2.0; });
3044 std::cout << "What's √2 already?\n" << x << "\n";
3145 return 0;
3246}
You can’t perform that action at this time.
0 commit comments