CMake: don't override target output locations if not top-level

CMake was unconditionally setting output locations globally, but
it should not do that if it is not the top-level project (e.g.
during chain building).  Detect this fact and only set the output
location when top level.

Fixes Issue: #708
Fix By: Anthony Alayo (@anthonyalayo)
pull/709/head
Brad House 10 months ago
parent 58e029f332
commit 52ad124676
  1. 14
      CMakeLists.txt

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

Loading…
Cancel
Save