MantisBT - CMake
View Issue Details
0015678CMakeCMakepublic2015-08-03 17:082016-01-04 11:52
Chris 
 
normalminoralways
closedwon't fix 
Apple MacOS X10.10.4
CMake 3.3 
 
0015678: CMakeCache.txt can't be passed into cmake's -C flag
I'm probably trying to be too clever, but I'm trying to setup a cmake build target for clang to do a "bootstrap" build where you build clang, then use the built clang to rebuild clang. I had this "genius" idea that I could try and pass through the CMake options used to configure the first clang using the CMakeCache.txt and the -C flag. It unfortunately doesn't work. I see the following errors:

[2/5] Performing configure step for 'bootstrap'
FAILED: cd /Users/cbieneman/dev/open-source/llvm-build-rel/tools/clang/bootstrap/src/bootstrap-build && /Users/cbieneman/dev/open-source/cmake-bins/bin/cmake -C /Users/cbieneman/dev/open-source/llvm-build-rel/CMakeCache.txt -DCMAKE_CXX_COMPILER=/Users/cbieneman/dev/open-source/llvm-build-rel/bin/clang++ -DCMAKE_CXX_COMPILER=/Users/cbieneman/dev/open-source/llvm-build-rel/bin/clang "-GSublime Text 2 - Ninja" /Users/cbieneman/dev/open-source/llvm && /Users/cbieneman/dev/open-source/cmake-bins/bin/cmake -E touch /Users/cbieneman/dev/open-source/llvm-build-rel/tools/clang/bootstrap/src/bootstrap-stamp/bootstrap-configure
loading initial cache file /Users/cbieneman/dev/open-source/llvm-build-rel/CMakeCache.txt
CMake Error: Error in cmake code at
/Users/cbieneman/dev/open-source/llvm-build-rel/CMakeCache.txt:17:
Parse error. Expected a command name, got unquoted argument with text "//Default".
CMake Error: Error processing file: /Users/cbieneman/dev/open-source/llvm-build-rel/CMakeCache.txt
Apply the diffs below to clang, and configure with CMake setting -DCLANG_ENABLE_BOOTSTRAP=On, and run <buildtool> bootstrap.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ab70f1d..6974b6e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -96,6 +96,7 @@ if( CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
 
   option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
     "Set to ON to force using an old, unsupported host toolchain." OFF)
+ option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
 
   include(AddLLVM)
   include(TableGen)
@@ -551,3 +552,31 @@ if (CLANG_BUILT_STANDALONE)
     ${CLANG_BINARY_DIR}/share/clang/cmake/ClangConfig.cmake
     COPYONLY)
 endif ()
+
+if (CLANG_ENABLE_BOOTSTRAP)
+ include(ExternalProject)
+
+ ExternalProject_Add(bootstrap
+ DEPENDS clang
+ PREFIX bootstrap
+ SOURCE_DIR ${CMAKE_SOURCE_DIR}
+ CMAKE_ARGS -C ${CMAKE_BINARY_DIR}/CMakeCache.txt
+ ${CLANG_BOOTSTRAP_CMAKE_ARGS}
+ -DCMAKE_CXX_COMPILER=${CMAKE_BINARY_DIR}/bin/clang++
+ -DCMAKE_CXX_COMPILER=${CMAKE_BINARY_DIR}/bin/clang
+ STEP_TARGETS configure build
+ )
+
+ ExternalProject_Add_Step(bootstrap force-reconfigure
+ DEPENDERS configure
+ ALWAYS 1
+ )
+
+ ExternalProject_Add_Step(bootstrap clobber
+ COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
+ COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
+ COMMENT "Clobberring compiler-rt build directory..."
+ DEPENDERS configure
+ DEPENDS ${LLVM_RUNTIME_OUTPUT_INTDIR}/bootstrap
+ )
+endif()
No tags attached.
Issue History
2015-08-03 17:08ChrisNew Issue
2015-08-04 08:50Brad KingNote Added: 0039225
2015-08-04 08:50Brad KingStatusnew => resolved
2015-08-04 08:50Brad KingResolutionopen => won't fix
2015-08-04 12:11ChrisNote Added: 0039228
2015-08-04 12:56Brad KingNote Added: 0039229
2016-01-04 11:52Robert MaynardNote Added: 0040105
2016-01-04 11:52Robert MaynardStatusresolved => closed

Notes
(0039225)
Brad King   
2015-08-04 08:50   
The -C option is not intended to load a CMakeCache.txt file. From the docs:

 http://www.cmake.org/cmake/help/v3.3/manual/cmake.1.html [^]

 -C ... "The given file should be a CMake script containing SET commands that use the CACHE option, not a cache-format file."

CMakeCache.txt stores much more than just user-selected options and is not appropriate for loading into another build tree.

You could investigate other mechanisms for sharing the settings, like having the bootstrapping build write out a .cmake file for later use with -C to propagate the relevant settings.
(0039228)
Chris   
2015-08-04 12:11   
Ok. Thanks for the information.

Is there any way to get the list of arguments set via the command line without anything else?
I know get_cmake_property can be used to get the cached variables, but as you point out that includes more than just the user-selected options.
(0039229)
Brad King   
2015-08-04 12:56   
Re 0015678:0039228: No access to the command line is available because after the first configuration then re-configuration can occur with no command since everything is cached. Also cmake-gui and ccmake allow options to be customized without a command-line.
(0040105)
Robert Maynard   
2016-01-04 11:52   
Closing resolved issues that have not been updated in more than 4 months.