Skip to content
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

Double quote prepended when exporting CMAKE compile option using zephyr_get_compile_options_for_lang() #28844

Closed
kurddt opened this issue Oct 1, 2020 · 2 comments

Comments

@kurddt
Copy link
Contributor

kurddt commented Oct 1, 2020

Describe the bug
A extra and unwanted '"' is prepended when using the output of zephyr_get_compile_options_for_lang() to set an other target compile option. This lead to a compilation failure (gcc does not really like this extra double quote)

example:

/usr/bin/arm-none-eabi-gcc -DLZG_SAVED_WINDOWS=1 -O3 -funroll-loops -W -Wall -Wno-extra " -O2 -imacros /home/glager/node/mcu/TN2/bluid/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -imacros /home/glager/node/mcu/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -ffunction-sections -Wformat=0 -Wno-format-security -fno-reorder-functions -fno-defer-pop -fstack-usage -ffunction-sections -fdata-sections -specs=nano.specs -std=c99" -MD -MT liblzg/src/lib/CMakeFiles/lzg.dir/checksum.c.obj -MF liblzg/src/lib/CMakeFiles/lzg.dir/checksum.c.obj.d -o liblzg/src/lib/CMakeFiles/lzg.dir/checksum.c.obj -c /home/glager/node/mcu/tremornet.tools/liblzg/src/lib/checksum.c

instead of

/usr/bin/arm-none-eabi-gcc -DLZG_SAVED_WINDOWS=1 -O3 -funroll-loops -W -Wall -Wno-extra -O2 -imacros /home/glager/node/mcu/TN2/bluid/zephyr/include/generated/autoconf.h -ffreestanding -fno-common -g -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -imacros /home/glager/node/mcu/zephyr/include/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wno-main -Wno-pointer-sign -Wpointer-arith -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -fno-pie -fno-pic -fno-strict-overflow -ffunction-sections -Wformat=0 -Wno-format-security -fno-reorder-functions -fno-defer-pop -fstack-usage -ffunction-sections -fdata-sections -specs=nano.specs -std=c99 -MD -MT liblzg/src/lib/CMakeFiles/lzg.dir/checksum.c.obj -MF liblzg/src/lib/CMakeFiles/lzg.dir/checksum.c.obj.d -o liblzg/src/lib/CMakeFiles/lzg.dir/checksum.c.obj -c /home/glager/node/mcu/tremornet.tools/liblzg/src/lib/checksum.c

To Reproduce

  • Have a zephyr-independant target (here lzg) and do:
zephyr_get_system_include_directories_for_lang(C ext_system_includes)
zephyr_get_compile_definitions_for_lang(C ext_definitions)

zephyr_get_compile_options_for_lang(C ext_options)

target_compile_options(lzg PRIVATE ${ext_options})
target_include_directories(lzg PRIVATE ${ext_system_includes})

Only zephyr_get_compile_options_for_lang seems to add this extra double quote, zephyr_get_system_include_directories_for_lang does not

Expected behavior
The extra double quote should not be added

Impact
This is kind of a show stopper since I can't compile my application anymore

Environment (please complete the following information):

  • OS: Linux
  • GNU Arm Embedded toolchain
  • Zephyr-v2.4.0
@kurddt kurddt added the bug The issue is a bug, or the PR is fixing a bug label Oct 1, 2020
@tejlmand
Copy link
Collaborator

tejlmand commented Oct 1, 2020

The zephyr_get_compile_options_for_lang(C ext_options) was originally intended to be used integration to external build system/libraries, such as here:

but it does have a side-effect, and that is that it is process order dependent (you may not get flags added after this code was called).
I have done some cleanup and improvements, but need to keep the code working for main use case.
A safer approach in your case is to do:

target_compile_options(lzg PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_COMPILE_OPTIONS>)
target_include_directories(lzg SYSTEM PRIVATE $<TARGET_PROPERTY:zephyr_interface,INTERFACE_SYSTEM_INCLUDE_DIRECTORIES>)

also look at openthread for inspiration:
https://github.com/zephyrproject-rtos/openthread/blob/zephyr/zephyr/CMakeLists.txt#L214-L229

btw. your code snippet doesn't use: ext_definitions

@tejlmand tejlmand added question and removed bug The issue is a bug, or the PR is fixing a bug labels Oct 1, 2020
@kurddt
Copy link
Contributor Author

kurddt commented Oct 2, 2020

Ok, thanks for the tip. This is working perfectly

@kurddt kurddt closed this as completed Oct 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants