Skip to content

Commit e1132bf

Browse files
authored
Merge pull request #3 from geefr/vsgvr
Vsgvr
2 parents f1ea885 + a5a6806 commit e1132bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2169
-925
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
[submodule "Format.cmake"]
2-
path = Format.cmake
3-
url = https://github.com/TheLartians/Format.cmake
1+
[submodule "deps/openvr"]
2+
path = deps/openvr
3+
url = https://github.com/ValveSoftware/openvr

CMakeLists.txt

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,39 +13,15 @@ endif()
1313
set( CMAKE_CXX_STANDARD 17 )
1414
set(OpenGL_GL_PREFERENCE GLVND)
1515

16-
#if( NOT MSVC )
17-
# set( CMAKE_CXX_FLAGS "-Werror=all -Wno-error=unused-variable" )
18-
#endif()
19-
2016
set( FORMAT_SKIP_CMAKE ON )
21-
add_subdirectory(Format.cmake)
17+
add_subdirectory(deps/Format.cmake)
2218

2319
# Package/System requirements
2420
find_package(vsg REQUIRED)
2521
find_package(Vulkan REQUIRED)
2622

27-
# TODO: Paths hardcoded for now
28-
if( NOT OPENVR_ROOT )
29-
set( OPENVR_ROOT "" CACHE PATH "Root directory of OpenVR SDK" FORCE )
30-
message( WARNING "VR Support enabled but OPENVR_ROOT not set")
31-
endif()
32-
#####################
33-
34-
FetchContent_Declare(fmt
35-
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
36-
GIT_TAG 7.1.3
37-
)
38-
FetchContent_MakeAvailable(fmt)
39-
40-
FetchContent_Declare(glm
41-
GIT_REPOSITORY https://github.com/g-truc/glm.git
42-
GIT_TAG 0.9.9.8
43-
)
44-
FetchContent_MakeAvailable(glm)
45-
46-
#####################
47-
4823
# TODO: openvr paths are hardcoded
24+
set( OPENVR_ROOT ${PROJECT_SOURCE_DIR}/deps/openvr )
4925
set( OPENVR_LIB "openvr_api" )
5026
if( MSVC )
5127
set( OPENVR_BINDIR ${OPENVR_ROOT}/bin/win64 )
@@ -57,11 +33,10 @@ endif()
5733

5834
#####################
5935

60-
add_subdirectory( vr )
6136
add_subdirectory( vsgvr )
6237

6338
add_executable( example_vr example_vr.cpp )
64-
target_link_libraries( example_vr vsg::vsg vsgvr fmt::fmt )
39+
target_link_libraries( example_vr vsg::vsg vsgvr )
6540
target_include_directories( example_vr PRIVATE
6641
${OPENVR_ROOT}/headers
6742
vsgvr/include )

Format.cmake

Lines changed: 0 additions & 1 deletion
This file was deleted.

