Skip to content

Commit 332b7c1

Browse files
[CMake] Fix default install directory
The mechanism for setting the default installation directory to <BUILDDIR>/install is highly dependent on the order of events in the CMakeLists.txt file. Due to recent shifts in the file this has stopped working. The CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT check must happen immediately after the first invocation of project(...). When the llvm-project directory is included first, it is calling project() and then sets the CMAKE_INSTALL_PREFIX to the system default.
1 parent 4a2f029 commit 332b7c1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,24 @@ if(NOT (LLVM_TOOLCHAIN_C_LIBRARY STREQUAL llvmlibc)) # libc in a separate repo?
332332
FetchContent_MakeAvailable(${LLVM_TOOLCHAIN_C_LIBRARY})
333333
endif()
334334

335+
##################################################################################################
336+
# We set all project properties later, this call is just to enable the
337+
# CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT check
338+
project(LLVMEmbeddedToolchainForArm)
335339
# We generally want to install to a local directory to see what the
336340
# output will look like rather than install into the system, so change
337341
# the default accordingly.
338342
# See https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
339-
# Note that this code only works after the first call to project so it
340-
# can't be moved after the add_subdirectory command below.
343+
# Note that THIS CODE ONLY WORKS AFTER THE FIRST CALL TO PROJECT so it
344+
# can't be moved after the add_subdirectory(<llvm>) command below as it will be too late -
345+
# the llvm project will set it to the default system install directory.
341346
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
342347
set(CMAKE_INSTALL_PREFIX
343348
"${CMAKE_BINARY_DIR}/install"
344349
CACHE PATH "" FORCE
345350
)
346351
endif()
352+
##################################################################################################
347353

348354
# Whether to try to build C++ libraries. (We can't currently do this
349355
# for all choices of C library.)

0 commit comments

Comments
 (0)