Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake] encapsulate target and dependencies #226

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,6 @@ include(CTest)
include(FetchContent)
include(GNUInstallDirs)

FetchContent_Declare(
eigen
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen.git"
FIND_PACKAGE_ARGS NAMES Eigen3)

FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
FIND_PACKAGE_ARGS NAMES FMT)

FetchContent_Declare(
google_benchmark
GIT_REPOSITORY "https://github.com/google/benchmark.git"
GIT_TAG "main"
FIND_PACKAGE_ARGS NAMES benchmark)

FetchContent_Declare(
google_test
GIT_REPOSITORY "https://github.com/google/googletest.git"
GIT_TAG "main"
FIND_PACKAGE_ARGS NAMES GTest)

FetchContent_MakeAvailable(fmt google_test google_benchmark eigen)

add_subdirectory(benchmark)
add_subdirectory(include)
add_subdirectory(sample)
Expand Down
4 changes: 2 additions & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ cmake --build "build" --parallel
sudo cmake --install "build"
```

# Build & Run
# Development Build & Run

## Tests & Samples

Build and run the tests and samples on all platforms:
Build and run the tests and samples:

```shell
git clone --depth 1 "https://github.com/FrancoisCarouge/Kalman.git" "kalman"
Expand Down
73 changes: 57 additions & 16 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,30 +38,71 @@ For more information, please refer to <https://unlicense.org> ]]

set(PROCESSOR_AFFINITY TRUE)

set(SOURCES "baseline.cpp" "predict_1x1x0.cpp" "predict_1x1x1.cpp"
"update_1x1x0.cpp" "update_1x1x1.cpp")
FetchContent_Declare(
google_benchmark
GIT_REPOSITORY "https://github.com/google/benchmark.git"
GIT_TAG "main"
FIND_PACKAGE_ARGS NAMES benchmark)

FetchContent_Declare(
google_test
GIT_REPOSITORY "https://github.com/google/googletest.git"
GIT_TAG "main"
FIND_PACKAGE_ARGS NAMES GTest)

FetchContent_MakeAvailable(google_test google_benchmark)

foreach(BENCHMARK "baseline.cpp" "predict_1x1x0.cpp" "predict_1x1x1.cpp"
"update_1x1x0.cpp" "update_1x1x1.cpp")
get_filename_component(NAME ${BENCHMARK} NAME_WE)
add_executable(kalman_benchmark_${NAME}_driver ${BENCHMARK})
target_include_directories(kalman_benchmark_${NAME}_driver PRIVATE "."
"include")
target_link_libraries(
kalman_benchmark_${NAME}_driver PRIVATE benchmark::benchmark
benchmark::benchmark_main kalman)
add_test(kalman_benchmark_${NAME} kalman_benchmark_${NAME}_driver
"--benchmark_out=${NAME}.json")
endforeach()

FetchContent_Declare(
eigen
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen.git"
FIND_PACKAGE_ARGS NAMES Eigen3)

FetchContent_MakeAvailable(eigen)

foreach(STATE_SIZE RANGE 1 2)
foreach(OUTPUT_SIZE RANGE 1 2)
configure_file(eigen_update_xx0.cpp
eigen_update_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp)
list(APPEND SOURCES eigen_update_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp)
get_filename_component(NAME eigen_update_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp
NAME_WE)
add_executable(kalman_benchmark_${NAME}_driver
eigen_update_${STATE_SIZE}x${OUTPUT_SIZE}x0.cpp)
target_include_directories(kalman_benchmark_${NAME}_driver
PRIVATE "." "include")
target_link_libraries(
kalman_benchmark_${NAME}_driver
PRIVATE benchmark::benchmark benchmark::benchmark_main Eigen3::Eigen
kalman)
add_test(kalman_benchmark_${NAME} kalman_benchmark_${NAME}_driver
"--benchmark_out=${NAME}.json")
endforeach()
foreach(INPUT_SIZE RANGE 1 2)
configure_file(eigen_predict_x1x.cpp
eigen_predict_${STATE_SIZE}x1x${INPUT_SIZE}.cpp)
list(APPEND SOURCES eigen_predict_${STATE_SIZE}x1x${INPUT_SIZE}.cpp)
get_filename_component(NAME eigen_predict_${STATE_SIZE}x1x${INPUT_SIZE}.cpp
NAME_WE)
add_executable(kalman_benchmark_${NAME}_driver
eigen_predict_${STATE_SIZE}x1x${INPUT_SIZE}.cpp)
target_include_directories(kalman_benchmark_${NAME}_driver
PRIVATE "." "include")
target_link_libraries(
kalman_benchmark_${NAME}_driver
PRIVATE benchmark::benchmark benchmark::benchmark_main Eigen3::Eigen
kalman)
add_test(kalman_benchmark_${NAME} kalman_benchmark_${NAME}_driver
"--benchmark_out=${NAME}.json")
endforeach()
endforeach()

