diff --git a/README.md b/README.md index 7e30131..13f0715 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Usage: ```pwsh -cmake -P rocsetup.cmake -p vs2022 -a x64 +cmake -P rocsetup.cmake -p vs2022 -a x64 -S . -B build ``` Will parse and then run: diff --git a/rocbuild.cmake b/rocbuild.cmake index 4261c64..3284671 100644 --- a/rocbuild.cmake +++ b/rocbuild.cmake @@ -92,14 +92,6 @@ endfunction() # dependencies of the executable target have been defined, otherwise some .dlls might not be copied to the target # folder. function(rocbuild_copy_dlls target) - if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.21") - add_custom_command(TARGET ${target} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ - COMMAND_EXPAND_LISTS - ) - return() - endif() - # Sanity checks if(CMAKE_CROSSCOMPILING OR (NOT WIN32)) return() @@ -116,6 +108,14 @@ function(rocbuild_copy_dlls target) message(FATAL_ERROR "rocbuild_copy_dlls() was called on a non-executable target: ${target}") endif() + if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.21") + add_custom_command(TARGET ${target} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different $ $ + COMMAND_EXPAND_LISTS + ) + return() + endif() + # set the name of file to be written if(DEFINED CMAKE_CONFIGURATION_TYPES) set(COPY_SCRIPT "${CMAKE_BINARY_DIR}/rocbuild_copy_dlls_${target}_$.cmake") @@ -298,5 +298,13 @@ function(rocbuild_remove_unused_data_and_function TARGET) endfunction() +function(rocbuild_print_args) + message(STATUS "ROCBUILD/I: CMake version: ${CMAKE_VERSION}") + message(STATUS "ROCBUILD/I: ROCBUILD_PLATFORM: ${ROCBUILD_PLATFORM}") + message(STATUS "ROCBUILD/I: ROCBUILD_ARCH: ${ROCBUILD_ARCH}") +endfunction() + + +rocbuild_print_args() rocbuild_set_artifacts_path() rocbuild_enable_ninja_colorful_output() \ No newline at end of file diff --git a/rocsetup.cmake b/rocsetup.cmake index 9b63f1d..23b6997 100644 --- a/rocsetup.cmake +++ b/rocsetup.cmake @@ -8,9 +8,18 @@ function(print_args) endfunction() +function(print_original_args) + set(all_args) + foreach(i RANGE 0 ${CMAKE_ARGC}) + set(all_args "${all_args} ${CMAKE_ARGV${i}}") + endforeach() + message(STATUS "ROCSETUP/I: Raw command:${all_args}") +endfunction() + + function(parse_args) math(EXPR LAST_INDEX "${CMAKE_ARGC}-1") - set(options -p -a) + set(options -p -a -S -B) set(current_option "") foreach(i RANGE 1 ${LAST_INDEX}) # message("Argument ${i}: ${CMAKE_ARGV${i}}") @@ -22,6 +31,10 @@ function(parse_args) set(ROCBUILD_PLATFORM "${arg}" PARENT_SCOPE) elseif(current_option STREQUAL "-a") set(ROCBUILD_ARCH "${arg}" PARENT_SCOPE) + elseif(current_option STREQUAL "-S") + set(ROCBUILD_SOURCE_DIR "${arg}" PARENT_SCOPE) + elseif(current_option STREQUAL "-B") + set(ROCBUILD_BINARY_DIR "${arg}" PARENT_SCOPE) endif() set(current_option "") endif() @@ -46,22 +59,41 @@ function(set_generator) set(ROCBUILD_GENERATOR_EXTRA ${ROCBUILD_GENERATOR_EXTRA} PARENT_SCOPE) endfunction() + +print_original_args() #print_args() parse_args() set_generator() -message(STATUS "ROCBUILD_PLATFORM: ${ROCBUILD_PLATFORM}") -message(STATUS "ROCBUILD_ARCH: ${ROCBUILD_ARCH}") -message(STATUS "ROCBUILD_GENERATOR: ${ROCBUILD_GENERATOR}") +set(cmake_arguments) -set(cmake_arguments - -S . -B build - -G ${ROCBUILD_GENERATOR} ${ROCBUILD_GENERATOR_EXTRA} - -DROCBUILD_PLATFORM=${ROCBUILD_PLATFORM} -DROCBUILD_ARCH=${ROCBUILD_ARCH} -) +if(ROCBUILD_SOURCE_DIR) + list(APPEND cmake_arguments -S ${ROCBUILD_SOURCE_DIR}) +endif() + +if(ROCBUILD_BINARY_DIR) + list(APPEND cmake_arguments -B ${ROCBUILD_BINARY_DIR}) +endif() + +if(ROCBUILD_GENERATOR) + list(APPEND cmake_arguments -G ${ROCBUILD_GENERATOR} ${ROCBUILD_GENERATOR_EXTRA}) +endif() + +if(ROCBUILD_PLATFORM) + list(APPEND cmake_arguments -DROCBUILD_PLATFORM=${ROCBUILD_PLATFORM}) +else() + message(FATAL_ERROR "Platform not specified") +endif() + +if(ROCBUILD_ARCH) + list(APPEND cmake_arguments -DROCBUILD_ARCH=${ROCBUILD_ARCH}) +else() + message(FATAL_ERROR "Architecture not specified") +endif() -string(REPLACE ";" " " cmake_arguments_str "${cmake_arguments}") -message(STATUS "CMake arguments: ${cmake_arguments_str}") +set(parsed_command "cmake ${cmake_arguments}") +string(REPLACE ";" " " parsed_command_str "${parsed_command}") +message(STATUS "ROCSETUP/I: Parsed command: ${parsed_command_str}") execute_process( COMMAND cmake ${cmake_arguments} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} @@ -70,7 +102,13 @@ execute_process( ERROR_VARIABLE error_output ) -message("${result}") -message("${output}") -message("${error_output}") +if(result) + message("${result}") +endif() +if(output) + message("${output}") +endif() +if(error_output) + message("${error_output}") +endif()