From 6c726f53f18197792cbb97517567137539366508 Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Mon, 30 Dec 2013 06:48:30 +0000 Subject: [PATCH] [CMake][VS][XCode] Restruct the output directory layout more comfortable, ${BINARY_DIR}/${BUILD_MODE}/(bin|lib) We have been seeing nasty directory layout with CMake multiconfig, such as, bin/Release/clang.exe lib/clang/3.x/... lib/Release/clang/3.x/.. (duplicated) Move the layout similar to autoconf's; Release/bin/clang.exe Release/lib/clang/3.x/... Checked on Visual Studio 10. Could you guys please confirm my change on XCode(and other multiconfig builders)? Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, or a certain builder, for eaxample, msbuild.exe, would be confused. llvm-svn: 198205 --- CMakeLists.txt | 4 ++-- cmake/modules/AddLLVM.cmake | 25 ++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6200de1e37f..56e83289a45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,8 +97,8 @@ set(LLVM_EXAMPLES_BINARY_DIR ${LLVM_BINARY_DIR}/examples) set(LLVM_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/include) set(LLVM_LIBDIR_SUFFIX "" CACHE STRING "Define suffix of library directory name (32/64)" ) -set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_BINARY_DIR}/bin/${CMAKE_CFG_INTDIR}) -set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_BINARY_DIR}/lib/${CMAKE_CFG_INTDIR}) +set(LLVM_RUNTIME_OUTPUT_INTDIR ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin) +set(LLVM_LIBRARY_OUTPUT_INTDIR ${LLVM_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib) set(LLVM_ALL_TARGETS AArch64 diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake index b31aeeeae1f..bbfb9b17ffc 100644 --- a/cmake/modules/AddLLVM.cmake +++ b/cmake/modules/AddLLVM.cmake @@ -95,9 +95,30 @@ function(add_dead_strip target_name) endif() endfunction(add_dead_strip) +# Set each output directory according to ${CMAKE_CONFIGURATION_TYPES}. +# Note: Don't set variables CMAKE_*_OUTPUT_DIRECTORY any more, +# or a certain builder, for eaxample, msbuild.exe, would be confused. +function(set_output_directory target bindir libdir) + if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") + foreach(build_mode ${CMAKE_CONFIGURATION_TYPES}) + string(TOUPPER "${build_mode}" CONFIG_SUFFIX) + string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${bindir}) + string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${libdir}) + set_target_properties(${target} PROPERTIES "RUNTIME_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${bi}) + set_target_properties(${target} PROPERTIES "ARCHIVE_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) + set_target_properties(${target} PROPERTIES "LIBDIR__OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${li}) + endforeach() + else() + set_target_properties(${target} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${bindir}) + set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${libdir}) + set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${libdir}) + endif() +endfunction() + macro(add_llvm_library name) llvm_process_sources( ALL_FILES ${ARGN} ) add_library( ${name} ${ALL_FILES} ) + set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} ) add_dead_strip( ${name} ) if( LLVM_COMMON_DEPENDS ) @@ -201,6 +222,7 @@ macro(add_llvm_executable name) endif(LLVM_EXPORTED_SYMBOL_FILE) set(EXCLUDE_FROM_ALL OFF) + set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR}) llvm_config( ${name} ${LLVM_LINK_COMPONENTS} ) if( LLVM_COMMON_DEPENDS ) add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} ) @@ -313,12 +335,13 @@ endfunction(add_llvm_implicit_external_projects) # Generic support for adding a unittest. function(add_unittest test_suite test_name) - set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) if( NOT LLVM_BUILD_TESTS ) set(EXCLUDE_FROM_ALL ON) endif() add_llvm_executable(${test_name} ${ARGN}) + set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}) + set_output_directory(${test_name} ${outdir} ${outdir}) target_link_libraries(${test_name} gtest gtest_main