Index: cmake/modules/AddLLVM.cmake =================================================================== --- cmake/modules/AddLLVM.cmake (revision 127962) +++ cmake/modules/AddLLVM.cmake (working copy) @@ -119,8 +119,99 @@ endmacro(add_llvm_example name) +macro(add_no_compile_file ofn) + # Add a dummy generated output files to enable correct dependency analysis + add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.nocompile + COMMAND "${CMAKE_COMMAND}" -E + touch ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.nocompile + DEPENDS ${ofn} + ) + set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${ofn}.nocompile + PROPERTIES + GENERATED TRUE + ) + + # Make sure not to try to compile source c/cpp files as the other build dir + # dir takes care of the actual compiling + set_source_files_properties(${file} PROPERTIES HEADER_FILE_ONLY TRUE) + + # Clean generated files + set_property(DIRECTORY APPEND + PROPERTY ADDITIONAL_MAKE_CLEAN_FILES + ${CMAKE_CURRENT_BINARY_DIR}/${ofn}.nocompile) +endmacro(add_no_compile_file ofn) + +# Used to keep track of the last added utility +set(LLVM_ADD_UTILITY_LAST "" CACHE STRING INTERNAL FORCE) + macro(add_llvm_utility name) - add_llvm_executable(${name} ${ARGN}) + if( LLVM_UTILS_BUILD_DIR ) + + # Figure out project to build + if (MSVC_IDE) + string(REPLACE "${CMAKE_HOME_DIRECTORY}/" "" + LLVM_TEMP_TARGET "${CMAKE_CURRENT_SOURCE_DIR}") + set(LLVM_TEMP_TARGET ${LLVM_TEMP_TARGET}/${name}) + else() + set(LLVM_TEMP_TARGET ${name}) + endif() + + # Add dummy generated files to force rebuild of project when source c/cpp + # files change + foreach(file ${ARGN}) + add_no_compile_file( ${file} ) + set(LLVM_TEMP_FILES ${LLVM_TEMP_FILES} + ${CMAKE_CURRENT_BINARY_DIR}/${file}.nocompile) + endforeach() + + # Add executable to allow resolution of executable path. + # Just build a minimal executable with default.c + add_executable(${name} ${LLVM_TEMP_FILES} ${ARGN} + "${CMAKE_HOME_DIRECTORY}/utils/default.c") + + # Try to hide no compile files in it's own directory + source_group("No Compile" FILES ${LLVM_TEMP_FILES}) + + # Try to put source files in correct directory even though CMake will + # currently put the files in the root when HEADER_FILE_ONLY is set. + source_group("Source Files" FILES ${ARGN}) + + if (MSVC_IDE AND MSVC_VERSION GREATER 1599) + # When building with msbuild reduce verbosity to a sane level + set(LLVM_TEMP_EXTRAPARAMS -- /verbosity:minimal /nologo) + endif() + + # When we are compiling on a multi config generator we need to append + # the configuration dir. + if( LLVM_UTILS_BUILD_CONFIG ) + set(LLVM_TEMP_CONFIG_DIR "/${LLVM_UTILS_BUILD_CONFIG}") + endif() + + # Add a custom command to post build that will build the project in the + # utils build dir and copy the result to our runtime dir. + add_custom_command(TARGET ${name} + POST_BUILD + COMMAND ${CMAKE_COMMAND} --build . --target ${LLVM_TEMP_TARGET} + --config ${LLVM_UTILS_BUILD_CONFIG} ${LLVM_TEMP_EXTRAPARAMS} + COMMAND ${CMAKE_COMMAND} -E copy_if_different + "bin${LLVM_TEMP_CONFIG_DIR}/${name}${CMAKE_EXECUTABLE_SUFFIX}" + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/" + COMMAND ${CMAKE_COMMAND} -E echo + "${LLVM_UTILS_BUILD_DIR}/bin${LLVM_TEMP_CONFIG_DIR}/${name}${CMAKE_EXECUTABLE_SUFFIX}" to + "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_CFG_INTDIR}/${name}${CMAKE_EXECUTABLE_SUFFIX}" + WORKING_DIRECTORY ${LLVM_UTILS_BUILD_DIR}) + + # We need to add dependencies between the different utils, otherwise a race + # condition will occur when the projects are bulit at the same time trying + # to write to the same files. + if ( LLVM_ADD_UTILITY_LAST ) + add_dependencies(${name} ${LLVM_ADD_UTILITY_LAST}) + endif() + set(LLVM_ADD_UTILITY_LAST ${name} CACHE STRING INTERNAL FORCE) + + else() + add_llvm_executable(${name} ${ARGN}) + endif() set_target_properties(${name} PROPERTIES FOLDER "Utils") endmacro(add_llvm_utility name) Index: CMakeLists.txt =================================================================== --- CMakeLists.txt (revision 127962) +++ CMakeLists.txt (working copy) @@ -202,6 +202,28 @@ # Put this before tblgen. Else we have a circular dependence. add_subdirectory(lib/Support) + +set(LLVM_UTILS_ONLY OFF CACHE + OPTION "Build only utils and nothing else.") + +if( CMAKE_VERSION STRGREATER "2.8." ) + set(LLVM_UTILS_BUILD_DIR "" CACHE STRING + "Use separate build dir for utils. Allows you to specify different compile options for utils to for example speed up compile time.") + if( CMAKE_CONFIGURATION_TYPES ) + set(LLVM_UTILS_BUILD_CONFIG "Release" CACHE STRING + "When specifying a separate build dir with LLVM_UTILS_BUILD_DIR use this config when building recursively.") + else() + set(LLVM_UTILS_BUILD_CONFIG "" CACHE STRING + "When specifying a separate build dir with LLVM_UTILS_BUILD_DIR use this config when building recursively.") + endif() +else() + if( LLVM_UTILS_BUILD_DIR ) + message(FATAL_ERROR + "LLVM_UTILS_BUILD_DIR is only supported for CMake 2.8 and later") + endif() +endif() + + set(LLVM_TABLEGEN "tblgen" CACHE STRING "Native TableGen executable. Saves building one when cross-compiling.") # Effective tblgen executable to be used: @@ -216,7 +238,9 @@ add_subdirectory(include/llvm) -add_subdirectory(lib) +if (NOT LLVM_UTILS_ONLY) + add_subdirectory(lib) +endif() add_subdirectory(utils/FileCheck) add_subdirectory(utils/FileUpdate) @@ -224,37 +248,46 @@ add_subdirectory(utils/not) add_subdirectory(utils/llvm-lit) -add_subdirectory(projects) +if (NOT LLVM_UTILS_ONLY) + add_subdirectory(projects) +endif() option(LLVM_BUILD_TOOLS "Build the LLVM tools. If OFF, just generate build targets." ON) option(LLVM_INCLUDE_TOOLS "Generate build targets for the LLVM tools." ON) -if( LLVM_INCLUDE_TOOLS ) +if( LLVM_INCLUDE_TOOLS AND NOT LLVM_UTILS_ONLY) add_subdirectory(tools) endif() option(LLVM_BUILD_EXAMPLES "Build the LLVM example programs. If OFF, just generate build targets." OFF) option(LLVM_INCLUDE_EXAMPLES "Generate build targets for the LLVM examples" ON) -if( LLVM_INCLUDE_EXAMPLES ) +if( LLVM_INCLUDE_EXAMPLES AND NOT LLVM_UTILS_ONLY) add_subdirectory(examples) endif() option(LLVM_BUILD_TESTS "Build LLVM unit tests. If OFF, just generate build targes." OFF) -if( LLVM_INCLUDE_TESTS ) - add_subdirectory(test) + +if( LLVM_INCLUDE_TESTS OR LLVM_UTILS_ONLY ) add_subdirectory(utils/unittest) - add_subdirectory(unittests) - if (MSVC) + if ( MSVC ) # This utility is used to prevent chrashing tests from calling Dr. Watson on # Windows. add_subdirectory(utils/KillTheDoctor) endif() endif() -add_subdirectory(cmake/modules) +if( LLVM_INCLUDE_TESTS AND NOT LLVM_UTILS_ONLY) + add_subdirectory(test) + add_subdirectory(unittests) +endif() + +if (NOT LLVM_UTILS_ONLY) + add_subdirectory(cmake/modules) +endif() + install(DIRECTORY include/ DESTINATION include FILES_MATCHING Index: docs/CMake.html =================================================================== --- docs/CMake.html (revision 127962) +++ docs/CMake.html (working copy) @@ -350,6 +350,25 @@ Function Interface library. If the library or its headers are installed on a custom location, you can set the variables FFI_INCLUDE_DIR and FFI_LIBRARY_DIR. Defaults to OFF. + +
LLVM_UTILS_ONLY:BOOL
+
Build only utils and nothing else. This can be useful in + combination with LLVM_UTILS_BUILD_DIR to minimize the required + CMake build system generation.
+ +
LLVM_UTILS_BUILD_DIR:STRING
+
Use separate build directory for utils. Allows you to specify different + build options for utils. Useful when you for example want to speed up Debug + compile time. The utilities in this directory will be built automatically + when needed.
+ +
LLVM_UTILS_BUILD_CONFIG:STRING
+
The target type to build when using LLVM_UTILS_BUILD_DIR. This is needed + on CMake generators that support generation of multiple target types such as + Visual Studio and Xcode. When set to "" utils build dir will be assumed to + not be multi targeted. Defaults to Release for generators that support + generation of multible targets, otherwise "".
+ Index: utils/default.c =================================================================== --- utils/default.c (revision 0) +++ utils/default.c (revision 0) @@ -0,0 +1,12 @@ +/*===- defalt.c - Default file for utils -----------------------------------===*\ + * + * The LLVM Compiler Infrastructure + * + * This file is distributed under the University of Illinois Open Source + * License. See LICENSE.TXT for details. + * +\*===----------------------------------------------------------------------===*/ + +int main(int argc, char **argv) { + return 0; +}