deps/Format.cmake/.cmake-format

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
format:
2+
tab_size: 2
3+
line_width: 100
4+
dangle_parens: true
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Style
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
14+
runs-on: macos-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Install format dependencies
20+
run: pip3 install cmake_format==0.6.11 pyyaml
21+
22+
- name: Check source style
23+
run: cmake-format --check ./CMakeLists.txt ./cmake-format.cmake
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Unix
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
14+
runs-on: macos-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Configure and build without format dependencies
20+
run: |
21+
cmake -Htest -Bbuild
22+
cmake --build build
23+
./build/test
24+
! cmake --build build --target format
25+
26+
- name: Install format dependencies
27+
run: |
28+
brew install clang-format
29+
pip3 install cmake_format==0.6.11 pyyaml
30+
31+
- name: Configure
32+
run: cmake -Htest -Bbuild
33+
34+
- name: Run format
35+
run: "cmake --build build --target format"
36+
37+
- name: Check clang-format
38+
run: "! cmake --build build --target check-clang-format"
39+
40+
- name: Check cmake-format
41+
run: "! cmake --build build --target check-cmake-format"
42+
43+
- name: Check format
44+
run: "! cmake --build build --target check-format"
45+
46+
- name: Fix format
47+
run: cmake --build build --target fix-format
48+
49+
- name: Check fixed format
50+
run: cmake --build build --target check-format && ! git diff --exit-code
51+
52+
- name: Configure cmake-format with excluded file
53+
run: |
54+
git reset --hard HEAD
55+
cmake -Htest -Bbuild -DCMAKE_FORMAT_EXCLUDE="(^|/)sample\\.cmake$"
56+
57+
- name: Fix cmake-format skipping excluded file
58+
run: cmake --build build --target fix-cmake-format
59+
60+
- name: Check cmake-format with excluded file
61+
run: cmake --build build --target check-cmake-format && ! git diff --exit-code -- test/CMakeLists.txt && git diff --exit-code -- test/sample.cmake
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Windows
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
14+
runs-on: windows-latest
15+
16+
steps:
17+
- uses: actions/checkout@v2
18+
19+
- name: Configure and build without format dependencies
20+
shell: bash
21+
run: |
22+
cmake -Htest -Bbuild
23+
cmake --build build
24+
./build/Debug/test.exe
25+
! cmake --build build --target format
26+
27+
- name: Install format dependencies
28+
env:
29+
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
30+
run: |
31+
choco install llvm -y
32+
echo "::add-path::C:\\Program Files\\LLVM\\bin"
33+
pip3 install cmake_format==0.6.11 pyyaml
34+
35+
- name: Configure
36+
shell: bash
37+
run: cmake -Htest -Bbuild
38+
39+
- name: Run format
40+
shell: bash
41+
run: "cmake --build build --target format"
42+
43+
- name: Check clang-format
44+
shell: bash
45+
run: "! cmake --build build --target check-clang-format"
46+
47+
- name: Check cmake-format
48+
shell: bash
49+
run: "! cmake --build build --target check-cmake-format"
50+
51+
- name: Check format
52+
shell: bash
53+
run: "! cmake --build build --target check-format"
54+
55+
- name: Fix format
56+
shell: bash
57+
run: cmake --build build --target fix-format
58+
59+
- name: Check fixed format
60+
shell: bash
61+
run: cmake --build build --target check-format && ! git diff --exit-code
62+
63+
- name: Configure cmake-format with excluded file
64+
# Not using `bash` to prevent regular expression from being treated as a filesystem path
65+
run: |
66+
git reset --hard HEAD
67+
cmake -Htest -Bbuild -DCMAKE_FORMAT_EXCLUDE="(^|/)sample\.cmake$"
68+
69+
- name: Fix cmake-format skipping excluded file
70+
shell: bash
71+
run: cmake --build build --target fix-cmake-format
72+
73+
- name: Check cmake-format with excluded file
74+
shell: bash
75+
run: cmake --build build --target check-cmake-format && ! git diff --exit-code -- test/CMakeLists.txt && git diff --exit-code -- test/sample.cmake

deps/Format.cmake/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build*