foreach(BENCHMARK ${SOURCES})
get_filename_component(NAME ${BENCHMARK} NAME_WE)
add_executable(kalman_benchmark_${NAME}_driver ${BENCHMARK})
target_include_directories(kalman_benchmark_${NAME}_driver PRIVATE "."
"include")
target_link_libraries(
kalman_benchmark_${NAME}_driver
PRIVATE benchmark::benchmark benchmark::benchmark_main Eigen3::Eigen kalman)
add_test(kalman_benchmark_${NAME} kalman_benchmark_${NAME}_driver
"--benchmark_out=${NAME}.json")
endforeach()
32 changes: 20 additions & 12 deletions sample/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,27 @@ OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org> ]]

set(SOURCES
"ekf_4x1x0_soaring.cpp"
"kf_1x1x0_building_height.cpp"
"kf_1x1x0_liquid_temperature.cpp"
"kf_1x1x1_dog_position.cpp"
"kf_2x1x1_rocket_altitude.cpp"
"kf_6x2x0_vehicle_location.cpp"
"kf_8x4x0_deep_sort_bounding_box.cpp")

foreach(SAMPLE ${SOURCES})
foreach(SAMPLE "kf_1x1x0_building_height.cpp" "kf_1x1x0_liquid_temperature.cpp"
"kf_1x1x1_dog_position.cpp")
get_filename_component(NAME ${SAMPLE} NAME_WE)
add_executable(kalman_sample_${NAME}_driver ${SAMPLE})
target_link_libraries(kalman_sample_${NAME}_driver PRIVATE Eigen3::Eigen
kalman main)
target_link_libraries(kalman_sample_${NAME}_driver PRIVATE kalman main)
add_test(kalman_sample_${NAME} kalman_sample_${NAME}_driver)
endforeach()

FetchContent_Declare(
eigen
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen.git"
FIND_PACKAGE_ARGS NAMES Eigen3)

FetchContent_MakeAvailable(eigen)

foreach(SAMPLE_EIGEN
"ekf_4x1x0_soaring.cpp" "kf_2x1x1_rocket_altitude.cpp"
"kf_6x2x0_vehicle_location.cpp" "kf_8x4x0_deep_sort_bounding_box.cpp")
get_filename_component(NAME ${SAMPLE_EIGEN} NAME_WE)
add_executable(kalman_sample_eigen_${NAME}_driver ${SAMPLE_EIGEN})
target_link_libraries(kalman_sample_eigen_${NAME}_driver PRIVATE Eigen3::Eigen
kalman main)
add_test(kalman_sample_eigen_${NAME} kalman_sample_eigen_${NAME}_driver)
endforeach()
20 changes: 17 additions & 3 deletions support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org> ]]

add_library(format INTERFACE)
target_include_directories(format INTERFACE ".")
target_link_libraries(format INTERFACE fmt::fmt)
if(WIN32)
# Microsoft Windows MSVC CL toolchain supports C++'s standard format library.
# Other compilers don't support it yet. TODO: This platform check is not ideal
# and should be replaced with a check for the compiler library support.
else()
FetchContent_Declare(
fmt
GIT_REPOSITORY "https://github.com/fmtlib/fmt.git"
FIND_PACKAGE_ARGS NAMES FMT)

FetchContent_MakeAvailable(fmt)

add_library(format INTERFACE)
target_sources(format INTERFACE FILE_SET "format_headers" TYPE "HEADERS"
FILES "format")
target_link_libraries(format INTERFACE fmt::fmt)
endif()
29 changes: 17 additions & 12 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,24 @@ OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org> ]]

set(SOURCES
"eigen_f.cpp"
"eigen_h.cpp"
"eigen_initialization.cpp"
"f.cpp"
"format.cpp"
"h.cpp"
"initialization.cpp")

foreach(TEST ${SOURCES})
foreach(TEST "f.cpp" "format.cpp" "h.cpp" "initialization.cpp")
get_filename_component(NAME ${TEST} NAME_WE)
add_executable(kalman_test_${NAME}_driver ${TEST})
target_link_libraries(kalman_test_${NAME}_driver PRIVATE Eigen3::Eigen kalman
main)
target_link_libraries(kalman_test_${NAME}_driver PRIVATE kalman main)
add_test(kalman_test_${NAME} kalman_test_${NAME}_driver)
endforeach()

FetchContent_Declare(
eigen
GIT_REPOSITORY "https://gitlab.com/libeigen/eigen.git"
FIND_PACKAGE_ARGS NAMES Eigen3)

FetchContent_MakeAvailable(eigen)

foreach(TEST_EIGEN "eigen_f.cpp" "eigen_h.cpp" "eigen_initialization.cpp")
get_filename_component(NAME ${TEST_EIGEN} NAME_WE)
add_executable(kalman_test_eigen_${NAME}_driver ${TEST_EIGEN})
target_link_libraries(kalman_test_eigen_${NAME}_driver PRIVATE Eigen3::Eigen
kalman main)
add_test(kalman_test_eigen_${NAME} kalman_test_eigen_${NAME}_driver)
endforeach()