Global variables in CMake for dependency tracking?

One way to make global CMake variables is: set(EXAMPLE_INCLUDE_DIRS CACHE INTERNAL "include directories" FORCE) Than when you want to append or set the value use: set(EXAMPLE_INCLUDE_DIRS ${EXAMPLE_INCLUDE_DIRS } ${EXTRA_INCLUDE_DIRS } CACHE INTERNAL "include directories").

I created an example online that attempts to answer this question. You should be able to download it my GitHub repository at bgoodrs-CMake-Examples. If you click on that link, you can read the document (README.

Markdown in that repository) that attempts to do the same kinds of things that I think that you want to do. You may click the download button to download a copy of the examples for local experimentation. If that missed the mark, then comment on my answer, and I'll try to improve the example accordingly.

Thanks for your very elaborate answer. As far as I see, your solution heads into a different direction, as I can't leave out the add_subdirectory, because the CMakeLists. Txt in each parts subdirectory contains the cache option that will make the targets of this part build or not.

Each subdirectory has to be added, no matter which parts are selected to be built. – crispinus Dec 20 '10 at 9:31.

I solved the problem by myself in meantime. In fact, it was quite straightforward to implement the setup I explained above. I used the EXCLUDE_FROM_ALL option to all targets depending on whether they were explicitly selected by user (=leave out the EXCLUDE_FROM_ALL) or not.

The EXCLUDE_FROM_ALL option has the effect that a target is not included in the all-Target, unless another target (which is not marked as EXCLUDE_FROM_ALL) depends on this target. This works even over subdirectories, because CMake targets are really global and even the topmost parent knows about the bottommost subdirectory's target, and even a subdirectory at the same level knows about the targets of another subdirectory. In my layout, each separate part of my project contains its own CMakeLists.

Txt and adds its own options to the cache, so a sample subproject would look this way: SET(PART_NAME SAMPLE_PART) SET(PART_TARGET_NAME samplepart) SET(BUILD_${PART_NAME} off CACHE BOOL "Build part ${PART_NAME}") SET(${PART_NAME}_FILES some_file. C another_file. C) IF(NOT BUILD_${PART_NAME}) SET(EXCLUDE_${PART_NAME} EXCLUDE_FROM_ALL) ENDIF(NOT BUILD_${PART_NAME}) ADD_LIBRARY(${PART_TARGET_NAME} SHARED ${EXCLUDE_SAMPLE_PART} ${PART_NAME}_FILES) TARGET_LINK_LIBRARY(${PART_TARGET_NAME} some_other_target) So if the user chooses to BUILD_SAMPLE_PART, the target is not set to EXCLUDE_FROM_ALL and will be included in all; if not, the target is set to EXCLUDE_FROM_ALL and will be built only if another target depends on this.

If this target is build, also the "some_other_target" will be built, whether it's included in all by itself or not.

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