Closed EmbedEngineer closed 2 years ago
cc @ARMmbed/mbed-os-test (or who could help with unittests?)
Quote from cmake.org:
AFAIK, CMAKE_CXX_FLAGS et al. are special in as much as the last value they receive within a CMakeLists.txt file is effective for all targets defined in that file, i.e. they undergo a kind of lazy evaluation. So, the answer to your question is: No, you can't specify CMAKE_CXX_FLAGS individually for targets within the same CMakeLists.txt, but you can specify them per directory, i.e. individually in each CMakeLists.txt. Nevertheless, CMAKE_CXX_FLAGS should be considered as project-wide settings, IMO.
So as I see it the whole "set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ...") is just wrong and should be replaced by target_compile_definitions()
in all unittest cmake files.
After trying to fix that, I figured out that you are relying on that, since some unittests are expecting that all defines from empty_baseline test are present. Well that is in my opinion just a misuse of the CMAKE_CXX_FLAGS and CMAKE_C_FLAGS. The better solution would be to add is permanently as add_compile_definitions()
Thank you for raising this detailed GitHub issue. I am now notifying our internal issue triagers. Internal Jira reference: https://jira.arm.com/browse/IOTOSM-2434
We closed this issue because it has been inactive for quite some time and we believe it to be low priority. If you think that the priority should be higher, then please reopen with your justification for increasing the priority.
Description of defect
Hi!
I stumbled upon the following problem: When designing my own unittests I figured out that all the defines set in CMAKE_CXX_FLAGS and CMAKE_C_FLAGS are carried on to my unittest cmake file. So after adding
message("${CMAKE_CXX_FLAGS}")
to my cmake file the following output was generated:This happens altough my cmake file looks like:
So there should not be the other defines in the list apart from
--coverage -DUNITTEST
. Trying to delete them also doesn't work. Since I am using the MbedCRC in that specific test the addition of "-DDEVICE_CRC " is breaking the test build. So in my opinion this shouldn't happen.Target(s) affected by this defect ?
unittests
Toolchain(s) (name and version) displaying this defect ?
make: GNU Make 4.2.1 cmake: 3.13.4
What version of Mbed-os are you using (tag or sha) ?
mbed-os-5.15.1
What version(s) of tools are you using. List all that apply (E.g. mbed-cli)
mbed cli: 1.10.2
How is this defect reproduced ?
add
message("${CMAKE_CXX_FLAGS}")
to any other cmake file or try to to run unittests with -vv flag