Jacob Davis-Hansson
Jacob Davis-Hansson

Reputation: 2663

How to set up sub directory includes in CMake/CLion?

This is similar to Including directories in Clion, but after following the accepted answer there I made no progress.

I'm trying to edit a large OSS project in CLion. It does not use CMake, so CLion has generated a CMakeLists.txt file. When I open a source file, it is unable to resolve includes that use sub directories:

Problem illustrated

The file this screenshot is from is in the same "opto" subdirectory it is importing from. If I change the imports to not include "opto" it works fine, but I can't do that, since this is a major project and I'm just wanting to write a small patch:

$ find . -type f | wc -l
10532

I've added the file I'm importing directly to add_executable as suggested in the other answer:

# CMakeLists.txt
add_executable(hotspot
    [lots of other files]
    src/share/vm/opto/compile.hpp
)

And I've added the opto directory to include_directories as outlined in the second answer to the other question:

# CMakeLists.txt
include_directories(
    src
    src/share/vm/opto)

Neither is helping CLion resolve imports via the opto subdirectory.

What am I missing?

Upvotes: 1

Views: 2788

Answers (1)

Akhilesh
Akhilesh

Reputation: 51

Using include_directories() must do, but you have to mention each sub_directory separately. Below i have included two directories in the same way where one of it is sub_directory.

enter image description here

The Header files have successfully been detected by CLion.

enter image description here

Upvotes: 2

Related Questions