incorrect syntax highlighting with nested ifdef

Answered

It seems like clion is not able correctly parse c files that has nested ifdef sections, especially if there is code in the inner ifdef section. For example the following file is an example of where everything within the first #ifdef is treated as includes and no syntax highlighting is available.

https://w1.fi/cgit/hostap/tree/wpa_supplicant/wpa_cli.c

Is there a setting to configure this ?

0
6 comments

Hi Darshak!

Is CONFIG_CTRL_IFACE defined? If yes, please specify where and how.

>everything within the first #ifdef is treated as includes

Could you please provide a screenshot?

0
Avatar
Permanently deleted user

The CONFIG_CTRL_IFACE is defined in a defconfig file ( https://w1.fi/cgit/hostap/tree/wpa_supplicant/defconfig ) line 209. 

attached below is the screenshot of how it looks in CLion

0

CLion doesn't see CONFIG_CTRL_IFACE as defined. As far as I see, the "hostapd and wpa_supplicant" project is not a CMake-based project originally. How have converted it into the CMake project?

I suppose if you add

target_compile_definitions(<target_name> PUBLIC CONFIG_CTRL_IFACE)

to the CMakeLists.txt and reload the CMake project, CLion will be able to provide syntax highlighting for the code inside this ifdef.

0
Avatar
Permanently deleted user

Hi Anna,

Yes this isn't a CMake project. I just used the CLion "import project" and let it create the CMakeLists.txt file. 

I did add the following lines explicitly in the CMakeLists.txt file but i'm still not seeing the syntax highlighting

add_executable(wpa_cli wpa_supplicant/wpa_cli.c)

target_compile_definitions(wpa_cli PUBLIC CONFIG_CTRL_IFACE)

 

0
Avatar
Permanently deleted user

I should have said, this isn't "originally" a CMake project.

0
Avatar
Permanently deleted user

Ok, i finally figured out how to get the syntax highlighting working. Since this is originally a Makefile project and in this particular case the Makefile's depend on a "config" file where some of the variables are defined, The CLion cmake wasn't parsing/reading variables from there.

I added an

add_definitions(-DCONFIG_CTRL_IFACE)

to the CMakeLists.txt file which basically replicates the variables defined in the included config file in the Makefile and it started working.

 

0

Please sign in to leave a comment.