Conan is changing the behaviour of a CMake project, it sets the output directories in macro(conan_output_dirs_setup). Regardless one like this or not: should there be set CMAKE_LIBRARY_OUTPUT_DIRECTORY too, just for completeness?
Currently iI can see this lines:
macro(conan_output_dirs_setup)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
endmacro()
But should be:
macro(conan_output_dirs_setup)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
endmacro()
I'm not sure if there are other variables which should be set too in this context.
Do you know this behavior is configurable? You can opt-out of cmake redefining your output directories with NO_OUTPUT_DIRS passed to conan_basic_setup(NO_OUTPUT_DIRS). Check: http://conanio.readthedocs.io/en/latest/reference/generators/cmake.html?highlight=NO_OUTPUT_DIRS
Yes, I knew about this cmake variable, but surprinsingly, it seems it is not really necessary. ARCHIVE takes care of the static libraries, and RUNTIME seems to take care of both executables and shared libraries. Is it failing in your case? Which files are not being directed to "bin" or "lib" folders?
Thanks for the hint regarding conan_basic_setup(NO_OUTPUT_DIRS), I didn't know. Great feature!
For CMake's RUNTIME variables, I'm on Linux and this doesn't work for my *.so files, they still remain in the old original location. Quotation from CMake's manual (https://cmake.org/cmake/help/v3.3/manual/cmake-buildsystem.7.html#id28):
A runtime output artifact of a buildsystem target may be:
- The executable file (e.g. .exe) of an executable target created by the add_executable() command.
- On DLL platforms: the executable file (e.g. .dll) of a shared library target created by the add_library() command with the SHARED option.
If I understand this right, RUNTIME is only for EXE and DLL files, not Linux shared objects. And in my opinion, shared objects should go to a lib folder, not to a bin.
@andioz this has been released in 0.29, please update and report
Perfect, it works!
Most helpful comment
Do you know this behavior is configurable? You can opt-out of cmake redefining your output directories with
NO_OUTPUT_DIRSpassed toconan_basic_setup(NO_OUTPUT_DIRS). Check: http://conanio.readthedocs.io/en/latest/reference/generators/cmake.html?highlight=NO_OUTPUT_DIRSYes, I knew about this cmake variable, but surprinsingly, it seems it is not really necessary. ARCHIVE takes care of the static libraries, and RUNTIME seems to take care of both executables and shared libraries. Is it failing in your case? Which files are not being directed to "bin" or "lib" folders?