-
Notifications
You must be signed in to change notification settings - Fork 21
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
Make header_only_library()
function
#262
Conversation
Au is overwhelmingly built from header-only libraries. We can make this a lot easier to maintain with a CMake function, `header_only_library()`, that presents an Au-centric interface. Specifically, the function will automatically: - Make the target an `INTERFACE` - Set `FILE_SET HEADERS` - Set `BASE_DIRS` to the base Au directory Users must provide the `HEADERS` option, and we will use those to set the `FILES` option. Users can optionall provide the `DEPS` option, and we'll use it if present to populate a `target_link_libraries` call. We also add an optional `GTEST_SRCS` argument. If this is provided, then we will automatically create a `_test`-suffixed target, link to the library and to `gtest_main`, and run `gtest_discover_tests()`. If the test has any dependencies apart from the tested target, and GTest, they can be supplied via an optional `GTEST_EXTRA_DEPS` argument. Finally, we provide the option to mark a library as `INTERNAL_ONLY`. For now, we borrow the `EXPORT_NAME` manipulation from the original CMake branch, but we could choose to do other things later --- the important part is marking the intent that the library is internal-only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes make sense. Test still passes.
docker run --rm \
ubuntu@sha256:2e863c44b718727c860746568e1d54afd13b2fa71b160f5cd9058fc436217b30 \
/bin/bash -c \
'apt update && apt install -y clang cmake git && git clone -b chiphogg/cmake-header-only-library#215 https://github.com/aurora-opensource/au.git && cd au && cmake -S . -B cmake/build -DCMAKE_VERIFY_INTERFACE_HEADER_SETS=TRUE && cmake --build cmake/build --target all all_verify_interface_header_sets test'
${ARG_NAME} | ||
${ARG_GTEST_EXTRA_DEPS} | ||
GTest::gtest_main | ||
GTest::gmock_main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both main targets would have two main
functions. You should only need GTest::gmock_main
.
gmock_main
has main and depends on gmock. gmock depends on gtest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! Now I'm a little curious why it actually worked before (or at least, appeared to), with two main
functions.
`gmock_main` already provides it.
Au is overwhelmingly built from header-only libraries. We can make this
a lot easier to maintain with a CMake function,
header_only_library()
,that presents an Au-centric interface. Specifically, the function will
automatically:
INTERFACE
FILE_SET HEADERS
BASE_DIRS
to the base Au directoryUsers must provide the
HEADERS
option, and we will use those to setthe
FILES
option. Users can optionall provide theDEPS
option, andwe'll use it if present to populate a
target_link_libraries
call.We also add an optional
GTEST_SRCS
argument. If this is provided,then we will automatically create a
_test
-suffixed target, link to thelibrary and to
gtest_main
, and rungtest_discover_tests()
. If thetest has any dependencies apart from the tested target, and GTest, they
can be supplied via an optional
GTEST_EXTRA_DEPS
argument.Finally, we provide the option to mark a library as
INTERNAL_ONLY
. Fornow, we borrow the
EXPORT_NAME
manipulation from the original CMakebranch, but we could choose to do other things later --- the important
part is marking the intent that the library is internal-only.
Helps #215.