Reputation: 11379
I have a project that builds on both Linux and Windows.
In that, I have in a subfolder somedir/modules/MyModule
a CMakeLists.txt which should add some test executables. cmake wants to put them in some subdirectory binary folder, but I want to place them in the common binary folder under ${CMAKE_BINARY_DIR}/x64
So what I'm doing is this (in the CMakeLists.txt in the somedir/modules/MyModules
directory):
ADD_EXECUTABLE(MyTest MyTest.cpp)
set_target_properties(MyTest PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/x64")
TARGET_LINK_LIBRARIES(MyTest SomeLibraries...)
ADD_TEST(MyTest ${CMAKE_BINARY_DIR}/x64/MyTest)
Under Linux this works nicely, but under Windows I simply cannot get it to build into the ${CMAKE_BINARY_DIR}/x64
folder. I've checked via MESSAGE
, the ${CMAKE_BINARY_DIR}/x64
does point to the right folder. I also tried changing the CMAKE_RUNTIME_OUTPUT_DIRECTORY
(or even the per-target variables, e.g. CMAKE_MyTest_OUTPUT_DIRECTORY
, MyTest_OUTPUT_DIRECTORY_Release
, MyTest_OUTPUT_DIRECTORY_Debug
, as mentioned here: https://stackoverflow.com/a/25328001/671366). Tested both before or after ADD_EXECUTABLE
, doesn't change anything. The output directory stays fixed on somedir/modules/x64/
.
I'm out of ideas what I need to do, or even where the output directory it insists on using is coming from. Any ideas? At which point in time is the output directory decided in cmake? How does this relate to subdirectories? The executables specified in the parent folder CMakeLists.txt files get built in the desired directory, but if that is by mere chance I can't really say.
Upvotes: 1
Views: 1775
Reputation: 65928
Config-specific property RUNTIME_OUTPUT_DIRECTORY_<CONFIG>
has priority over common one RUNTIME_OUTPUT_DIRECTORY
. Both types of properties are initialized from corresponded CMAKE_*
variable(if it is set) when executable target is created.
So, having e.g CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG
config-specific variable being set makes this variable to be used for Debug
configuration even if RUNTIME_OUTPUT_DIRECTORY
property is explicitely set. The only way to redefine output directory in that case is to set RUNTIME_OUTPUT_DIRECTORY_DEBUG
config-specific property.
Upvotes: 2