Skip to content

Commit af912f7

Browse files
committed
Add option to build DXTex as shared lib to cmake
1 parent 9303898 commit af912f7

File tree

6 files changed

+214
-132
lines changed

6 files changed

+214
-132
lines changed

.github/workflows/bvt.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,28 @@ jobs:
8181
echo "::error Unknown architecture/build-type triplet mapping"
8282
}
8383
84+
- name: Get vcpkg commit hash
85+
shell: pwsh
86+
run: |
87+
if ($Env:vcpkgRelease) {
88+
echo "Using vcpkg commit from repo variable..."
89+
$VCPKG_COMMIT_ID = $Env:vcpkgRelease
90+
}
91+
else {
92+
echo "Fetching latest vcpkg commit hash..."
93+
$commit = (git ls-remote https://github.com/microsoft/vcpkg.git HEAD | Select-String -Pattern '([a-f0-9]{40})').Matches.Value
94+
$VCPKG_COMMIT_ID = $commit
95+
}
96+
Write-Host "VCPKG_COMMIT_ID=$VCPKG_COMMIT_ID"
97+
echo "VCPKG_COMMIT_ID=$VCPKG_COMMIT_ID" >> $env:GITHUB_ENV
98+
env:
99+
vcpkgRelease: '${{ vars.VCPKG_COMMIT_ID }}'
100+
84101
- uses: lukka/run-vcpkg@7d259227a1fb6471a0253dd5ab7419835228f7d7 # v11
85102
with:
86103
runVcpkgInstall: true
87104
vcpkgJsonGlob: '**/build/vcpkg.json'
88-
vcpkgGitCommitId: '${{ vars.VCPKG_COMMIT_ID }}'
105+
vcpkgGitCommitId: '${{ env.VCPKG_COMMIT_ID }}'
89106

90107
- name: 'Configure CMake'
91108
working-directory: ${{ github.workspace }}

.github/workflows/test.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,28 @@ jobs:
121121
echo "::error Unknown architecture/build-type triplet mapping"
122122
}
123123
124+
- name: Get vcpkg commit hash
125+
shell: pwsh
126+
run: |
127+
if ($Env:vcpkgRelease) {
128+
echo "Using vcpkg commit from repo variable..."
129+
$VCPKG_COMMIT_ID = $Env:vcpkgRelease
130+
}
131+
else {
132+
echo "Fetching latest vcpkg commit hash..."
133+
$commit = (git ls-remote https://github.com/microsoft/vcpkg.git HEAD | Select-String -Pattern '([a-f0-9]{40})').Matches.Value
134+
$VCPKG_COMMIT_ID = $commit
135+
}
136+
Write-Host "VCPKG_COMMIT_ID=$VCPKG_COMMIT_ID"
137+
echo "VCPKG_COMMIT_ID=$VCPKG_COMMIT_ID" >> $env:GITHUB_ENV
138+
env:
139+
vcpkgRelease: '${{ vars.VCPKG_COMMIT_ID }}'
140+
124141
- uses: lukka/run-vcpkg@7d259227a1fb6471a0253dd5ab7419835228f7d7 # v11
125142
with:
126143
runVcpkgInstall: true
127144
vcpkgJsonGlob: '**/build/vcpkg.json'
128-
vcpkgGitCommitId: '${{ vars.VCPKG_COMMIT_ID }}'
145+
vcpkgGitCommitId: '${{ env.VCPKG_COMMIT_ID }}'
129146

130147
- name: 'Configure CMake'
131148
working-directory: ${{ github.workspace }}

.github/workflows/vcpkg.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,28 @@ jobs:
9393
echo "::error Unknown architecture/build-type triplet mapping"
9494
}
9595
96+
- name: Get vcpkg commit hash
97+
shell: pwsh
98+
run: |
99+
if ($Env:vcpkgRelease) {
100+
echo "Using vcpkg commit from repo variable..."
101+
$VCPKG_COMMIT_ID = $Env:vcpkgRelease
102+
}
103+
else {
104+
echo "Fetching latest vcpkg commit hash..."
105+
$commit = (git ls-remote https://github.com/microsoft/vcpkg.git HEAD | Select-String -Pattern '([a-f0-9]{40})').Matches.Value
106+
$VCPKG_COMMIT_ID = $commit
107+
}
108+
Write-Host "VCPKG_COMMIT_ID=$VCPKG_COMMIT_ID"
109+
echo "VCPKG_COMMIT_ID=$VCPKG_COMMIT_ID" >> $env:GITHUB_ENV
110+
env:
111+
vcpkgRelease: '${{ vars.VCPKG_COMMIT_ID }}'
112+
96113
- uses: lukka/run-vcpkg@7d259227a1fb6471a0253dd5ab7419835228f7d7 # v11
97114
with:
98115
runVcpkgInstall: true
99116
vcpkgJsonGlob: '**/build/vcpkg.json'
100-
vcpkgGitCommitId: '${{ vars.VCPKG_COMMIT_ID }}'
117+
vcpkgGitCommitId: '${{ env.VCPKG_COMMIT_ID }}'
101118

102119
- name: 'Configure CMake'
103120
working-directory: ${{ github.workspace }}

.github/workflows/wsl.yml

+18-1
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,28 @@ jobs:
3737

3838
- uses: seanmiddleditch/gha-setup-ninja@96bed6edff20d1dd61ecff9b75cc519d516e6401 # v5
3939

40+
- name: Get vcpkg commit hash
41+
shell: pwsh
42+
run: |
43+
if ($Env:vcpkgRelease) {
44+
echo "Using vcpkg commit from repo variable..."
45+
$VCPKG_COMMIT_ID = $Env:vcpkgRelease
46+
}
47+
else {
48+
echo "Fetching latest vcpkg commit hash..."
49+
$commit = (git ls-remote https://github.com/microsoft/vcpkg.git HEAD | Select-String -Pattern '([a-f0-9]{40})').Matches.Value
50+
$VCPKG_COMMIT_ID = $commit
51+
}
52+
Write-Host "VCPKG_COMMIT_ID=$VCPKG_COMMIT_ID"
53+
echo "VCPKG_COMMIT_ID=$VCPKG_COMMIT_ID" >> $env:GITHUB_ENV
54+
env:
55+
vcpkgRelease: '${{ vars.VCPKG_COMMIT_ID }}'
56+
4057
- uses: lukka/run-vcpkg@7d259227a1fb6471a0253dd5ab7419835228f7d7 # v11
4158
with:
4259
runVcpkgInstall: true
4360
vcpkgJsonGlob: '**/build/vcpkg.json'
44-
vcpkgGitCommitId: '${{ vars.VCPKG_COMMIT_ID }}'
61+
vcpkgGitCommitId: '${{ env.VCPKG_COMMIT_ID }}'
4562

4663
- name: 'Configure CMake'
4764
working-directory: ${{ github.workspace }}

CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ project (DirectXTex
1717

1818
option(BUILD_TOOLS "Build tex command-line tools" ON)
1919

20+
option(BUILD_SHARED_LIBS "Build DirectXTex as a shared library" OFF)
21+
2022
option(BUILD_SAMPLE "Build DDSView sample (requires fxc.exe)" ON)
2123

2224
# Includes the functions for Direct3D 11 resources and DirectCompute compression
@@ -220,7 +222,12 @@ if(BUILD_DX11 AND WIN32 AND (NOT (XBOX_CONSOLE_TARGET STREQUAL "durango")))
220222
endif()
221223
endif()
222224

223-
add_library(${PROJECT_NAME} STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
225+
add_library(${PROJECT_NAME} ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
226+
227+
if(WIN32 AND BUILD_SHARED_LIBS)
228+
target_compile_definitions(${PROJECT_NAME} PRIVATE DIRECTX_TEX_EXPORT)
229+
target_compile_definitions(${PROJECT_NAME} INTERFACE DIRECTX_TEX_IMPORT)
230+
endif()
224231

225232
if(BUILD_DX11 AND WIN32)
226233
target_include_directories(${PROJECT_NAME} PRIVATE ${COMPILED_SHADERS})

0 commit comments

Comments
 (0)