Cmake dependency problem?

First off, you should use add_subdirectory() instead of subdirs() which is deprecated . You get more precise control of the order of processing that way.

Up vote 1 down vote favorite share g+ share fb share tw.

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. Cmake link|improve this question asked Dec 15 '09 at 19:28name500312 100% accept rate.

I solved this by setting up an VAR in main-tool/CMakeLists. Txt and then by IF statements in tool1/CMakeLists. Txt: IF (NOT DEFINED VAR) SUBDIR(../tool2) ENDIF (NOT DEFINED VAR).

It works but it's obscure. – name Dec 16 '09 at 12:26 Maybe you should close the question if you already found a solution – Nicolás Dec 23 '09 at 18:05.

First off, you should use add_subdirectory() instead of subdirs(), 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.

Main-tool/CMakeLists. Txt: add_subdirectory{"tool2"} add_subdirectory{"tool1"} Don't add another add_subdirectory command in the tool1 directory. There are two approaches you can use to access tool2 from the tool1 build.

First, you could define some cmake variables in the top level main CMakeLists. Txt related to tool2, then populate those variables in the tool2 build. You might need to use the PARENT_SCOPE directive to set those variables from the tool2 subdirectory.

Then use those variables to access tool2 from the tool1 subdirectory. Alternatively, you could build all three tools (tool2, tool1, and main tool, in that order) from the top level CMakeLists file. The build file can get long, but it saves headaches trying to manage the scope of cmake variables.

This is the approach I usually take and I recommend it. To summarize, my recommendation is "one big CMakeLists. Txt file".

Unless it gets really, really big.

Thanks Christopher, I went with the (1) and used the configure_file(). I didn't know about the PARENT_SCOPE. That would help a lot.

– name Feb 10 '10 at 22:14.

You really should use SUBDIRS only for sub directories. What you actually mean by dependency? If you link some libraries together use TARGET_LINK_LIBRARIES, CMake will find them in your project regardless directory.

If it is run time dependency, you usually care about it only after installation or you can use "${CMAKE_CURRENT_BINARY_DIR}/../tool2/tool2" as path to the binary.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions