I understand that by default, Clion creates the binary files for a project loaded in Clion in all the four configurations:
(Debug;Release;MinSizeRel;RelWithDebInfo)
as well as one called: __default__
.
I am using a third party cmake module which downloads an external project in a way that add_subdirectory()
can be run on it so it would be included in the root project.
add_subdirectory(${downloaded_proj_src_dir} ${downloaded_proj_bin_dir} EXCLUDE_FROM_ALL)
In this setup, if I decide to place the child project outside the binary directory of the root project, I get:
Error:Binary directories outside of CMake build directory are not supported. Most likely this error is caused by an add_subdirectory command with an explicitly specified binary_dir argument.
which is an understandable restriction by CMake.
now if I instead decide to set the binary directory of the downloaded project in a subdirectory of the binary directory of the parent project, ie:
set(downloaded_proj_bin_dir "${CMAKE_BINARY_DIR}/${downloaded_proj}-build")
...
add_subdirectory(${downloaded_proj_src_dir} ${downloaded_proj_bin_dir} EXCLUDE_FROM_ALL)
I will get the file created in the parent binary directory of all the build configurations because ${CMAKE_BINARY_DIR}
is different for each configuration. To avoid seeing all these directories listed on the project view sidebar, I have set the CMAKE_CONFIGURATION_TYPES
to be Debug
. But even then, I get:
Error:Configuration Debug The current CMakeCache.txt directory
/path/Debug/downloaded_proj_bin/CMakeCache.txt
is different than the directory/path/__default__/downloaded_proj_bin/CMakeCache.txt
where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
Clearly something is going on with this __default__
configuration which I don't understand. So the question is, what is the significance of this default
configuration and why should there be a conflict here?
P.s. Setting the configuration to __default__
does not solve the problem as I will have a __default__0
configuration created instead and get the same error.
Update: some further observations
- My enviornment variables set in IDE don't have any effect on the cmake builds.
- Cmake "options" however which presumably will be passed as arguments to cmake do seem to work. -D CMAKE_CONFIGURATION_TYPES=Debug.
- When I specify the command line option, I get
Warning:Manually-specified variables were not used by the project: CMAKE_CONFIGURATION_TYPES
But it clearly does have the effect of no longer creating the other build configurations. My guess is that this message relates to the __default__
build which is ignoring the argument.
- Even in the case of specifying CMAKE_CONFIGURATION_TYPES in the IDE, I still get the additional
__default__
build which is apparently unaffected by the CMAKE_CONFIGURATION_TYPES assignment. - Logging:
message("Build type: ${CMAKE_BUILD_TYPE} )
does not return any build_type. - Outputting
message(and generator: ${CMAKE_GENERATOR} ")
returns "Unix-make files" for both, so both are being generated with the same generator. - Taking a diff from the CMakeCache.txt files, I can see that they are identical.