Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/cmake-source-groups.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: CMake source groups
on:
pull_request:
paths:
- SerialPrograms/CMakeLists.txt
- SerialPrograms/cmake/SourceGroups.cmake
- SerialPrograms/cmake/tests/source-groups/**
- .github/workflows/cmake-source-groups.yml
workflow_dispatch:
jobs:
configure:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v7
- run: cmake -S SerialPrograms/cmake/tests/source-groups -B ../external-source-group-tests
- run: ctest --test-dir ../external-source-group-tests -C Debug --output-on-failure
7 changes: 3 additions & 4 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,9 @@ include(cmake/SourceFiles.cmake)
# add extract_discord_sdk(), which unpacks the per-platform Discord Social SDK zips
include(cmake/ExtractDiscordSDK.cmake)

# Organize source files in IDE project view
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/../../ FILES ${CORE_LIBRARY_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/../../ FILES ${LIBRARY_SOURCES})
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/../../ FILES ${EXECUTABLE_SOURCES})
# Organize source files in IDE project view, including external build outputs.
include(cmake/SourceGroups.cmake)
pa_source_groups("${CMAKE_CURRENT_SOURCE_DIR}/../../" ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES} ${EXECUTABLE_SOURCES})

# Create GUI-free Controller library, CoreLib
include(cmake/CoreLib.cmake)
Expand Down
20 changes: 20 additions & 0 deletions SerialPrograms/cmake/SourceGroups.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Keep authored files in their existing IDE tree and generated files in a group
# independent of the build directory's location (e.g. external Qt qrc output).
function(pa_source_groups ROOT)
set(AUTHORED)
set(GENERATED)
foreach(SOURCE IN LISTS ARGN)
get_source_file_property(IS_GENERATED "${SOURCE}" GENERATED)
if(IS_GENERATED)
list(APPEND GENERATED "${SOURCE}")
else()
list(APPEND AUTHORED "${SOURCE}")
endif()
endforeach()
if(AUTHORED)
source_group(TREE "${ROOT}" FILES ${AUTHORED})
endif()
if(GENERATED)
source_group("Generated Files" FILES ${GENERATED})
endif()
endfunction()
17 changes: 17 additions & 0 deletions SerialPrograms/cmake/tests/source-groups/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Configure-only regression tests; no Qt, compiler or hardware is needed.
# cmake -S SerialPrograms/cmake/tests/source-groups -B /external/path/source-group-tests
# ctest --test-dir /external/path/source-group-tests -C Debug --output-on-failure
cmake_minimum_required(VERSION 3.24)
project(SourceGroupTests NONE)
enable_testing()
get_filename_component(MODULE "../../SourceGroups.cmake" ABSOLUTE)
foreach(CASE IN ITEMS mixed all_generated authored empty)
add_test(NAME ${CASE} COMMAND "${CMAKE_COMMAND}"
-S "${CMAKE_CURRENT_SOURCE_DIR}/fixture"
-B "${CMAKE_CURRENT_BINARY_DIR}/${CASE} output"
"-DSOURCE_GROUPS_MODULE=${MODULE}" "-DSCENARIO=${CASE}")
endforeach()
add_test(NAME reject_external_authored COMMAND "${CMAKE_COMMAND}"
"-DFIXTURE=${CMAKE_CURRENT_SOURCE_DIR}/fixture"
"-DOUTPUT=${CMAKE_CURRENT_BINARY_DIR}/invalid output"
"-DMODULE=${MODULE}" -P "${CMAKE_CURRENT_SOURCE_DIR}/reject-external.cmake")
19 changes: 19 additions & 0 deletions SerialPrograms/cmake/tests/source-groups/fixture/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
cmake_minimum_required(VERSION 3.24)
project(SourceGroupFixture NONE)
include("${SOURCE_GROUPS_MODULE}")
set(SOURCES)
if(SCENARIO STREQUAL "mixed" OR SCENARIO STREQUAL "authored")
list(APPEND SOURCES CMakeLists.txt)
endif()
if(SCENARIO STREQUAL "mixed" OR SCENARIO STREQUAL "all_generated")
# qt_add_resources() marks its binary-directory qrc output GENERATED.
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/qrc_darkstyle.cpp")
set_source_files_properties("${OUTPUT}" PROPERTIES GENERATED TRUE)
list(APPEND SOURCES "${OUTPUT}")
endif()
if(SCENARIO STREQUAL "invalid")
set(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/unrelated.cpp")
file(WRITE "${OUTPUT}" "// Authored outside the source tree.\n")
list(APPEND SOURCES "${OUTPUT}")
endif()
pa_source_groups("${CMAKE_CURRENT_SOURCE_DIR}" ${SOURCES})
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
execute_process(COMMAND "${CMAKE_COMMAND}" -S "${FIXTURE}" -B "${OUTPUT}"
"-DSOURCE_GROUPS_MODULE=${MODULE}" -DSCENARIO=invalid
RESULT_VARIABLE RESULT OUTPUT_VARIABLE STDOUT ERROR_VARIABLE STDERR)
if(RESULT EQUAL 0 OR NOT "${STDOUT}${STDERR}" MATCHES "is not a prefix of file")
message(FATAL_ERROR "Expected source_group to reject an authored file outside ROOT: ${STDOUT}${STDERR}")
endif()
Loading