Skip to content

Commit

Permalink
✨ Add test specific args to libhal_test_and_make_library
Browse files Browse the repository at this point in the history
Add TEST_PACKAGE & TEST_LINK_LIBRARIES multi value arguments to
libhal_test_and_make_library. This allows library developers to specify
packages and libraries that only belong to unit tests.
  • Loading branch information
Khalil Estell authored and kammce committed Oct 1, 2023
1 parent bcba2c9 commit d30b8d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ This package automatically injects libhal cmake utility functions:
### `libhal_test_and_make_library()`

Builds and tests a library. This function must be used in place of using
libhal_unit_test and libhal_make_library separately.
`libhal_unit_test` and `libhal_make_library` separately.

```cmake
libhal_test_and_make_library([LIBRARY_NAME <library_name>]
Expand All @@ -122,13 +122,17 @@ libhal_test_and_make_library([LIBRARY_NAME <library_name>]
- `PACKAGES` list of packages to automatically find and make available for the
package build.
- `LINK_LIBRARIES` list of the libraries to link into the library.
- `TEST_PACKAGES` list of test packages to automatically find and make available
for the package build.
- `TEST_LINK_LIBRARIES` list of the libraries to link into the unit tests. These
libraries will be added to the library target.

This function requires that Boost.UT unit testing framework to be available
as a package. In conan, add this to your `build_requirements()` method:

```python
def build_requirements(self):
self.tool_requires("libhal-cmake-util/1.1.0")
self.tool_requires("libhal-cmake-util/2.1.0")
self.test_requires("boost-ext-ut/1.1.9")
```

Expand Down
17 changes: 14 additions & 3 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,14 @@ endfunction()
function(libhal_test_and_make_library)
set(options)
set(one_value_args LIBRARY_NAME)
set(multi_value_args SOURCES TEST_SOURCES INCLUDES PACKAGES LINK_LIBRARIES)
set(multi_value_args
SOURCES
TEST_SOURCES
INCLUDES
PACKAGES
LINK_LIBRARIES
TEST_PACKAGES
TEST_LINK_LIBRARIES)
cmake_parse_arguments(BUILD_ARGS
"${options}"
"${one_value_args}"
Expand All @@ -173,8 +180,12 @@ function(libhal_test_and_make_library)
libhal_unit_test(
SOURCES ${BUILD_ARGS_SOURCES} ${BUILD_ARGS_TEST_SOURCES}
INCLUDES ${BUILD_ARGS_INCLUDES}
PACKAGES ${BUILD_ARGS_PACKAGES}
LINK_LIBRARIES ${BUILD_ARGS_LINK_LIBRARIES}
PACKAGES
${BUILD_ARGS_PACKAGES}
${BUILD_ARGS_TEST_PACKAGES}
LINK_LIBRARIES
${BUILD_ARGS_LINK_LIBRARIES}
${BUILD_ARGS_TEST_LINK_LIBRARIES}
)
endif()

Expand Down

0 comments on commit d30b8d1

Please sign in to comment.