Skip to content

Commit 995f666

Browse files
committed
Merge branch 'yas_with_docker_option' of github.com:Devsh-Graphics-Programming/Nabla
2 parents 84efa72 + d999bbd commit 995f666

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,60 @@ option(NBL_BUILD_BULLET "Enable Bullet Physics building and integration?" OFF)
193193
option(NBL_BUILD_DOCS "Enable building documentation?" OFF) # No one has doxygen installed, plus we dont know when was the last time we generated working doxy and we'll use SphinX in the future
194194
option(NBL_ENABLE_PROJECT_JSON_CONFIG_VALIDATION "" ON)
195195
option(NBL_EMBED_BUILTIN_RESOURCES "Embed built-in resources?" ON)
196+
option(NBL_WITH_DOCKER "Enables docker integration, if client is not found Docker Desktop will be installed" OFF)
197+
198+
if (NBL_WITH_DOCKER)
199+
if (NOT CMAKE_HOST_WIN32)
200+
message(FATAL_ERROR "NBL_WITH_DOCKER works only with Windows machines. Please disable this option")
201+
endif()
202+
203+
find_program(DOCKER_EXECUTABLE docker REQUIRED)
204+
205+
if (DOCKER_EXECUTABLE)
206+
message(STATUS "Found docker executable: ${DOCKER_EXECUTABLE}")
207+
else()
208+
execute_process(COMMAND powershell -Command "& {
209+
Invoke-WebRequest -Uri https://desktop.docker.com/win/main/amd64/Docker%20Desktop%20Installer.exe -OutFile DockerDesktopInstaller.exe;
210+
$exitCode = Start-Process -Wait -FilePath .\\DockerDesktopInstaller.exe -ArgumentList 'install','--quiet','--accept-license','--backend=wsl-2','--always-run-service';
211+
Remove-Item -Force DockerDesktopInstaller.exe;
212+
exit $exitCode;
213+
}" RESULT_VARIABLE DOCKER_INSTALLER_EXIT_CODE)
214+
215+
if (DOCKER_INSTALLER_EXIT_CODE NOT EQUAL 0)
216+
message(FATAL_ERROR "Docker installer exited with non-zero return code")
217+
endif()
218+
endif()
219+
220+
# check if the docker daemon is running
221+
# DDT stands for Docker Daemon Test
222+
set(DDT_MAX_ATTEMPTS 10)
223+
set(DDT_DOCKER_RESPONDING False)
224+
foreach(ATTEMPT RANGE 1 ${DDT_MAX_ATTEMPTS})
225+
message(STATUS "Attempt ${ATTEMPT} of ${DDT_MAX_ATTEMPTS}: Checking Docker Endpoint")
226+
NBL_DOCKER(info)
227+
228+
if (DOCKER_EXIT_CODE EQUAL 0)
229+
set(DDT_DOCKER_RESPONDING True)
230+
break()
231+
endif()
232+
233+
NBL_WAIT_FOR(5)
234+
endforeach()
235+
236+
if (NOT DDT_DOCKER_RESPONDING)
237+
message(FATAL_ERROR "Docker Daemon is not responding. Please make sure it's running in the background")
238+
endif()
239+
240+
set(DNT_NETWORK_NAME "docker_default")
241+
message(STATUS "Checking wether \"${DNT_NETWORK_NAME}\" docker network exist.")
242+
NBL_DOCKER(network inspect ${DNT_NETWORK_NAME})
243+
if (NOT DOCKER_EXIT_CODE EQUAL 0)
244+
message(STATUS "Docker network \"${DNT_NETWORK_NAME}\" doesn't exist. Creating one.'")
245+
NBL_DOCKER(network create -d nat ${DNT_NETWORK_NAME})
246+
else()
247+
message(STATUS "Docker network \"${DNT_NETWORK_NAME}\" exists")
248+
endif()
249+
endif()
196250

197251
set(THIRD_PARTY_SOURCE_DIR "${PROJECT_SOURCE_DIR}/3rdparty")
198252
set(THIRD_PARTY_BINARY_DIR "${PROJECT_BINARY_DIR}/3rdparty")

cmake/common.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1334,4 +1334,13 @@ macro(NBL_TARGET_FORCE_ASSEMBLER_EXECUTABLE _NBL_TARGET_ _NBL_ASM_DIALECT_ _NBL_
13341334
TARGET_DIRECTORY "${_NBL_TARGET_}"
13351335
PROPERTIES LANGUAGE "${_NBL_ASM_DIALECT_}"
13361336
)
1337+
endmacro()
1338+
1339+
macro(NBL_WAIT_FOR SLEEP_DURATION)
1340+
execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${SLEEP_DURATION})
1341+
endmacro()
1342+
1343+
# helper macro for calling docker, takes args as a list of strings
1344+
macro(NBL_DOCKER)
1345+
execute_process(COMMAND ${DOCKER_EXECUTABLE} ${ARGN} RESULT_VARIABLE DOCKER_EXIT_CODE OUTPUT_QUIET)
13371346
endmacro()

0 commit comments

Comments
 (0)