[llvm-commits] [llvm] r155654 - in /llvm/trunk: cmake/modules/AddLLVM.cmake docs/CMake.html tools/CMakeLists.txt

Michael J. Spencer bigcheesegs at gmail.com
Thu Apr 26 12:43:35 PDT 2012


Author: mspencer
Date: Thu Apr 26 14:43:35 2012
New Revision: 155654

URL: http://llvm.org/viewvc/llvm-project?rev=155654&view=rev
Log:
[CMake] Restructure how Clang, Polly and other external projects get included.

While making lld build under the tools directory I decided to refactor how this
works.

There is now a macro, add_llvm_external_project, which takes the name of the
expected subdirectory. This sets up two CMake options.

 * LLVM_EXTERNAL_${NAME}_SOURCE_DIR
     This is the path to the source. It defaults to
     ${CMAKE_CURRENT_SOURCE_DIR}/${name}.
 * LLVM_EXTERNAL_${NAME}_BUILD
     Enable and disable building the tool as part of LLVM.

I chose LLVM_EXTERNAL_${NAME} as a prefix so they all show up together in the
GUI.

Modified:
    llvm/trunk/cmake/modules/AddLLVM.cmake
    llvm/trunk/docs/CMake.html
    llvm/trunk/tools/CMakeLists.txt

Modified: llvm/trunk/cmake/modules/AddLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/modules/AddLLVM.cmake?rev=155654&r1=155653&r2=155654&view=diff
==============================================================================
--- llvm/trunk/cmake/modules/AddLLVM.cmake (original)
+++ llvm/trunk/cmake/modules/AddLLVM.cmake Thu Apr 26 14:43:35 2012
@@ -130,3 +130,21 @@
   add_llvm_library(LLVM${target_name} ${ARGN} ${TABLEGEN_OUTPUT})
   set( CURRENT_LLVM_TARGET LLVM${target_name} )
 endmacro(add_llvm_target)
+
+# Add external project that may want to be built as part of llvm such as Clang,
+# lld, and Polly. This adds two options. One for the source directory of the
+# project, which defaults to ${CMAKE_CURRENT_SOURCE_DIR}/${name}. Another to
+# enable or disable building it with everthing else.
+macro(add_llvm_external_project name)
+  string(TOUPPER ${name} nameUPPER)
+  set(LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${name}"
+      CACHE PATH "Path to ${name} source directory")
+  if (NOT ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} STREQUAL ""
+      AND EXISTS ${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR}/CMakeLists.txt)
+    option(LLVM_EXTERNAL_${nameUPPER}_BUILD
+           "Whether to build ${name} as part of LLVM" ON)
+    if (LLVM_EXTERNAL_${nameUPPER}_BUILD)
+      add_subdirectory(${LLVM_EXTERNAL_${nameUPPER}_SOURCE_DIR} ${name})
+    endif()
+  endif()
+endmacro(add_llvm_external_project)

Modified: llvm/trunk/docs/CMake.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CMake.html?rev=155654&r1=155653&r2=155654&view=diff
==============================================================================
--- llvm/trunk/docs/CMake.html (original)
+++ llvm/trunk/docs/CMake.html Thu Apr 26 14:43:35 2012
@@ -353,10 +353,10 @@
     installed on a custom location, you can set the variables
     FFI_INCLUDE_DIR and FFI_LIBRARY_DIR. Defaults to OFF.</dd>
 
-  <dt><b>LLVM_CLANG_SOURCE_DIR</b>:PATH</dt>
-  <dd>Path to Clang's source directory. Defaults to tools/clang.
-    Clang will not be built when it is empty or it does not point valid
-    path.</dd>
+  <dt><b>LLVM_EXTERNAL_{CLANG,LLD,POLLY}_SOURCE_DIR</b>:PATH</dt>
+  <dd>Path to {Clang,lld,Polly}'s source directory. Defaults to
+    tools/{clang,lld,polly}. {Clang,lld,Polly} will not be built when it is
+    empty or it does not point valid path.</dd>
 
   <dt><b>LLVM_USE_OPROFILE</b>:BOOL</dt>
   <dd> Enable building OProfile JIT support. Defaults to OFF</dd>

Modified: llvm/trunk/tools/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/CMakeLists.txt?rev=155654&r1=155653&r2=155654&view=diff
==============================================================================
--- llvm/trunk/tools/CMakeLists.txt (original)
+++ llvm/trunk/tools/CMakeLists.txt Thu Apr 26 14:43:35 2012
@@ -2,14 +2,6 @@
 # three small executables. This is done to minimize memory load in parallel
 # builds.  Please retain this ordering.
 
-# If polly exists and is not disabled compile it and add it to the LLVM tools.
-option(LLVM_BUILD_POLLY "Compile polly" ON)
-if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/polly/CMakeLists.txt )
-  if (LLVM_BUILD_POLLY)
-    add_subdirectory( ${CMAKE_CURRENT_SOURCE_DIR}/polly)
-  endif (LLVM_BUILD_POLLY)
-endif( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/polly/CMakeLists.txt )
-
 if( NOT WIN32 OR MSYS OR CYGWIN )
   # We currently require 'sed' to build llvm-config, so don't try to build it
   # on pure Win32.
@@ -56,14 +48,8 @@
   endif()
 endif()
 
-set(LLVM_CLANG_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/clang" CACHE PATH "Path to Clang source directory")
-
-if (NOT ${LLVM_CLANG_SOURCE_DIR} STREQUAL ""
-    AND EXISTS ${LLVM_CLANG_SOURCE_DIR}/CMakeLists.txt)
-  option(LLVM_BUILD_CLANG "Whether to build Clang as part of LLVM" ON)
-  if (${LLVM_BUILD_CLANG})
-    add_subdirectory(${LLVM_CLANG_SOURCE_DIR} clang)
-  endif()
-endif ()
+add_llvm_external_project(clang)
+add_llvm_external_project(lld)
+add_llvm_external_project(polly)
 
 set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS} PARENT_SCOPE)





More information about the llvm-commits mailing list