[libcxx] r256606 - Cleanup CMake for out-of-tree builds

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 29 17:02:39 PST 2015


Author: ericwf
Date: Tue Dec 29 19:02:38 2015
New Revision: 256606

URL: http://llvm.org/viewvc/llvm-project?rev=256606&view=rev
Log:
Cleanup CMake for out-of-tree builds

Modified:
    libcxx/trunk/CMakeLists.txt
    libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake

Modified: libcxx/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=256606&r1=256605&r2=256606&view=diff
==============================================================================
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Tue Dec 29 19:02:38 2015
@@ -12,20 +12,29 @@ if(POLICY CMP0022)
   cmake_policy(SET CMP0022 NEW) # Required when interacting with LLVM and Clang
 endif()
 
-project(libcxx CXX C)
-
-set(PACKAGE_NAME libcxx)
-set(PACKAGE_VERSION trunk-svn)
-set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
-set(PACKAGE_BUGREPORT "llvm-bugs at lists.llvm.org")
-
 # Add path for custom modules
 set(CMAKE_MODULE_PATH
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake"
   "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules"
-  ${CMAKE_MODULE_PATH}
+   ${CMAKE_MODULE_PATH}
   )
 
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+  project(libcxx CXX C)
+  set(PACKAGE_NAME libcxx)
+  set(PACKAGE_VERSION trunk-svn)
+  set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
+  set(PACKAGE_BUGREPORT "llvm-bugs at lists.llvm.org")
+
+  # Configure for a standalone build
+  message(STATUS "Configuring for standalone build.")
+  set(LIBCXX_BUILT_STANDALONE 1)
+
+  # Find the LLVM sources and simulate LLVM CMake options.
+  include(HandleOutOfTreeLLVM)
+  handle_out_of_tree_llvm()
+endif()
+
 # Require out of source build.
 include(MacroEnsureOutOfSourceBuild)
 MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
@@ -33,15 +42,6 @@ MACRO_ENSURE_OUT_OF_SOURCE_BUILD(
  build directory and run 'cmake /path/to/${PROJECT_NAME} [options]' there."
  )
 
-# Find the LLVM sources and simulate LLVM CMake options.
-include(HandleOutOfTreeLLVM)
-if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND)
-  message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: "
-                  "llvm-config not found and LLVM_PATH not defined.\n"
-                  "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
-                  "or -DLLVM_PATH=path/to/llvm-source-root.")
-endif()
-
 #===============================================================================
 # Setup CMake Options
 #===============================================================================

Modified: libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake?rev=256606&r1=256605&r2=256606&view=diff
==============================================================================
--- libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake (original)
+++ libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake Tue Dec 29 19:02:38 2015
@@ -1,4 +1,6 @@
-macro(find_llvm_parts)
+
+
+macro(internal_find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
   find_program(LLVM_CONFIG "llvm-config")
@@ -57,16 +59,13 @@ macro(find_llvm_parts)
   list(APPEND CMAKE_MODULE_PATH "${LLVM_MAIN_SRC_DIR}/cmake/modules")
 
   set(LLVM_FOUND ON)
-endmacro(find_llvm_parts)
-
+endmacro(internal_find_llvm_parts)
 
-if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
-  set(LIBCXX_BUILT_STANDALONE 1)
-  message(STATUS "Configuring for standalone build.")
-
-  find_llvm_parts()
 
+macro(internal_simulate_llvm_options)
   # LLVM Options --------------------------------------------------------------
+  # Configure the LLVM CMake options expected by libc++.
+
   include(FindPythonInterp)
   if( NOT PYTHONINTERP_FOUND )
     message(WARNING "Failed to find python interpreter. "
@@ -132,7 +131,29 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURR
       MESSAGE(SEND_ERROR "Unable to determine platform")
     endif(UNIX)
   endif(WIN32)
+endmacro(internal_simulate_llvm_options)
+
+
+macro(handle_out_of_tree_llvm)
+  # This macro should not be called unless we are building out of tree.
+  # Enforce that.
+  if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+    message(FATAL_ERROR "libc++ incorrectly configured for out-of-tree LLVM")
+  endif()
+
+  # Attempt to find an LLVM installation and source directory. Warn if they
+  # are not found.
+  internal_find_llvm_parts()
+  if (NOT LLVM_FOUND)
+    message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: "
+                    "llvm-config not found and LLVM_PATH not defined.\n"
+                    "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
+                    "or -DLLVM_PATH=path/to/llvm-source-root.")
+  endif()
+
+  # Simulate the LLVM CMake options and variables provided by an in-tree LLVM.
+  internal_simulate_llvm_options()
 
-  # Add LLVM Functions --------------------------------------------------------
+  # Additionally include the LLVM CMake functions if we can find the module.
   include(AddLLVM OPTIONAL)
-endif()
+endmacro()




More information about the cfe-commits mailing list