deps/Format.cmake/CMakeLists.txt

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
option(FORMAT_SKIP_CMAKE "Skip CMake formatting.")
2+
3+
find_program(CLANG_FORMAT_PROGRAM clang-format)
4+
find_program(GIT_PROGRAM git)
5+
find_program(CMAKE_FORMAT_PROGRAM cmake-format)
6+
find_package(Python)
7+
8+
if(CLANG_FORMAT_PROGRAM AND Python_FOUND)
9+
set(CLANG_FORMAT_COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/git-clang-format.py
10+
--binary=${CLANG_FORMAT_PROGRAM}
11+
)
12+
set(GIT_EMPTY_TREE_HASH 4b825dc642cb6eb9a060e54bf8d69288fbee4904)
13+
14+
add_custom_target(
15+
clang-format
16+
COMMAND ${CLANG_FORMAT_COMMAND} --diff ${GIT_EMPTY_TREE_HASH}
17+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
18+
)
19+
20+
add_custom_target(
21+
check-clang-format
22+
COMMAND ${CLANG_FORMAT_COMMAND} --ci ${GIT_EMPTY_TREE_HASH}
23+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
24+
)
25+
26+
add_custom_target(
27+
fix-clang-format
28+
COMMAND ${CLANG_FORMAT_COMMAND} ${GIT_EMPTY_TREE_HASH} -f
29+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
30+
)
31+
else()
32+
message(STATUS "Format.cmake: clang-format and/or python not found, adding dummy targets")
33+
34+
set(CLANG_FORMAT_NOT_FOUND_COMMAND_ARGS
35+
# show error message
36+
COMMAND ${CMAKE_COMMAND} -E echo
37+
"Format.cmake: cannot run because clang-format and/or python not found"
38+
# fail build
39+
COMMAND ${CMAKE_COMMAND} -E false
40+
)
41+
42+
add_custom_target(clang-format ${CLANG_FORMAT_NOT_FOUND_COMMAND_ARGS})
43+
add_custom_target(check-clang-format ${CLANG_FORMAT_NOT_FOUND_COMMAND_ARGS})
44+
add_custom_target(fix-clang-format ${CLANG_FORMAT_NOT_FOUND_COMMAND_ARGS})
45+
endif()
46+
47+
if(GIT_PROGRAM AND CMAKE_FORMAT_PROGRAM)
48+
function(add_cmake_format_target name)
49+
add_custom_target(
50+
${name}
51+
COMMAND
52+
${CMAKE_COMMAND} -DGIT_PROGRAM=${GIT_PROGRAM} -DCMAKE_FORMAT_PROGRAM=${CMAKE_FORMAT_PROGRAM}
53+
-DCMAKE_FORMAT_TARGET=${name} -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}
54+
-DCMAKE_FORMAT_EXCLUDE=${CMAKE_FORMAT_EXCLUDE} -P
55+
${CMAKE_CURRENT_LIST_DIR}/cmake-format.cmake
56+
VERBATIM
57+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
58+
)
59+
endfunction()
60+
61+
add_cmake_format_target(cmake-format)
62+
add_cmake_format_target(check-cmake-format)
63+
add_cmake_format_target(fix-cmake-format)
64+
else()
65+
message(STATUS "Format.cmake: cmake-format and/or git not found, adding dummy targets")
66+
67+
set(CMAKE_FORMAT_NOT_FOUND_COMMAND_ARGS
68+
# show error message
69+
COMMAND ${CMAKE_COMMAND} -E echo
70+
"Format.cmake: cannot run because cmake-format and/or git not found"
71+
# fail build
72+
COMMAND ${CMAKE_COMMAND} -E false
73+
)
74+
75+
add_custom_target(cmake-format ${CMAKE_FORMAT_NOT_FOUND_COMMAND_ARGS})
76+
add_custom_target(check-cmake-format ${CMAKE_FORMAT_NOT_FOUND_COMMAND_ARGS})
77+
add_custom_target(fix-cmake-format ${CMAKE_FORMAT_NOT_FOUND_COMMAND_ARGS})
78+
endif()
79+
80+
list(APPEND FORMAT_TARGETS clang-format)
81+
list(APPEND CHECK_FORMAT_TARGETS check-clang-format)
82+
list(APPEND FIX_FORMAT_TARGETS fix-clang-format)
83+
if(NOT FORMAT_SKIP_CMAKE)
84+
list(APPEND FORMAT_TARGETS cmake-format)
85+
list(APPEND CHECK_FORMAT_TARGETS check-cmake-format)
86+
list(APPEND FIX_FORMAT_TARGETS fix-cmake-format)
87+
endif()
88+
89+
add_custom_target(format)
90+
add_custom_target(check-format)
91+
add_custom_target(fix-format)
92+
93+
add_dependencies(format ${FORMAT_TARGETS})
94+
add_dependencies(check-format ${CHECK_FORMAT_TARGETS})
95+
add_dependencies(fix-format ${FIX_FORMAT_TARGETS})

0 commit comments

Comments
 (0)