Skip to content

Commit bcff54b

Browse files
committed
Fix gtest build to work for windows static or dynamic
Signed-off-by: Neil R. Spruit <neil.r.spruit@intel.com>
1 parent 41e5e32 commit bcff54b

3 files changed

Lines changed: 11 additions & 16 deletions

File tree

.github/workflows/build-quick-static.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
-D CMAKE_C_COMPILER_LAUNCHER=ccache \
3636
-D CMAKE_CXX_COMPILER_LAUNCHER=ccache \
3737
-D CMAKE_BUILD_TYPE=Release \
38-
-D BUILD_L0_LOADER_TESTS=1 \
3938
-D BUILD_STATIC=0 \
4039
..
4140
make -j$(nproc)
@@ -49,13 +48,20 @@ jobs:
4948
runs-on: [windows-latest]
5049
steps:
5150
- uses: actions/checkout@v3
52-
- name: Build Loader on Latest Windows
51+
- name: Build Static Loader on Latest Windows
5352
run: |
5453
mkdir build
5554
cd build
5655
cmake -D BUILD_L0_LOADER_TESTS=1 -D BUILD_STATIC=1 ..
5756
cmake --build . --config Release
57+
- name: Build Dynamic Loader on Latest Windows
58+
run: |
59+
cd ${{ github.workspace }}
60+
mkdir dynamic_build
61+
cd dynamic_build
62+
cmake -D BUILD_L0_LOADER_TESTS=0 -D BUILD_STATIC=0 ..
63+
cmake --build . --config Release
5864
- env:
59-
ZEL_LIBRARY_PATH: '${{ github.workspace }}/build/bin/Release'
65+
ZEL_LIBRARY_PATH: '${{ github.workspace }}/dynamic_build/bin/Release'
6066
working-directory: build
6167
run: ctest -C Release -V

CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ endif()
5252

5353
include(FetchContent)
5454

55-
if(BUILD_L0_LOADER_TESTS AND (NOT MSVC OR (MSVC AND NOT BUILD_STATIC)))
55+
if(BUILD_L0_LOADER_TESTS)
5656
FetchContent_Declare(
5757
googletest
5858
GIT_REPOSITORY https://github.com/google/googletest.git
@@ -61,11 +61,6 @@ if(BUILD_L0_LOADER_TESTS AND (NOT MSVC OR (MSVC AND NOT BUILD_STATIC)))
6161
add_library(GTest::GTest INTERFACE IMPORTED)
6262
target_link_libraries(GTest::GTest INTERFACE gtest_main)
6363

64-
# For Windows: Prevent overriding the parent project's compiler/linker settings
65-
if(MSVC)
66-
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
67-
endif()
68-
6964
FetchContent_MakeAvailable(googletest)
7065

7166
enable_testing()
@@ -229,7 +224,7 @@ set(TARGET_LOADER_NAME ze_loader)
229224
add_subdirectory(source)
230225
add_subdirectory(samples)
231226

232-
if(BUILD_L0_LOADER_TESTS AND (NOT MSVC OR (MSVC AND NOT BUILD_STATIC)))
227+
if(BUILD_L0_LOADER_TESTS)
233228
include(CTest)
234229
add_subdirectory(test)
235230
endif()

test/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ target_link_libraries(
1313
${TARGET_LOADER_NAME}
1414
)
1515

16-
# For some reason the MSVC runtime libraries used by googletest and test
17-
# binaries don't match, so force the test binary to use the dynamic runtime.
18-
if(MSVC)
19-
target_compile_options(tests PRIVATE "/MD$<$<CONFIG:Debug>:d>")
20-
endif()
21-
2216
add_test(NAME tests_api COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingzeGetLoaderVersionsAPIThenValidVersionIsReturned*)
2317
set_property(TEST tests_api PROPERTY ENVIRONMENT "ZE_ENABLE_LOADER_DEBUG_TRACE=1;ZE_ENABLE_NULL_DRIVER=1")
2418
add_test(NAME tests_init_gpu_all COMMAND tests --gtest_filter=*GivenLevelZeroLoaderPresentWhenCallingZeInitDriversWithGPUTypeThenExpectPassWithGPUorAllOnly*)

0 commit comments

Comments
 (0)