I have 3 small dependent tools:
main-tool/
tool1/
tool2/
* ----- main-tool ----- *
| |
tool1 ---------- > tool2
The main-tool depends on tool1 & tool2.
The tool1 depends on tool2.
The CMakeFiles look like that:
main-tool/CMakeLists.txt
SUBDIRS{"tool1"}
SUBDIRS{"tool2"}
main-tool/tool1/CMakeLists.txt
SUBDIRS("../tool2"}
I can compile tool1 smoothly. However whenever I want to compile main-tool the tool2 is included twice and produces error. How can I avoid this?
Thanks.
First off, you should use
add_subdirectory()instead ofsubdirs(), which is deprecated. You get more precise control of the order of processing that way.Second, because everything depends on tool2, you should build tool2 first.
Don’t add another
add_subdirectorycommand in the tool1 directory. There are two approaches you can use to access tool2 from the tool1 build.setthose variables from the tool2 subdirectory. Then use those variables to access tool2 from the tool1 subdirectory.To summarize, my recommendation is “one big CMakeLists.txt file”. Unless it gets really, really big.