[llvm] [cmake] Move LLVM_ENABLE_PIC cmake option to HandleLLVMOptions.cmake (PR #84750)

Kristina Bessonova via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 05:11:22 PDT 2024


https://github.com/chbessonova created https://github.com/llvm/llvm-project/pull/84750

LLVM_ENABLE_PIC is used by various LLVM projects which can be built standalone (runtimes, for example), but the only place this option defined is CMakeLists.txt in `llvm/` directory. This hides LLVM_ENABLE_PIC for standalone project builds and makes different defaults for them (as of LLVM_ENABLE_PIC is ON by default, but only for builds where `llvm/` directory is root).

This patch proposes moving the option to HandleLLVMOptions.cmake so that making it defined for all projects that can be built standalone and avoid inconsistency in defaults. The patch also moves LLVM_ENABLE_PLUGINS cmake option since its default value may depend on LLVM_ENABLE_PIC.

>From 4a3b1aab535d26ef4850c53a7360a78e6807287a Mon Sep 17 00:00:00 2001
From: Kristina Bessonova <kbessonova at accesssoftek.com>
Date: Thu, 29 Feb 2024 15:15:15 +0200
Subject: [PATCH] [cmake] Move LLVM_ENABLE_PIC cmake option to
 HandleLLVMOptions.cmake

LLVM_ENABLE_PIC is used by various LLVM projects which can be built standalone
(runtimes, for example), but the only place this option defined is
CMakeLists.txt in `llvm/` directory. This hides LLVM_ENABLE_PIC for standalone
project builds and makes different defaults for them (as of LLVM_ENABLE_PIC is
ON by default, but only for builds where `llvm/` directory is root).

This patch proposes moving the option to HandleLLVMOptions.cmake so that making
it defined for all projects that can be built standalone and avoid inconsistency
in defaults. The patch also moves LLVM_ENABLE_PLUGINS cmake option since its
default value may depend on LLVM_ENABLE_PIC.
---
 llvm/CMakeLists.txt                        | 14 --------------
 llvm/cmake/modules/HandleLLVMOptions.cmake | 14 ++++++++++++++
 2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 111c8cfa15d828..44735e794d38d3 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -599,9 +599,6 @@ set(LLVM_TARGETS_TO_BUILD
    ${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD})
 list(REMOVE_DUPLICATES LLVM_TARGETS_TO_BUILD)
 
-if (NOT CMAKE_SYSTEM_NAME MATCHES "OS390")
-  option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
-endif()
 option(LLVM_ENABLE_MODULES "Compile with C++ modules enabled." OFF)
 if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
   option(LLVM_ENABLE_MODULE_DEBUGGING "Compile with -gmodules." ON)
@@ -930,17 +927,6 @@ message(STATUS "LLVM default target triple: ${LLVM_DEFAULT_TARGET_TRIPLE}")
 
 set(LLVM_TARGET_TRIPLE "${LLVM_DEFAULT_TARGET_TRIPLE}")
 
-if(WIN32 OR CYGWIN)
-  if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
-    set(LLVM_ENABLE_PLUGINS_default ON)
-  else()
-    set(LLVM_ENABLE_PLUGINS_default OFF)
-  endif()
-else()
-  set(LLVM_ENABLE_PLUGINS_default ${LLVM_ENABLE_PIC})
-endif()
-option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default})
-
 set(LLVM_ENABLE_NEW_PASS_MANAGER TRUE CACHE BOOL
   "Enable the new pass manager by default.")
 if(NOT LLVM_ENABLE_NEW_PASS_MANAGER)
diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake
index eca2962cf82071..ad8ad1ae602f7a 100644
--- a/llvm/cmake/modules/HandleLLVMOptions.cmake
+++ b/llvm/cmake/modules/HandleLLVMOptions.cmake
@@ -376,6 +376,9 @@ if( LLVM_USE_LINKER )
   endif()
 endif()
 
+if (NOT CMAKE_SYSTEM_NAME MATCHES "OS390")
+  option(LLVM_ENABLE_PIC "Build Position-Independent Code" ON)
+endif()
 if( LLVM_ENABLE_PIC )
   if( XCODE )
     # Xcode has -mdynamic-no-pic on by default, which overrides -fPIC. I don't
@@ -414,6 +417,17 @@ if( LLVM_ENABLE_PIC )
   endif()
 endif()
 
+if(WIN32 OR CYGWIN)
+  if(BUILD_SHARED_LIBS OR LLVM_BUILD_LLVM_DYLIB)
+    set(LLVM_ENABLE_PLUGINS_default ON)
+  else()
+    set(LLVM_ENABLE_PLUGINS_default OFF)
+  endif()
+else()
+  set(LLVM_ENABLE_PLUGINS_default ${LLVM_ENABLE_PIC})
+endif()
+option(LLVM_ENABLE_PLUGINS "Enable plugin support" ${LLVM_ENABLE_PLUGINS_default})
+
 if((NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX")) AND
    (NOT (WIN32 OR CYGWIN) OR (MINGW AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")))
   # GCC for MinGW does nothing about -fvisibility-inlines-hidden, but warns



More information about the llvm-commits mailing list