custom shell script setting environmental variables with paths for cmake

已回答

I'm working on the C++ CMake project where authors have created external shell scripts where you configure paths like:

ANDROID_NDK:/home/kamil/tools/android-ndk-r16b
PROTOBUF_DIR:/home/kamil/tools/protobuf_lib

it's very convenient that you can abstract complex CMake which is rather constant and configuration which is specific for your environment.

But CLion relies on CMake for indexing and fails to use it.

And even when I use mark directory as project sources and headers for directories with header or sources files from my project indexing doesn't pick them so CLion is able to find only definitions / declarations from the given file.

That's very inconvenient. Eclipse CDT doesn't have problem with indexing these other files.

Is there a way to tell CLion what are values of these missing variables provided by config shell scripts.

0

Hi, Kamil!

Do I understand correctly that the mentioned variables (ANDROID_NDK and PROTOBUF_DIR) are used in the project's CMakeLists.txt? And it's not desirable to change the CMakeLists.txt (so you can't set these variables in it)? In this case you can set values for these variables in the CMake profile (File | Settings | Build, Execution, Deployment | CMake).

Or did I misunderstand the problem?

0

Great Anna! - that solved this issue.

There's one more thing. Authors of the library decided to split CMake so that CMake of the library doesn't include CMake of the examples where I build the code which is interesting for me.

Is there a way to tell CLion to use two different CMake files (the one from top of the project and examples directory) or I need to update the top CMake?

That's acceptable for me but I want to ensure if I need to change this CMake file.

0

So there are two CMakeLists.txt in the project: one in the root folder and another one in the examples subfolder, right? You can add the examples subfolder to the top-level CMakeLists.txt using just add_subdirectory() command (https://cmake.org/cmake/help/latest/command/add_subdirectory.html).

0

I preferred to keep the amount of changes in the original code as small as possible (to avoid possible conflicts when authors of the repository decide to update top CMake and some conflicts might occur) but from your response Anna I understand it's not possible to provide two CMake files so I'll stick to your solution.

Thank you!

0

Yes, a subproject (the examples subfolder) should either be included into the main project (using add_subdirectory()) or be opened as a separate project. 

0

Anna, it is common when working with CMake projects to use bash scripts that run the cmake command. These configure scripts contain my very specific configuration and store it in to variables, that then will be used in CMakeLists.txt. So, I don't have to change CMakeLists.txt every time I want to use a different configuration. 

 

Since I (and probably also many others) have such scripts in place, it would be great to reuse them rather than manually typing their content into the CMake Profile. Is this supported in CLion? 

0

请先登录再写评论。