[PATCH] D13215: [CMake] Make the bindir and libdir arguments to set_output_directory optional

John Brawn via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 29 08:14:53 PDT 2015


john.brawn updated this revision to Diff 35980.
john.brawn added a comment.

I've gone with the suggestion of using cmake_parse_arguments. I haven't gone for calling set_target_properties is the argument is set, instead of the check at the start, mainly as I'm not sure how moddir would be handled if that were done.


Repository:
  rL LLVM

http://reviews.llvm.org/D13215

Files:
  cmake/modules/AddLLVM.cmake

Index: cmake/modules/AddLLVM.cmake
===================================================================
--- cmake/modules/AddLLVM.cmake
+++ cmake/modules/AddLLVM.cmake
@@ -193,33 +193,34 @@
 # 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)
+function(set_output_directory target)
+  cmake_parse_arguments(ARG "" "BINDIR;LIBDIR;" ${ARGN})
   # Do nothing if *_OUTPUT_INTDIR is empty.
-  if("${bindir}" STREQUAL "")
+  if("${ARG_BINDIR}" STREQUAL "")
     return()
   endif()
 
   # moddir -- corresponding to LIBRARY_OUTPUT_DIRECTORY.
   # It affects output of add_library(MODULE).
   if(WIN32 OR CYGWIN)
     # DLL platform
-    set(moddir ${bindir})
+    set(moddir ${ARG_BINDIR})
   else()
-    set(moddir ${libdir})
+    set(moddir ${ARG_LIBDIR})
   endif()
   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})
+      string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} bi ${ARG_BINDIR})
+      string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} li ${ARG_LIBDIR})
       string(REPLACE ${CMAKE_CFG_INTDIR} ${build_mode} mi ${moddir})
       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 "LIBRARY_OUTPUT_DIRECTORY_${CONFIG_SUFFIX}" ${mi})
     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 RUNTIME_OUTPUT_DIRECTORY ${ARG_BINDIR})
+    set_target_properties(${target} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${ARG_LIBDIR})
     set_target_properties(${target} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${moddir})
   endif()
 endfunction()
@@ -398,7 +399,7 @@
     set(windows_resource_file ${windows_resource_file} PARENT_SCOPE)
   endif()
 
-  set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
+  set_output_directory(${name} BINDIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
   # $<TARGET_OBJECTS> doesn't require compile flags.
   if(NOT obj_name)
     llvm_update_compile_flags(${name})
@@ -627,7 +628,7 @@
   endif()
 
   set(EXCLUDE_FROM_ALL OFF)
-  set_output_directory(${name} ${LLVM_RUNTIME_OUTPUT_INTDIR} ${LLVM_LIBRARY_OUTPUT_INTDIR})
+  set_output_directory(${name} BINDIR ${LLVM_RUNTIME_OUTPUT_INTDIR} LIBDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
   llvm_config( ${name} ${USE_SHARED} ${LLVM_LINK_COMPONENTS} )
   if( LLVM_COMMON_DEPENDS )
     add_dependencies( ${name} ${LLVM_COMMON_DEPENDS} )
@@ -834,7 +835,7 @@
 
   add_llvm_executable(${test_name} ${ARGN})
   set(outdir ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR})
-  set_output_directory(${test_name} ${outdir} ${outdir})
+  set_output_directory(${test_name} BINDIR ${outdir} LIBDIR ${outdir})
   target_link_libraries(${test_name}
     gtest
     gtest_main


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D13215.35980.patch
Type: text/x-patch
Size: 3418 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150929/a0108a15/attachment.bin>


More information about the llvm-commits mailing list