Skip to content

Commit 991167c

Browse files
committed
Add sourcelink
refs #1
1 parent f8e3627 commit 991167c

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ jobs:
3737
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=$(pwd)/build/output/bin" `
3838
"-DCMAKE_PDB_OUTPUT_DIRECTORY=$(pwd)/build/output/pdb" `
3939
-DPROJECT_VERSION_TWEAK=${{github.run_number}} `
40-
"-DBUILD_METADATA=gha.${{github.run_number}}"
40+
"-DBUILD_METADATA=gha.${{github.run_number}}" `
41+
"-DSOURCELINK=https://raw.githubusercontent.com/${{github.repository}}/${{github.sha}}"
4142
- name: Build
4243
run: cmake --build build --config ${{matrix.kind}} --parallel
4344
- name: Upload artifacts

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.25..4.2 FATAL_ERROR)
33
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
44
include(hybrid-crt)
55
include(smol-binaries)
6+
include(sourcelink)
67

78
if (NOT PROJECT_VERSION_TWEAK)
89
set(PROJECT_VERSION_TWEAK 0)

cmake/sourcelink.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
set(SOURCELINK "" CACHE STRING "URL to retrieve the source")
2+
if (NOT SOURCELINK)
3+
return()
4+
endif ()
5+
6+
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
7+
message(WARNING "SOURCELINK was specified, but not using MSVC-compatible compiler ID")
8+
return()
9+
endif ()
10+
11+
message(STATUS "Using SOURCELINK: ${SOURCELINK}")
12+
cmake_path(
13+
NATIVE_PATH
14+
CMAKE_SOURCE_DIR
15+
NORMALIZE
16+
NATIVE_SOURCE
17+
)
18+
string(REPLACE "\\" "\\\\" NATIVE_SOURCE "${NATIVE_SOURCE}")
19+
file(
20+
WRITE
21+
"${CMAKE_CURRENT_BINARY_DIR}/sourcelink.json"
22+
"{ \"documents\": { \"${NATIVE_SOURCE}\\\\*\": \"${SOURCELINK}/*\" } }"
23+
)
24+
add_link_options("/SOURCELINK:${CMAKE_CURRENT_BINARY_DIR}/sourcelink.json")

0 commit comments

Comments
 (0)