How to configure Makefile build targets in subdirectories

已完成

I'm running CLion 2023.2.2 on a Macbook Pro, and using the remote development facility to copy and build the code on a Linux box. My team's main C++ project is set up roughly like this:

root
  Makefile
  component1
    Makefile
    [source files]
    unittest
      Makefile
      [unit tests]
  component2
    [more of the same]
  [more components like that]

When I run a build via the all target, everything builds fine. The top-level makefile also has a check target which builds and runs the unit tests, and I have that also set up as a build configuration and it works too. However, it takes a long time so what I want is to have build configurations for the individual unittest directories, either for the check targets in the makefiles or the individual test targets.  I cannot for the life of me figure out a way to do this with CLion. 
The other problem I'm having, undoubtedly related, is that when I'm working on the unit tests, I get the banner across the top that says “This file does not belong to any project target; code insight features might not work properly” and indeed they don't. 

0

Stumbled across the same problem, maybe this will help someone else in the future:

I resolved it by right-clicking the Makefile in the subdirectory and selected “Load Makefile project”

0

I didn't realize my conversation with JetBrains support didn't show up here. I solved most of the problem by writing a build script for my target to invoke remotely; if the currently selected file is in a unittest directory it runs `make check` in that directory, which builds and runs all the unit tests. The other problem was that my unit tests weren't being indexed, because their makefiles are generated on the remote machine by automake and don't exist on my laptop. JetBrains support helped me figure this out; the solution was to go into Advanced Settings, scroll down to “Implicit Make analyzer options” and add `check` to the list of options. Turns out CLion builds its list of targets by running `make` on the remote and creating a target for each compilation command that appears in the output, and in my build environment, the `check` target builds all the unit tests, enabling CLion to index them. Then I added a “test” target that, if the selected file is a unit test, invokes the build script on that file to build and run it.
 

0

请先登录再写评论。