diff --git a/CMakeLists.txt b/CMakeLists.txt index ebd1ee50..88f55d25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -91,11 +91,15 @@ IF (CARES_SYMBOL_HIDING) CMAKE_POLICY (SET CMP0063 NEW) ENDIF () -# Keep build organized. -SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") -SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") -SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") -SET (PACKAGE_DIRECTORY ${PROJECT_BINARY_DIR}/package) +# Keep build organized, but only if it is the top-level project. +# CMake 3.21 or later has PROJECT_IS_TOP_LEVEL, but we aren't yet depending on +# that version. +IF (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) + SET (CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}") + SET (CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") + SET (CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}") + SET (PACKAGE_DIRECTORY ${PROJECT_BINARY_DIR}/package) +ENDIF () # Destinations for installing different kinds of targets (pass to install command). SET (TARGETS_INST_DEST