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: Handle generated files in core_add_test correctly #9692
Conversation
# otherwise use the absolute path. We can't just prepend | ||
# CMAKE_CURRENT_SOURCE_DIR as this source file might be genertaed | ||
# in the build directory (in which case it would have been passed | ||
# to SOURCES as an absolute path). |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
A source file might have an absolute path if it was being generated and stored in the binary directory.
@wsnipex Let me know if there's additional things that need to be addressed here. |
trivial bit; variable should be CORE prefixed (yes i know not entirely consistent). i don't quite get the solution. while some of the contents of these tests are generated, the things we snoop for shouldn't be so we can as well snoop the template files afaik. |
@akva2 I was thinking more of the case where you have a "support" file which is generated. That file might not contain any tests, but is used by the tests. This happens in a PR that I am working on. Something has to be done with the generated file and in this case ignoring it makes the most sense. I gather that there might be templates which contain tests - I suppose the best way to handle that is to add them to the I don't prefer the approach taken by |
the problem is that the regex'ing is the only way to map gtest to ctest. otherwise you just get a single test under ctest. i'm all ears for a better approach but it's the only one i have found. i don't see why we need to bother with generated resources here at all. you just make the test target depend on the resource file and it will be generated before the test is executed. |
@akva2 Ah, that's not really the problem I was referring to. The problem is this:
In this case, the test uses symbols from
However, at that point, |
aha. now i get it. it's an unfortunate assumption on my part, that all sources going into the test executable will hold tests. then this should be fine, but the variable name is slightly confusing. this is not only for generated sources, but test support sources (or whatever name you want to apply, but generated is misleading). note i do understand why them being generated trigger the issue, but thinking a bit wider, that's not the actual issue here is all i'm saying. |
actually looking at the code, what i'm suggesting is to add a second list of sources to be linked into the test application which is not passed to gtest_add_tests, then give core_add_test another parameter for such sources. can you take care of that? i can, but it won't be now for sure, likely in a few days. |
if(NOT ARGN) | ||
message(FATAL_ERROR "Missing ARGN: Read the documentation for GTEST_ADD_TESTS") | ||
endif() | ||
foreach(source ${ARGN}) | ||
get_property(GENERATED SOURCE "${source}" PROPERTY GENERATED) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Generated files don't exist yet, so they can't just be passed to file(READ). Unfortunately, the GENERATED property doesn't help that much here, since it is only visible to lists in the same directory as the relevant source file. Since we call gtest_add_tests at the toplevel CMakeLists.txt, it won't be visible. Generated files which form part of the tests but don't contain any tests themselves should be put into SUPPORT_SOURCES before core_add_test is called. In that case, they won't be considered as part of the library.
this looks much cleaner now. |
Done :)
|
Good stuff thx for patience. |
great, thanks! |
Fixes #16708