KhronosGroup / OpenCL-SDK

OpenCL SDK
Apache License 2.0
577 stars 120 forks source link

Auto-fetch missing dependencies (console samples) #40

Closed MathiasMagnus closed 2 years ago

MathiasMagnus commented 2 years ago

This is basic dependency management implemented in CMake, primarily relying on the FetchContent module (CMake v3.11) which is capable of making the build of the subproject part of the SDK's buid (in the case of non-header-only deps). This initial work involved only the deps requried for the console samples only.

This PR allows users to self-host their dependencies (eg. using package managers) and if something is not found, they are auto-fetched by the SDK scripts.

Sample out-of-the-box experience for users not providing any deps:

cmake.exe -DBUILD_DOCS=OFF -DBUILD_TESTING=OFF -DOPENCL_SDK_BUILD_SAMPLES=ON -DOPENCL_SDK_BUILD_OPENGL_SAMPLES=OFF -Hc:/Users/mate/Source/Repos/OpenCL-SDK -Bc:/Users/mate/Source/Repos/OpenCL-SDK/.vscode/build -G "Ninja Multi-Config"
...
[cmake] -- cargs (https://github.com/likle/cargs) not found. To self-host, set cargs_INCLUDE_PATH and cargs_LIBRARY to point to the headers and library respectively adding '-D cargs_INCLUDE_PATH=/path/to/cargs/include/dir -D cargs_LIBRARY/path/to/cargs/libcargs' to the cmake command. (missing: cargs_INCLUDE_PATH cargs_LIBRARY) 
[cmake] -- Fetching cargs.
[cmake] -- Adding cargs subproject: C:/Users/mate/Source/Repos/OpenCL-SDK/.vscode/build/_deps/cargs-external-src
[cmake] -- TCLAP (http://tclap.sourceforge.net/) not found. To self-host, set TCLAP_INCLUDE_PATH to point to the headers adding '-DTCLAP_INCLUDE_PATH=/path/to/tclap' to the cmake command. (missing: TCLAP_INCLUDE_PATH) 
[cmake] -- Fetching TCLAP.
[cmake] -- Found TCLAP: C:/Users/mate/Source/Repos/OpenCL-SDK/.vscode/build/_deps/tclap-external-src/include  
[cmake] -- Stb (https://github.com/nothings/stb) not found. To self-host, set Stb_INCLUDE_PATH to point to the headers adding '-D Stb_INCLUDE_PATH=/path/to/stb' to the cmake command. (missing: Stb_INCLUDE_PATH) 
[cmake] -- Fetching Stb.
[cmake] -- Found Stb: C:/Users/mate/Source/Repos/OpenCL-SDK/.vscode/build/_deps/stb-external-src
...
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/Users/mate/Source/Repos/OpenCL-SDK/.vscode/build

Sample Vcpkg user experience:

cmake.exe -DBUILD_DOCS=OFF -DBUILD_TESTING=OFF -DOPENCL_SDK_BUILD_SAMPLES=ON -DOPENCL_SDK_BUILD_OPENGL_SAMPLES=OFF -DCMAKE_TOOLCHAIN_FILE:FILEPATH=C:\Users\mate\Source\Repos\vcpkg\scripts\buildsystems\vcpkg.cmake -DVCPKG_TARGET_TRIPLET:STRING=x64-windows -DVCPKG_CHAINLOAD_TOOLCHAIN_FILE:STRING=C:\Users\mate\Documents\MSVC-Vcpkg.cmake "-DVCPKG_C_FLAGS:STRING=/W4 /arch:AVX2" "-DVCPKG_CXX_FLAGS:STRING=/W4 /permissive- /arch:AVX2 /EHsc" -Hc:/Users/mate/Source/Repos/OpenCL-SDK -Bc:/Users/mate/Source/Repos/OpenCL-SDK/.vscode/build -G "Ninja Multi-Config"
...
[cmake] -- cargs (https://github.com/likle/cargs) not found. To self-host, set cargs_INCLUDE_PATH and cargs_LIBRARY to point to the headers and library respectively adding '-D cargs_INCLUDE_PATH=/path/to/cargs/include/dir -D cargs_LIBRARY/path/to/cargs/libcargs' to the cmake command. (missing: cargs_INCLUDE_PATH cargs_LIBRARY) 
[cmake] -- Fetching cargs.
[cmake] -- Adding cargs subproject: C:/Users/mate/Source/Repos/OpenCL-SDK/.vscode/build/_deps/cargs-external-src
[cmake] -- Found TCLAP: C:/Users/mate/Source/Repos/vcpkg/installed/x64-windows/include  
[cmake] -- Found Stb: C:/Users/mate/Source/Repos/vcpkg/installed/x64-windows/include  
...
[cmake] -- Configuring done
[cmake] -- Generating done
[cmake] -- Build files have been written to: C:/Users/mate/Source/Repos/OpenCL-SDK/.vscode/build

(Note: cargs is missing from Vcpkg, so even in this case, that needs to be autofetched. I'll likely contribute a port to the Vcpkg repo, as it's a simple project.)

When something is found, standard FindPackageHandleStandardArgs diagnostics are issued, much like when something is missing. Then users are notified of auto-fetch happening. Moreover, reconfigurations don't reissue these diagnostics to not litter the command-line.

MathiasMagnus commented 2 years ago

Superceded by #42