Skip to content

Commit 5959979

Browse files
Fix UtilsCpp debug install (#50)
* Add utility lib config postfix * Add consumtion test of utility libraries * Use image Vcpkg * Fix util func invocation
1 parent ff44fc3 commit 5959979

6 files changed

Lines changed: 129 additions & 7 deletions

File tree

.github/workflows/presubmit.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ jobs:
8383
shell: pwsh
8484
run: |
8585
if ('${{ matrix.deps }}' -eq 'vcpkg') {
86-
git clone https://github.com/Microsoft/vcpkg.git
87-
.\vcpkg\bootstrap-vcpkg.bat
88-
.\vcpkg\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb
89-
$TOOLCHAIN_ARG='-D CMAKE_TOOLCHAIN_FILE=.\vcpkg\scripts\buildsystems\vcpkg.cmake'
86+
Get-ChildItem Env:\
87+
& ${env:VCPKG_ROOT}\vcpkg.exe --triplet=x64-windows install sfml tclap glm glew stb
88+
$TOOLCHAIN_ARG="-D CMAKE_TOOLCHAIN_FILE=${env:VCPKG_ROOT}\scripts\buildsystems\vcpkg.cmake"
9089
} else {
9190
$TOOLCHAIN_ARG=''
9291
}

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ foreach(UTIL_LIB_NAME IN ITEMS Utils UtilsCpp)
5555
INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
5656
FOLDER "Libraries/${UTIL_LIB_NAME}"
5757
EXPORT_NAME ${UTIL_LIB_NAME}
58+
DEBUG_POSTFIX d
5859
)
5960

6061
install(

test/cmake/pkgconfig/CMakeLists.txt renamed to test/cmake/pkgconfig/platformenum/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.0)
22

3-
project(PkgConfigTest)
3+
project(PkgConfigTest-PlatformEnum)
44

55
find_package(OpenCL
66
REQUIRED
@@ -14,7 +14,7 @@ find_package(OpenCL
1414
# Test consuming from C++ source files
1515

1616
add_executable(${PROJECT_NAME}_cpp
17-
../platformenum.cpp
17+
../../platformenum.cpp
1818
)
1919

2020
target_link_libraries(${PROJECT_NAME}_cpp
@@ -38,7 +38,7 @@ add_test(
3838
# Test consuming from C source files
3939

4040
add_executable(${PROJECT_NAME}_c
41-
../platformenum.c
41+
../../platformenum.c
4242
)
4343

4444
target_link_libraries(${PROJECT_NAME}_c
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
cmake_minimum_required(VERSION 3.0)
2+
3+
project(PkgConfigTest-UseUtil)
4+
5+
find_package(OpenCL
6+
REQUIRED
7+
CONFIG
8+
COMPONENTS
9+
Utils
10+
UtilsCpp
11+
HeadersCpp
12+
Headers
13+
OpenCL
14+
)
15+
16+
# Test consuming from C++ source files
17+
18+
add_executable(${PROJECT_NAME}_cpp
19+
../../useutil.cpp
20+
)
21+
22+
target_link_libraries(${PROJECT_NAME}_cpp
23+
PRIVATE
24+
OpenCL::UtilsCpp
25+
OpenCL::HeadersCpp
26+
OpenCL::Headers
27+
OpenCL::OpenCL
28+
)
29+
30+
target_compile_definitions(${PROJECT_NAME}_cpp
31+
PRIVATE
32+
CL_HPP_ENABLE_EXCEPTIONS
33+
CL_HPP_TARGET_OPENCL_VERSION=300
34+
)
35+
36+
add_test(
37+
NAME ${PROJECT_NAME}_cpp
38+
COMMAND ${PROJECT_NAME}_cpp
39+
)
40+
41+
# Test consuming from C source files
42+
43+
add_executable(${PROJECT_NAME}_c
44+
../../useutil.c
45+
)
46+
47+
target_link_libraries(${PROJECT_NAME}_c
48+
PRIVATE
49+
OpenCL::Utils
50+
OpenCL::Headers
51+
OpenCL::OpenCL
52+
)
53+
54+
target_compile_definitions(${PROJECT_NAME}_c
55+
PRIVATE
56+
CL_TARGET_OPENCL_VERSION=300
57+
)
58+
59+
add_test(
60+
NAME ${PROJECT_NAME}_c
61+
COMMAND ${PROJECT_NAME}_c
62+
)

test/cmake/useutil.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// OpenCL includes
2+
#include <CL/cl.h>
3+
4+
// C standard includes
5+
#include <stdio.h>
6+
7+
#ifdef _MSC_VER
8+
#define print(...) printf_s(__VA_ARGS__)
9+
#else
10+
#define print(...) printf(__VA_ARGS__)
11+
#endif
12+
13+
int main()
14+
{
15+
cl_int CL_err = CL_SUCCESS;
16+
cl_uint numPlatforms = 0;
17+
18+
CL_err = clGetPlatformIDs(0, NULL, &numPlatforms);
19+
20+
if (CL_err == CL_SUCCESS)
21+
print("%u platform(s) found\n", numPlatforms);
22+
else
23+
print("clGetPlatformIDs(%i)\n", CL_err);
24+
25+
return 0;
26+
}

test/cmake/useutil.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <CL/opencl.hpp>
2+
3+
#include <CL/Utils/Utils.hpp>
4+
5+
#include <vector> // std::vector
6+
#include <exception> // std::runtime_error, std::exception
7+
#include <iostream> // std::cout
8+
#include <cstdlib> // EXIT_FAILURE
9+
10+
int main(int argc, char* argv[])
11+
{
12+
try
13+
{
14+
cl::Context context = cl::util::get_context(
15+
argc > 1 ? std::atoi(argv[1]) : 0,
16+
argc > 2 ? std::atoi(argv[2]) : 0, CL_DEVICE_TYPE_ALL);
17+
} catch (cl::Error& error) // If any OpenCL error occurs
18+
{
19+
if (error.err() == CL_PLATFORM_NOT_FOUND_KHR)
20+
{
21+
std::cout << "No OpenCL platform found." << std::endl;
22+
std::exit(EXIT_SUCCESS);
23+
}
24+
else
25+
{
26+
std::cerr << error.what() << "(" << error.err() << ")" << std::endl;
27+
std::exit(error.err());
28+
}
29+
} catch (std::exception& error) // If STL/CRT error occurs
30+
{
31+
std::cerr << error.what() << std::endl;
32+
std::exit(EXIT_FAILURE);
33+
}
34+
}

0 commit comments

Comments
 (0)