aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Freilich <sfreilich@google.com>2022-03-07 12:50:49 -0800
committerCopybara-Service <copybara-worker@google.com>2022-03-07 12:51:17 -0800
commit0b0d57895bbe4afaf1d77d0a22a599bb8012444b (patch)
tree2d8b68a37f7c0cfb2727937b943771daa1df6a0b
parentbf6f33f34f7063ae8ccc1e1f798d3ecf14286f0a (diff)
downloadink-stroke-modeler-0b0d57895bbe4afaf1d77d0a22a599bb8012444b.tar.gz
Fix CMake build structure and add usage docs
Focus on consumers using submodules + add_subdirectory, pruning logic related to local installation for now. Targets are now namespaced properly in `InkStrokeModeler::`. Adds usage documentation for consuming the library from Bazel and CMake projects. PiperOrigin-RevId: 433015667
-rw-r--r--BUILD1
-rw-r--r--CMakeLists.txt10
-rw-r--r--README.md93
-rw-r--r--cmake/InkBazelEquivalents.cmake21
-rw-r--r--ink_stroke_modeler/CMakeLists.txt34
-rw-r--r--ink_stroke_modeler/internal/CMakeLists.txt60
-rw-r--r--ink_stroke_modeler/internal/prediction/CMakeLists.txt46
-rw-r--r--ink_stroke_modeler/internal/prediction/kalman_filter/CMakeLists.txt6
8 files changed, 176 insertions, 95 deletions
diff --git a/BUILD b/BUILD
index f8433a5..cefdd4d 100644
--- a/BUILD
+++ b/BUILD
@@ -24,4 +24,5 @@ alias(
name = "gtest_for_library_testonly",
testonly = 1,
actual = "@com_google_googletest//:gtest",
+ visibility = ["//:__subpackages__"],
)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6d6fac5..99e79a5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -41,9 +41,6 @@ FetchContent_Declare(
GIT_PROGRESS TRUE
)
set(ABSL_PROPAGATE_CXX_STD ON)
-if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
- set(ABSL_ENABLE_INSTALL ON)
-endif()
# No reason to get two different versions of Googletest.
set(ABSL_USE_EXTERNAL_GOOGLETEST ON)
FetchContent_MakeAvailable(abseil-cpp)
@@ -62,10 +59,3 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
add_subdirectory(ink_stroke_modeler)
-
-if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
- install(EXPORT ${PROJECT_NAME}Targets
- NAMESPACE InkStrokeModeler::
- DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
- )
-endif()
diff --git a/README.md b/README.md
index a600f86..c7ab9ca 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,99 @@ This library is designed to have minimal dependencies; the library itself relies
only on the C++ Standard Library and [Abseil](https://abseil.io/), and the tests
use the [GoogleTest](https://google.github.io/googletest/) framework.
+## Build System
+
+### Bazel
+
+Ink Stroke Modeler can be built and the tests run from the GitHub repo root
+with:
+
+```shell
+bazel test ...
+```
+
+To use Ink Stroke Modeler in another Bazel project, put the following in the
+`WORKSPACE` file to download the code from GitHub head and set up dependencies:
+
+```bazel
+load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
+
+git_repository(
+ name = "ink_stroke_modeler",
+ remote = "https://github.com/google/ink-stroke-modeler.git",
+ branch = "main",
+)
+load("@ink_stroke_modeler//:workspace.bzl", "ink_stroke_modeler_workspace")
+ink_stroke_modeler_workspace()
+```
+
+If you want to depend on a specific version, you can change the options passed
+to [`git_repository`](https://bazel.build/rules/lib/repo/git#git_repository). Or
+if you want to use a local checkout of Ink Stroke Modeler instead, use the
+[`local_repository`](https://bazel.build/reference/be/workspace#local_repository)
+workspace rule instead of `git_repository`.
+
+Since Ink Stroke Modler requires C++17, it must be built with
+`--cxxopt='-std=c++17'` (or similar indicating a newer version). You can put the
+following in your project's `.bazelrc` to use this by default:
+
+```none
+build --cxxopt='-std=c++17'
+```
+
+Then you can include the following in your targets' `deps`:
+
+* `@ink_stroke_modeler//ink_stroke_modeler:stroke_modeler`:
+ [`ink_stroke_modeler/stroke_modeler.h`](ink_stroke_modeler/stroke_modeler.h)
+* `@ink_stroke_modeler//ink_stroke_modeler:types`:
+ [`ink_stroke_modeler/types.h`](ink_stroke_modeler/types.h)
+* `@ink_stroke_modeler//ink_stroke_modeler:params`:
+ [`ink_stroke_modeler/types.h`](ink_stroke_modeler/params.h)
+
+### CMake
+
+Ink Stroke Modeler can be built and the tests run from the GitHub repo root
+with:
+
+```shell
+cmake .
+cmake --build .
+ctest
+```
+
+To use Ink Stroke Modeler in another CMake project, you can add the project as a
+submodule:
+
+```shell
+git submodule add https://github.com/google/ink-stroke-modeler
+```
+
+And then include it in your `CMakeLists.txt`, requiring at least C++17:
+
+```cmake
+set(CMAKE_CXX_STANDARD 17)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+add_subdirectory(ink-stroke-modeler)
+```
+
+Then you can depend on the following with `target_link_libraries`:
+
+* `InkStrokeModeler::stroke_modeler`: `ink_stroke_modeler/stroke_modeler.h`
+* `InkStrokeModeler::types`: `ink_stroke_modeler/types.h`
+* `InkStrokeModeler::params`: `ink_stroke_modeler/types.h`
+
+CMake does not have a mechanism for enforcing target visibility, but consumers
+should depend only on the non-test top-level targets defined in
+`ink_stroke_modeler/CMakeLists.txt`.
+
+The CMake build uses the abstractions defined in
+`cmake/InkBazelEquivalents.cmake` to structure targets in a way that's similar
+to the Bazel BUILD files to make it easier to keep those in sync. The main
+difference is that CMake has a flat structure for target names, e.g.
+`@com_google_absl//absl/types:optional` in Bazel is `absl::optional` in CMake.
+This means that targets need to be given unique names within the entire project
+in CMake.
+
## Usage
The Ink Stroke Modeler API is in the namespace `ink::stroke_model`. The primary
diff --git a/cmake/InkBazelEquivalents.cmake b/cmake/InkBazelEquivalents.cmake
index e1a3d6a..8bdc3fb 100644
--- a/cmake/InkBazelEquivalents.cmake
+++ b/cmake/InkBazelEquivalents.cmake
@@ -14,20 +14,18 @@
function(ink_cc_library)
cmake_parse_arguments(INK_CC_LIB
- "PUBLIC"
+ ""
"NAME"
"HDRS;SRCS;DEPS"
${ARGN}
)
- add_library(${INK_CC_LIB_NAME} ${INK_CC_LIB_SRCS} ${INK_CC_LIB_HDRS})
+ set(_NAME "ink_stroke_modeler_${INK_CC_LIB_NAME}")
+ add_library(${_NAME} ${INK_CC_LIB_SRCS} ${INK_CC_LIB_HDRS})
if(NOT DEFINED INK_CC_LIB_SRCS)
- set_target_properties(${INK_CC_LIB_NAME} PROPERTIES LINKER_LANGUAGE CXX)
- endif()
- target_link_libraries(${INK_CC_LIB_NAME} PUBLIC ${INK_CC_LIB_DEPS})
- if(INK_CC_LIB_PUBLIC)
- install(TARGETS ${INK_CC_LIB_NAME} EXPORT ${PROJECT_NAME}Targets)
+ set_target_properties(${_NAME} PROPERTIES LINKER_LANGUAGE CXX)
endif()
- target_compile_features(${INK_CC_LIB_NAME} PUBLIC cxx_std_17)
+ target_link_libraries(${_NAME} PUBLIC ${INK_CC_LIB_DEPS})
+ add_library(InkStrokeModeler::${INK_CC_LIB_NAME} ALIAS ${_NAME})
endfunction()
function(ink_cc_test)
@@ -37,7 +35,8 @@ function(ink_cc_test)
"SRCS;DEPS"
${ARGN}
)
- add_executable(${INK_CC_TEST_NAME} ${INK_CC_TEST_SRCS})
- target_link_libraries(${INK_CC_TEST_NAME} ${INK_CC_TEST_DEPS})
- add_test(NAME ${INK_CC_TEST_NAME} COMMAND ${INK_CC_TEST_NAME})
+ set(_NAME "ink_stroke_modeler_${INK_CC_TEST_NAME}")
+ add_executable(${_NAME} ${INK_CC_TEST_SRCS})
+ target_link_libraries(${_NAME} ${INK_CC_TEST_DEPS})
+ add_test(NAME ${_NAME} COMMAND ${_NAME})
endfunction()
diff --git a/ink_stroke_modeler/CMakeLists.txt b/ink_stroke_modeler/CMakeLists.txt
index c204cac..b31e9c7 100644
--- a/ink_stroke_modeler/CMakeLists.txt
+++ b/ink_stroke_modeler/CMakeLists.txt
@@ -22,11 +22,10 @@ ink_cc_library(
HDRS
params.h
DEPS
- types
+ InkStrokeModeler::types
absl::status
absl::strings
absl::variant
- PUBLIC
)
ink_cc_test(
@@ -35,7 +34,7 @@ ink_cc_test(
SRCS
params_test.cc
DEPS
- params
+ InkStrokeModeler::params
absl::status
GTest::gmock_main
)
@@ -45,7 +44,6 @@ ink_cc_library(
types
HDRS
types.h
- PUBLIC
)
ink_cc_test(
@@ -54,8 +52,8 @@ ink_cc_test(
SRCS
types_test.cc
DEPS
- types
- type_matchers
+ InkStrokeModeler::types
+ InkStrokeModeler::type_matchers
GTest::gmock_main
)
@@ -67,15 +65,15 @@ ink_cc_library(
HDRS
stroke_modeler.h
DEPS
- params
- types
- internal_types
- position_modeler
- stylus_state_modeler
- wobble_smoother
- input_predictor
- kalman_predictor
- stroke_end_predictor
+ InkStrokeModeler::params
+ InkStrokeModeler::types
+ InkStrokeModeler::internal_types
+ InkStrokeModeler::position_modeler
+ InkStrokeModeler::stylus_state_modeler
+ InkStrokeModeler::wobble_smoother
+ InkStrokeModeler::input_predictor
+ InkStrokeModeler::kalman_predictor
+ InkStrokeModeler::stroke_end_predictor
absl::core_headers
absl::memory
absl::status
@@ -90,9 +88,9 @@ ink_cc_test(
SRCS
stroke_modeler_test.cc
DEPS
- params
- stroke_modeler
- type_matchers
+ InkStrokeModeler::params
+ InkStrokeModeler::stroke_modeler
+ InkStrokeModeler::type_matchers
absl::status
GTest::gmock_main
)
diff --git a/ink_stroke_modeler/internal/CMakeLists.txt b/ink_stroke_modeler/internal/CMakeLists.txt
index 9d78957..b2f04c1 100644
--- a/ink_stroke_modeler/internal/CMakeLists.txt
+++ b/ink_stroke_modeler/internal/CMakeLists.txt
@@ -20,7 +20,7 @@ ink_cc_library(
HDRS
internal_types.h
DEPS
- types
+ InkStrokeModeler::types
)
ink_cc_library(
@@ -31,8 +31,8 @@ ink_cc_library(
HDRS
type_matchers.h
DEPS
- internal_types
- types
+ InkStrokeModeler::internal_types
+ InkStrokeModeler::types
GTest::gmock_main
)
@@ -42,7 +42,7 @@ ink_cc_library(
HDRS
utils.h
DEPS
- types
+ InkStrokeModeler::types
)
ink_cc_test(
@@ -51,8 +51,8 @@ ink_cc_test(
SRCS
utils_test.cc
DEPS
- type_matchers
- utils
+ InkStrokeModeler::type_matchers
+ InkStrokeModeler::utils
GTest::gmock_main
)
@@ -64,9 +64,9 @@ ink_cc_library(
HDRS
wobble_smoother.h
DEPS
- utils
- params
- types
+ InkStrokeModeler::utils
+ InkStrokeModeler::params
+ InkStrokeModeler::types
)
ink_cc_test(
@@ -75,10 +75,10 @@ ink_cc_test(
SRCS
wobble_smoother_test.cc
DEPS
- type_matchers
- wobble_smoother
- params
- types
+ InkStrokeModeler::type_matchers
+ InkStrokeModeler::wobble_smoother
+ InkStrokeModeler::params
+ InkStrokeModeler::types
GTest::gmock_main
)
@@ -88,10 +88,10 @@ ink_cc_library(
HDRS
position_modeler.h
DEPS
- internal_types
- utils
- params
- types
+ InkStrokeModeler::internal_types
+ InkStrokeModeler::utils
+ InkStrokeModeler::params
+ InkStrokeModeler::types
)
ink_cc_test(
@@ -100,11 +100,11 @@ ink_cc_test(
SRCS
position_modeler_test.cc
DEPS
- internal_types
- position_modeler
- type_matchers
- params
- types
+ InkStrokeModeler::internal_types
+ InkStrokeModeler::position_modeler
+ InkStrokeModeler::type_matchers
+ InkStrokeModeler::params
+ InkStrokeModeler::types
GTest::gmock_main
)
@@ -116,9 +116,9 @@ ink_cc_library(
HDRS
stylus_state_modeler.h
DEPS
- internal_types
- utils
- params
+ InkStrokeModeler::internal_types
+ InkStrokeModeler::utils
+ InkStrokeModeler::params
)
ink_cc_test(
@@ -127,10 +127,10 @@ ink_cc_test(
SRCS
stylus_state_modeler_test.cc
DEPS
- internal_types
- stylus_state_modeler
- type_matchers
- params
- types
+ InkStrokeModeler::internal_types
+ InkStrokeModeler::stylus_state_modeler
+ InkStrokeModeler::type_matchers
+ InkStrokeModeler::params
+ InkStrokeModeler::types
GTest::gmock_main
)
diff --git a/ink_stroke_modeler/internal/prediction/CMakeLists.txt b/ink_stroke_modeler/internal/prediction/CMakeLists.txt
index d3fcd76..e54dbbe 100644
--- a/ink_stroke_modeler/internal/prediction/CMakeLists.txt
+++ b/ink_stroke_modeler/internal/prediction/CMakeLists.txt
@@ -20,9 +20,9 @@ ink_cc_library(
HDRS
input_predictor.h
DEPS
- params
- types
- internal_types
+ InkStrokeModeler::params
+ InkStrokeModeler::types
+ InkStrokeModeler::internal_types
)
ink_cc_library(
@@ -33,12 +33,12 @@ ink_cc_library(
HDRS
kalman_predictor.h
DEPS
- input_predictor
- params
- types
- internal_types
- utils
- kalman_filter
+ InkStrokeModeler::input_predictor
+ InkStrokeModeler::params
+ InkStrokeModeler::types
+ InkStrokeModeler::internal_types
+ InkStrokeModeler::utils
+ InkStrokeModeler::kalman_filter
)
ink_cc_test(
@@ -47,11 +47,11 @@ ink_cc_test(
SRCS
kalman_predictor_test.cc
DEPS
- input_predictor
- kalman_predictor
- params
- types
- type_matchers
+ InkStrokeModeler::input_predictor
+ InkStrokeModeler::kalman_predictor
+ InkStrokeModeler::params
+ InkStrokeModeler::types
+ InkStrokeModeler::type_matchers
absl::optional
GTest::gmock_main
)
@@ -64,11 +64,11 @@ ink_cc_library(
HDRS
stroke_end_predictor.h
DEPS
- input_predictor
- params
- types
- internal_types
- position_modeler
+ InkStrokeModeler::input_predictor
+ InkStrokeModeler::params
+ InkStrokeModeler::types
+ InkStrokeModeler::internal_types
+ InkStrokeModeler::position_modeler
absl::optional
)
@@ -78,9 +78,9 @@ ink_cc_test(
SRCS
stroke_end_predictor_test.cc
DEPS
- input_predictor
- stroke_end_predictor
- params
- type_matchers
+ InkStrokeModeler::input_predictor
+ InkStrokeModeler::stroke_end_predictor
+ InkStrokeModeler::params
+ InkStrokeModeler::type_matchers
GTest::gmock_main
)
diff --git a/ink_stroke_modeler/internal/prediction/kalman_filter/CMakeLists.txt b/ink_stroke_modeler/internal/prediction/kalman_filter/CMakeLists.txt
index 2661a10..03bbb47 100644
--- a/ink_stroke_modeler/internal/prediction/kalman_filter/CMakeLists.txt
+++ b/ink_stroke_modeler/internal/prediction/kalman_filter/CMakeLists.txt
@@ -25,7 +25,7 @@ ink_cc_test(
SRCS
matrix_test.cc
DEPS
- matrix
+ InkStrokeModeler::matrix
GTest::gmock_main
)
@@ -39,7 +39,7 @@ ink_cc_library(
axis_predictor.h
kalman_filter.h
DEPS
- matrix
+ InkStrokeModeler::matrix
absl::memory
)
@@ -49,6 +49,6 @@ ink_cc_test(
SRCS
axis_predictor_test.cc
DEPS
- kalman_filter
+ InkStrokeModeler::kalman_filter
GTest::gmock_main
)