1

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.

9
  • Are you sure that you doesn't use set_target_properties (<target> PROPERTIES PREFIX "../") or similar somewhere? Default output directory ../x64 looks strange. (It is your output directory somedir/modules/x64/ relative to CMakeLists.txt location somedir/modules/MyModules) . Commented Sep 22, 2015 at 15:15
  • Isn't it related to the fact that you call ADD_EXECUTABLE and ADD_TEST with the same target name ? Commented Sep 22, 2015 at 15:23
  • What if you try something like: ADD_TEST(NAME MyTestName COMMAND MyTest) ? Commented Sep 22, 2015 at 15:25
  • @Tsyvarev the only other set_target_properties in the whole project is this: set_target_properties(${ITK} PROPERTIES MAP_INPORTED_CONFIG_RELWITHDEBUGINFO RELEASE) (not sure what it does, that's code I didn't write), and also not setting PREFIX anywhere Commented Sep 23, 2015 at 7:39
  • @RenépaulDebroize I thought add_executable and add_test were both required, and in that way - one to create the executable, and the other to add the produced executable as test - is that wrong? adding name/command to add_test unfortunately didn't change anything. Commented Sep 23, 2015 at 8:47

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.