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.
set_target_properties (<target> PROPERTIES PREFIX "../")or similar somewhere? Default output directory../x64looks strange. (It is your output directorysomedir/modules/x64/relative toCMakeLists.txtlocationsomedir/modules/MyModules) .ADD_TEST(NAME MyTestName COMMAND MyTest)?set_target_propertiesin 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 anywhereadd_executableandadd_testwere both required, and in that way - one to create the executable, and the other to add the produced executable as test - is that wrong? addingname/commandto add_test unfortunately didn't change anything.