|
1 | | -cmake_minimum_required(VERSION 3.23..4.1) |
| 1 | +cmake_minimum_required(VERSION 3.23..4.3) |
2 | 2 | project(axslcc) |
3 | 3 |
|
4 | 4 | if (WIN32) |
@@ -88,6 +88,69 @@ add_subdirectory(3rdparty/spirv-cross) |
88 | 88 | add_subdirectory(3rdparty/sx) |
89 | 89 | add_subdirectory(src) |
90 | 90 |
|
| 91 | + |
| 92 | +# ------------------------------------------------------------------------------ |
| 93 | +# Helper Function: get_all_targets |
| 94 | +# Description: |
| 95 | +# A helper function to collect all targets (including those in subdirectories) |
| 96 | +# into a list variable. This solves the limitation of CMake's native target listing. |
| 97 | +# Parameters: |
| 98 | +# result - Output variable name to store the list of all targets |
| 99 | +# ------------------------------------------------------------------------------ |
| 100 | +function(get_all_targets result) |
| 101 | + # Initialize an empty list to store targets |
| 102 | + set(targets "") |
| 103 | + |
| 104 | + # Define a recursive function to collect targets from all directories |
| 105 | + function(_get_all_targets_recursive dir) |
| 106 | + # Get targets in the current directory |
| 107 | + get_property(current_targets DIRECTORY ${dir} PROPERTY BUILDSYSTEM_TARGETS) |
| 108 | + |
| 109 | + # Add current directory's targets to the global list |
| 110 | + list(APPEND targets ${current_targets}) |
| 111 | + |
| 112 | + # Get subdirectories of the current directory |
| 113 | + get_property(subdirs DIRECTORY ${dir} PROPERTY SUBDIRECTORIES) |
| 114 | + |
| 115 | + # Recursively process all subdirectories |
| 116 | + foreach(subdir IN LISTS subdirs) |
| 117 | + _get_all_targets_recursive(${subdir}) |
| 118 | + endforeach() |
| 119 | + |
| 120 | + # Update the global targets list (PARENT_SCOPE to pass up) |
| 121 | + set(targets ${targets} PARENT_SCOPE) |
| 122 | + endfunction() |
| 123 | + |
| 124 | + # Start recursive collection from the top-level source directory |
| 125 | + _get_all_targets_recursive(${CMAKE_SOURCE_DIR}) |
| 126 | + |
| 127 | + # Pass the collected targets to the output variable |
| 128 | + set(${result} ${targets} PARENT_SCOPE) |
| 129 | +endfunction() |
| 130 | + |
| 131 | + # Get the list of all targets defined in the current CMake context |
| 132 | +get_all_targets(all_targets) |
| 133 | + |
| 134 | +# Iterate through each target in the collected list |
| 135 | +foreach(target IN LISTS all_targets) |
| 136 | + # Check if the target is an IMPORTED target (external dependency) |
| 137 | + get_target_property(is_imported ${target} IMPORTED) |
| 138 | + |
| 139 | + # Skip imported targets to prevent modifying external libraries |
| 140 | + if(NOT is_imported) |
| 141 | + # Set C++ standard to 20 for the target (C++20) |
| 142 | + set_target_properties(${target} PROPERTIES |
| 143 | + C_STANDARD ${CMAKE_C_STANDARD} |
| 144 | + CXX_STANDARD ${CMAKE_CXX_STANDARD} |
| 145 | + # Enforce the standard (disable compiler-specific extensions) |
| 146 | + CXX_STANDARD_REQUIRED ON |
| 147 | + ) |
| 148 | + |
| 149 | + # Optional: Print log to confirm the setting (comment out if not needed) |
| 150 | + message(STATUS "Set C++${CMAKE_CXX_STANDARD} standard for target: ${target}") |
| 151 | + endif() |
| 152 | +endforeach() |
| 153 | + |
91 | 154 | if(MSVC_IDE) |
92 | 155 | set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT axslcc) |
93 | 156 | endif() |
0 commit comments