Skip to content

Commit 605d8e7

Browse files
#486 Attempts to fix cmake build on windows, msvc (#487)
* #486 Attempts to fix cmake build on windows, msvc * #486 Addresses review comments * #486 Addresses review comments --------- Co-authored-by: ZigRazor <zigrazor@gmail.com>
1 parent 3da142e commit 605d8e7

3 files changed

Lines changed: 42 additions & 35 deletions

File tree

.github/workflows/cmake.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches: [ master ]
66
pull_request:
77
branches: [ master ]
8-
98
env:
109
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
1110
BUILD_TYPE: Release
@@ -39,9 +38,12 @@ jobs:
3938
- name: Configure CMake
4039
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
4140
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
41+
42+
# The macro ${{github.workspace}} results in windows file seprators, (\) which CMake often cannot parse.
43+
# To get around this use a relative path instead.
4244
run: |
4345
if [ ${{ matrix.os }} == 'windows-latest' ]; then
44-
cmake -DTEST=ON -Dgtest_disable_pthreads=ON -B ${{github.workspace}}/build
46+
cmake -DTEST=ON -Dgtest_disable_pthreads=ON -B ./build
4547
else
4648
cmake -DTEST=ON -B ${{github.workspace}}/build
4749
fi;

CMakeLists.txt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ if(DEBUG)
1919
)
2020
endif(DEBUG)
2121

22-
option(SANITIZE "Enable Sanitize" OFF)
23-
if(SANITIZE)
24-
add_compile_options(
25-
-fsanitize=address
26-
-fsanitize=leak
27-
)
28-
add_link_options(
29-
-fsanitize=address
30-
-fsanitize=leak
31-
)
32-
endif(SANITIZE)
22+
if (NOT MSVC)
23+
option(SANITIZE "Enable Sanitize" OFF)
24+
if(SANITIZE)
25+
add_compile_options(
26+
-fsanitize=address
27+
-fsanitize=leak
28+
)
29+
add_link_options(
30+
-fsanitize=address
31+
-fsanitize=leak
32+
)
33+
endif(SANITIZE)
34+
endif(NOT MSVC)
3335

3436
# set up CPM.cmake
3537
if(CPM_SOURCE_CACHE)
@@ -52,5 +54,4 @@ add_subdirectory(test)
5254
add_subdirectory(benchmark)
5355
add_subdirectory(examples)
5456

55-
#install(FILES include/Graph.hpp DESTINATION /usr/include)
5657
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include)

test/CMakeLists.txt

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
1-
option(CODE_COVERAGE "Enable coverage reporting" OFF)
21
option(CMAKE_USE_WIN32_THREADS_INIT "using WIN32 threads" ON)
32
option(gtest_disable_pthreads "Disable uses of pthreads in gtest." ON)
43

54
# Force dynamic linking since MSVC now links C runtimes dynamically by default
65
set(gtest_force_shared_crt on)
76

8-
if(CODE_COVERAGE)
9-
message( "Code Coverage Enabled" )
10-
add_compile_options(
11-
-O0 #no optimization
12-
-g #generate debug info
13-
--coverage #set coverage flag
14-
-fprofile-arcs
15-
-ftest-coverage
16-
-fPIC
17-
)
18-
link_libraries(
19-
"gcov"
20-
"-fprofile-arcs"
21-
"--coverage"
22-
)
7+
if (NOT MSVC)
8+
option(CODE_COVERAGE "Enable coverage reporting" OFF)
9+
if(CODE_COVERAGE)
10+
message( "Code Coverage Enabled" )
11+
add_compile_options(
12+
-O0 #no optimization
13+
-g #generate debug info
14+
--coverage #set coverage flag
15+
-fprofile-arcs
16+
-ftest-coverage
17+
-fPIC
18+
)
19+
link_libraries(
20+
"gcov"
21+
"-fprofile-arcs"
22+
"--coverage"
23+
)
2324

24-
endif(CODE_COVERAGE)
25+
endif(CODE_COVERAGE)
26+
endif(NOT MSVC)
2527

2628
option(TEST "Enable Test" OFF)
2729
if(TEST)
2830
include(${CPM_DOWNLOAD_LOCATION})
29-
add_compile_options(
30-
-Wall
31-
-Wextra
32-
)
31+
if (NOT MSVC)
32+
add_compile_options(
33+
-Wall
34+
-Wextra
35+
)
36+
endif(NOT MSVC)
3337

3438
CPMAddPackage(
3539
NAME googletest

0 commit comments

Comments
 (0)