From 657287e774c6d7f740bedbcbd9846de473dd1b18 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 10:15:21 +0800 Subject: format cmake files (#5406) * format cmake files * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- cmake/FetchedSharedLibrary.cmake | 27 ++++---- cmake/GitHubRelease.cmake | 146 +++++++++++++++++++++++++++++++-------- cmake/Glob.cmake | 4 +- cmake/LLVM.cmake | 55 +++++++++++---- cmake/SlangTarget.cmake | 26 ++++--- 5 files changed, 189 insertions(+), 69 deletions(-) (limited to 'cmake') diff --git a/cmake/FetchedSharedLibrary.cmake b/cmake/FetchedSharedLibrary.cmake index 3c7f24be5..fa0bd9f5e 100644 --- a/cmake/FetchedSharedLibrary.cmake +++ b/cmake/FetchedSharedLibrary.cmake @@ -9,23 +9,24 @@ function(download_and_extract archive_name url) set(archive_path ${url}) else() message(STATUS "Fetching ${archive_name} from ${url}") - file(DOWNLOAD ${url} ${archive_path} - # SHOW_PROGRESS - STATUS status + file( + DOWNLOAD ${url} ${archive_path} + # SHOW_PROGRESS + STATUS status ) list(GET status 0 status_code) list(GET status 1 status_string) if(NOT status_code EQUAL 0) - message(WARNING "Failed to download ${archive_name} from ${url}: ${status_string}") + message( + WARNING + "Failed to download ${archive_name} from ${url}: ${status_string}" + ) return() endif() endif() - file(ARCHIVE_EXTRACT - INPUT ${archive_path} - DESTINATION ${extract_dir} - ) + file(ARCHIVE_EXTRACT INPUT ${archive_path} DESTINATION ${extract_dir}) set(${archive_name}_SOURCE_DIR ${extract_dir} PARENT_SCOPE) message(STATUS "${archive_name} downloaded and extracted to ${extract_dir}") @@ -51,10 +52,7 @@ function(copy_fetched_shared_library library_name url) ) macro(from_glob dir) # A little helper function - file( - GLOB_RECURSE source_object - "${dir}/${shared_library_filename}" - ) + file(GLOB_RECURSE source_object "${dir}/${shared_library_filename}") list(LENGTH source_object nmatches) if(nmatches EQUAL 0) message( @@ -88,7 +86,10 @@ function(copy_fetched_shared_library library_name url) elseif(ARG_IGNORE_FAILURE) return() else() - message(SEND_ERROR "Unable to download and extract ${library_name} from ${url}") + message( + SEND_ERROR + "Unable to download and extract ${library_name} from ${url}" + ) return() endif() endif() diff --git a/cmake/GitHubRelease.cmake b/cmake/GitHubRelease.cmake index 0590933d2..adcb9a563 100644 --- a/cmake/GitHubRelease.cmake +++ b/cmake/GitHubRelease.cmake @@ -14,24 +14,45 @@ function(check_assets_for_file json_content filename found_var) set(${found_var} "${found}" PARENT_SCOPE) endfunction() -function(get_latest owner repo os arch github_token out_var) - set(json_output_file "${CMAKE_CURRENT_BINARY_DIR}/${owner}_${repo}_release_info.json") - set(latest_release_url "https://api.github.com/repos/${owner}/${repo}/releases/latest") +function( + get_latest + owner + repo + os + arch + github_token + out_var +) + set(json_output_file + "${CMAKE_CURRENT_BINARY_DIR}/${owner}_${repo}_release_info.json" + ) + set(latest_release_url + "https://api.github.com/repos/${owner}/${repo}/releases/latest" + ) set(download_args "${latest_release_url}" "${json_output_file}" - STATUS download_statuses + STATUS + download_statuses ) if(github_token) - list(APPEND download_args HTTPHEADER "Authorization: token ${github_token}") + list( + APPEND + download_args + HTTPHEADER + "Authorization: token ${github_token}" + ) endif() file(DOWNLOAD ${download_args}) list(GET download_statuses 0 status_code) if(NOT status_code EQUAL 0) - message(WARNING "Failed to download latest release info from ${latest_release_url}") + message( + WARNING + "Failed to download latest release info from ${latest_release_url}" + ) return() endif() @@ -42,33 +63,62 @@ function(get_latest owner repo os arch github_token out_var) # Check if the expected ZIP file is in the latest release set(desired_zip "${repo}-${latest_version}-${os}-${arch}.zip") - message(VERBOSE "searching for the prebuilt slang-llvm library in ${latest_release_url}") - check_assets_for_file("${latest_json_content}" "${desired_zip}" file_found_latest) + message( + VERBOSE + "searching for the prebuilt slang-llvm library in ${latest_release_url}" + ) + check_assets_for_file( + "${latest_json_content}" + "${desired_zip}" + file_found_latest + ) if(file_found_latest) # If we got it, we found a good version set(${out_var} "${latest_version}" PARENT_SCOPE) else() - message(WARNING "No release binary for ${os}-${arch} exists for the latest version: ${latest_version}") + message( + WARNING + "No release binary for ${os}-${arch} exists for the latest version: ${latest_version}" + ) endif() endfunction() -function(check_release_and_get_latest owner repo version os arch github_token out_var) +function( + check_release_and_get_latest + owner + repo + version + os + arch + github_token + out_var +) # Construct the URL for the specified version's release API endpoint - set(version_url "https://api.github.com/repos/${owner}/${repo}/releases/tags/v${version}") + set(version_url + "https://api.github.com/repos/${owner}/${repo}/releases/tags/v${version}" + ) - set(json_output_file "${CMAKE_CURRENT_BINARY_DIR}/${owner}_${repo}_release_info.json") + set(json_output_file + "${CMAKE_CURRENT_BINARY_DIR}/${owner}_${repo}_release_info.json" + ) # Prepare download arguments set(download_args "${version_url}" "${json_output_file}" - STATUS download_statuses + STATUS + download_statuses ) if(github_token) # Add authorization header if token is provided - list(APPEND download_args HTTPHEADER "Authorization: token ${github_token}") + list( + APPEND + download_args + HTTPHEADER + "Authorization: token ${github_token}" + ) endif() # Perform the download @@ -81,18 +131,28 @@ function(check_release_and_get_latest owner repo version os arch github_token ou # Check if the specified version contains the expected ZIP file set(desired_zip "${repo}-${version}-${os}-${arch}.zip") - message(VERBOSE "searching for the prebuilt slang-llvm library in ${version_url}") + message( + VERBOSE + "searching for the prebuilt slang-llvm library in ${version_url}" + ) check_assets_for_file("${json_content}" "${desired_zip}" file_found) if(file_found) set(${out_var} "${version}" PARENT_SCOPE) return() endif() - message(WARNING "Failed to find ${desired_zip} in release assets for ${version} from ${version_url}\nFalling back to latest version if it differs") + message( + WARNING + "Failed to find ${desired_zip} in release assets for ${version} from ${version_url}\nFalling back to latest version if it differs" + ) else() - set(w "Failed to download release info for version ${version} from ${version_url}\nFalling back to latest version if it differs") + set(w + "Failed to download release info for version ${version} from ${version_url}\nFalling back to latest version if it differs" + ) if(status_code EQUAL 22) - set(w "${w}\nIf you think this is failing because of GitHub API rate limiting, Github allows a higher limit if you use a token. Try the cmake option -DSLANG_GITHUB_TOKEN=your_token_here") + set(w + "${w}\nIf you think this is failing because of GitHub API rate limiting, Github allows a higher limit if you use a token. Try the cmake option -DSLANG_GITHUB_TOKEN=your_token_here" + ) endif() message(WARNING ${w}) @@ -112,7 +172,10 @@ function(get_best_slang_binary_release_url github_token out_var) elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64|ARM64|arm64") set(arch "aarch64") else() - message(WARNING "Unsupported architecture for slang binary releases: ${CMAKE_SYSTEM_PROCESSOR}") + message( + WARNING + "Unsupported architecture for slang binary releases: ${CMAKE_SYSTEM_PROCESSOR}" + ) return() endif() @@ -123,7 +186,10 @@ function(get_best_slang_binary_release_url github_token out_var) elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") set(os "linux") else() - message(WARNING "Unsupported operating system for slang binary releases: ${CMAKE_SYSTEM_NAME}") + message( + WARNING + "Unsupported operating system for slang binary releases: ${CMAKE_SYSTEM_NAME}" + ) return() endif() @@ -135,17 +201,43 @@ function(get_best_slang_binary_release_url github_token out_var) # fallback to the latest release if(${SLANG_VERSION_NUMERIC} VERSION_LESS "2024.1.27") if(${SLANG_VERSION_NUMERIC} VERSION_EQUAL "0.0.0") - message(VERBOSE "The detected version of slang is ${SLANG_VERSION_NUMERIC}, fetching libslang-llvm from the latest release") + message( + VERBOSE + "The detected version of slang is ${SLANG_VERSION_NUMERIC}, fetching libslang-llvm from the latest release" + ) else() - message(WARNING "The detected version of slang ${SLANG_VERSION_NUMERIC} is very old (probably you haven't fetched tags recently?), libslang-llvm will be fetched from the latest release rather than the one matching ${SLANG_VERSION_NUMERIC}") + message( + WARNING + "The detected version of slang ${SLANG_VERSION_NUMERIC} is very old (probably you haven't fetched tags recently?), libslang-llvm will be fetched from the latest release rather than the one matching ${SLANG_VERSION_NUMERIC}" + ) endif() - get_latest(${owner} ${repo} ${os} ${arch} "${github_token}" release_version) + get_latest( + ${owner} + ${repo} + ${os} + ${arch} + "${github_token}" + release_version + ) else() - check_release_and_get_latest(${owner} ${repo} ${SLANG_VERSION_NUMERIC} ${os} ${arch} "${github_token}" release_version) + check_release_and_get_latest( + ${owner} + ${repo} + ${SLANG_VERSION_NUMERIC} + ${os} + ${arch} + "${github_token}" + release_version + ) endif() if(DEFINED release_version) - message(VERBOSE "Found a version of libslang-llvm.so in ${release_version}") - set(${out_var} "https://github.com/${owner}/${repo}/releases/download/v${release_version}/slang-${release_version}-${os}-${arch}.zip" PARENT_SCOPE) + message( + VERBOSE + "Found a version of libslang-llvm.so in ${release_version}" + ) + set(${out_var} + "https://github.com/${owner}/${repo}/releases/download/v${release_version}/slang-${release_version}-${os}-${arch}.zip" + PARENT_SCOPE + ) endif() endfunction() - diff --git a/cmake/Glob.cmake b/cmake/Glob.cmake index 831a07496..7adf355f1 100644 --- a/cmake/Glob.cmake +++ b/cmake/Glob.cmake @@ -22,9 +22,9 @@ function(slang_glob_sources var dir) "*.natstepfilter" "*.natjmc" ) - if (CMAKE_SYSTEM_NAME MATCHES "Darwin") + if(CMAKE_SYSTEM_NAME MATCHES "Darwin") list(APPEND patterns "*.mm") - endif() + endif() list(TRANSFORM patterns PREPEND "${dir}/") file(GLOB_RECURSE files CONFIGURE_DEPENDS ${patterns}) diff --git a/cmake/LLVM.cmake b/cmake/LLVM.cmake index a9afdb3cb..e0b7d6241 100644 --- a/cmake/LLVM.cmake +++ b/cmake/LLVM.cmake @@ -41,12 +41,22 @@ endfunction() function(fetch_or_build_slang_llvm) if(SLANG_SLANG_LLVM_FLAVOR STREQUAL "FETCH_BINARY") - install_fetched_shared_library("slang-llvm" "${SLANG_SLANG_LLVM_BINARY_URL}") + install_fetched_shared_library( + "slang-llvm" + "${SLANG_SLANG_LLVM_BINARY_URL}" + ) elseif(SLANG_SLANG_LLVM_FLAVOR STREQUAL "FETCH_BINARY_IF_POSSIBLE") if(SLANG_SLANG_LLVM_BINARY_URL) - install_fetched_shared_library("slang-llvm" "${SLANG_SLANG_LLVM_BINARY_URL}" IGNORE_FAILURE) + install_fetched_shared_library( + "slang-llvm" + "${SLANG_SLANG_LLVM_BINARY_URL}" + IGNORE_FAILURE + ) if(NOT TARGET slang-llvm) - message(WARNING "Unable to fetch slang-llvm prebuilt binary, configuring without LLVM support") + message( + WARNING + "Unable to fetch slang-llvm prebuilt binary, configuring without LLVM support" + ) endif() endif() elseif(SLANG_SLANG_LLVM_FLAVOR STREQUAL "USE_SYSTEM_LLVM") @@ -77,7 +87,11 @@ function(fetch_or_build_slang_llvm) ) # If we don't include this, then the symbols in the LLVM linked here may # conflict with those of other LLVMs linked at runtime, for instance in mesa. - add_supported_cxx_linker_flags(slang-llvm PRIVATE "-Wl,--exclude-libs,ALL") + add_supported_cxx_linker_flags( + slang-llvm + PRIVATE + "-Wl,--exclude-libs,ALL" + ) # The LLVM headers need a warning disabling, which somehow slips through \external if(MSVC) @@ -94,22 +108,37 @@ function(fetch_or_build_slang_llvm) if(CMAKE_SYSTEM_NAME MATCHES "Windows") # DX Agility SDK requires the D3D12*.DLL files to be placed under a sub-directory, "D3D12". # https://devblogs.microsoft.com/directx/gettingstarted-dx12agility/#d3d12sdkpath-should-not-be-the-same-directory-as-the-application-exe - file(GLOB prebuilt_binaries "${slang_SOURCE_DIR}/external/slang-binaries/bin/windows-x64/*") - file(GLOB prebuilt_d3d12_binaries "${slang_SOURCE_DIR}/external/slang-binaries/bin/windows-x64/[dD]3[dD]12*") + file( + GLOB prebuilt_binaries + "${slang_SOURCE_DIR}/external/slang-binaries/bin/windows-x64/*" + ) + file( + GLOB prebuilt_d3d12_binaries + "${slang_SOURCE_DIR}/external/slang-binaries/bin/windows-x64/[dD]3[dD]12*" + ) list(REMOVE_ITEM prebuilt_binaries ${prebuilt_d3d12_binaries}) add_custom_target( - copy-prebuilt-binaries ALL - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/$/${runtime_subdir} - COMMAND ${CMAKE_COMMAND} -E copy_if_different - ${prebuilt_binaries} + copy-prebuilt-binaries + ALL + COMMAND + ${CMAKE_COMMAND} -E make_directory + ${CMAKE_BINARY_DIR}/$/${runtime_subdir} + COMMAND + ${CMAKE_COMMAND} -E copy_if_different ${prebuilt_binaries} ${CMAKE_BINARY_DIR}/$/${runtime_subdir} - COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/$/${runtime_subdir}/D3D12 - COMMAND ${CMAKE_COMMAND} -E copy_if_different + COMMAND + ${CMAKE_COMMAND} -E make_directory + ${CMAKE_BINARY_DIR}/$/${runtime_subdir}/D3D12 + COMMAND + ${CMAKE_COMMAND} -E copy_if_different ${prebuilt_d3d12_binaries} ${CMAKE_BINARY_DIR}/$/${runtime_subdir}/D3D12 VERBATIM ) - set_target_properties(copy-prebuilt-binaries PROPERTIES FOLDER external) + set_target_properties( + copy-prebuilt-binaries + PROPERTIES FOLDER external + ) endif() endif() endfunction() diff --git a/cmake/SlangTarget.cmake b/cmake/SlangTarget.cmake index bf1abe3a9..4a3b75704 100644 --- a/cmake/SlangTarget.cmake +++ b/cmake/SlangTarget.cmake @@ -232,7 +232,10 @@ function(slang_add_target dir type) if(CMAKE_SYSTEM_NAME MATCHES "Darwin") foreach(link_framework ${ARG_LINK_WITH_FRAMEWORK}) - target_link_libraries(${target} PRIVATE "-framework ${link_framework}") + target_link_libraries( + ${target} + PRIVATE "-framework ${link_framework}" + ) endforeach() endif() @@ -294,7 +297,10 @@ function(slang_add_target dir type) PUBLIC "${ARG_EXPORT_MACRO_PREFIX}_STATIC" ) else() - message(WARNING "unhandled case in slang_add_target while setting export macro") + message( + WARNING + "unhandled case in slang_add_target while setting export macro" + ) endif() endif() @@ -394,18 +400,10 @@ function(slang_add_target dir type) install( TARGETS ${target} EXPORT SlangTargets - ARCHIVE - DESTINATION ${archive_subdir} - ${ARGN} - LIBRARY - DESTINATION ${library_subdir} - ${ARGN} - RUNTIME - DESTINATION ${runtime_subdir} - ${ARGN} - PUBLIC_HEADER - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ${ARGN} + ARCHIVE DESTINATION ${archive_subdir} ${ARGN} + LIBRARY DESTINATION ${library_subdir} ${ARGN} + RUNTIME DESTINATION ${runtime_subdir} ${ARGN} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ${ARGN} ) endmacro() if(ARG_INSTALL) -- cgit v1.2.3