[DO-981] qt package (!15)
Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/15
This commit is contained in:
31
recipes/opengl/all/test_package/CMakeLists.txt
Normal file
31
recipes/opengl/all/test_package/CMakeLists.txt
Normal file
@@ -0,0 +1,31 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
project(test_package)
|
||||
|
||||
find_package(opengl_system REQUIRED CONFIG)
|
||||
|
||||
set(SOURCES test_package.cpp)
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND SOURCES win.cpp)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
list(APPEND SOURCES osx.mm)
|
||||
set_source_files_properties(osx.mm PROPERTIES COMPILE_FLAGS "-x objective-c++")
|
||||
|
||||
list(APPEND PLATFORM_LIBS "objc")
|
||||
|
||||
find_library(APPKIT_LIBRARY AppKit)
|
||||
find_library(FOUNDATION_LIBRARY Foundation)
|
||||
|
||||
if(APPKIT_LIBRARY)
|
||||
list(APPEND PLATFORM_LIBS ${APPKIT_LIBRARY})
|
||||
endif()
|
||||
|
||||
if(FOUNDATION_LIBRARY)
|
||||
list(APPEND PLATFORM_LIBS ${FOUNDATION_LIBRARY})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE opengl::opengl ${PLATFORM_LIBS})
|
||||
10
recipes/opengl/all/test_package/CMakeUserPresets.json
Normal file
10
recipes/opengl/all/test_package/CMakeUserPresets.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"version": 4,
|
||||
"vendor": {
|
||||
"conan": {}
|
||||
},
|
||||
"include": [
|
||||
"build/gcc-12-x86_64-gnu17-release/generators/CMakePresets.json",
|
||||
"build/gcc-11.5-x86_64-17-release/generators/CMakePresets.json"
|
||||
]
|
||||
}
|
||||
26
recipes/opengl/all/test_package/conanfile.py
Normal file
26
recipes/opengl/all/test_package/conanfile.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from conan import ConanFile
|
||||
from conan.tools.build import can_run
|
||||
from conan.tools.cmake import cmake_layout, CMake
|
||||
import os
|
||||
|
||||
|
||||
class TestPackageConan(ConanFile):
|
||||
settings = "os", "arch", "compiler", "build_type"
|
||||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
|
||||
test_type = "explicit"
|
||||
|
||||
def layout(self):
|
||||
cmake_layout(self)
|
||||
|
||||
def requirements(self):
|
||||
self.requires(self.tested_reference_str)
|
||||
|
||||
def build(self):
|
||||
cmake = CMake(self)
|
||||
cmake.configure()
|
||||
cmake.build()
|
||||
|
||||
def test(self):
|
||||
if can_run(self):
|
||||
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
|
||||
self.run(bin_path, env="conanrun")
|
||||
31
recipes/opengl/all/test_package/osx.mm
Normal file
31
recipes/opengl/all/test_package/osx.mm
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "TargetConditionals.h"
|
||||
|
||||
#if TARGET_OS_TV || TARGET_OS_WATCH || TARGET_OS_IPHONE
|
||||
#else
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#endif
|
||||
|
||||
bool init_context()
|
||||
{
|
||||
#if TARGET_OS_TV || TARGET_OS_WATCH || TARGET_OS_IPHONE
|
||||
return true;
|
||||
#else
|
||||
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
|
||||
{
|
||||
NSOpenGLPFAColorSize, 24,
|
||||
NSOpenGLPFAAlphaSize, 8,
|
||||
NSOpenGLPFADoubleBuffer,
|
||||
0
|
||||
};
|
||||
NSOpenGLPixelFormat *pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes];
|
||||
if (!pixelFormat)
|
||||
return false;
|
||||
|
||||
NSOpenGLContext *context = [[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil];
|
||||
if (!context)
|
||||
return false;
|
||||
[context makeCurrentContext];
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
47
recipes/opengl/all/test_package/test_package.cpp
Normal file
47
recipes/opengl/all/test_package/test_package.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <OpenGL/gl.h>
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#if defined(__linux__) or defined(__FreeBSD__)
|
||||
|
||||
bool init_context() { return true; }
|
||||
|
||||
#endif
|
||||
|
||||
#include <GL/gl.h>
|
||||
|
||||
#endif
|
||||
|
||||
bool init_context();
|
||||
|
||||
int main()
|
||||
{
|
||||
if (!init_context())
|
||||
{
|
||||
// std::cerr << "failed to initialize OpenGL context!" << std::endl;
|
||||
// return -1;
|
||||
|
||||
// Don't fail if we can't init the context - won't work on a headless CI
|
||||
// Instead, if we made it this far, then we were able to #include and link,
|
||||
// count that as a success!
|
||||
std::cout << "Linked test, but failed to initialize OpenGL context (headless platform?)" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
const char * gl_vendor = (const char *) glGetString(GL_VENDOR);
|
||||
const char * gl_renderer = (const char *) glGetString(GL_RENDERER);
|
||||
const char * gl_version = (const char *) glGetString(GL_VERSION);
|
||||
const char * gl_extensions = (const char *) glGetString(GL_EXTENSIONS);
|
||||
std::cout << "GL_VENDOR: " << (gl_vendor ? gl_vendor : "(null)") << std::endl;
|
||||
std::cout << "GL_RENDERER: " << (gl_renderer ? gl_renderer : "(null)") << std::endl;
|
||||
std::cout << "GL_VERSION: " << (gl_version ? gl_version : "(null)") << std::endl;
|
||||
std::cout << "GL_EXTENSIONS: " << (gl_extensions ? gl_extensions : "(null)") << std::endl;
|
||||
return 0;
|
||||
}
|
||||
58
recipes/opengl/all/test_package/win.cpp
Normal file
58
recipes/opengl/all/test_package/win.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include <windows.h>
|
||||
|
||||
static LRESULT CALLBACK WndProc(HWND hwnd,
|
||||
UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
LRESULT res = 1;
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_DESTROY:
|
||||
::PostQuitMessage (0);
|
||||
break;
|
||||
default:
|
||||
res = ::DefWindowProc(hwnd, uMsg, wParam, lParam);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
bool init_context()
|
||||
{
|
||||
static const wchar_t * class_name = L"ConanOpenGL";
|
||||
static const wchar_t * window_name = L"Conan OpenGL";
|
||||
WNDCLASSEXW wc = {0};
|
||||
wc.cbSize = sizeof(WNDCLASSEXW);
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = ::GetModuleHandle(NULL);
|
||||
wc.hIcon = ::LoadIcon(0, IDI_APPLICATION);
|
||||
wc.hCursor = ::LoadCursor(0, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH) ::GetStockObject(WHITE_BRUSH);
|
||||
wc.lpszClassName = class_name;
|
||||
if (!::RegisterClassExW(&wc))
|
||||
return false;
|
||||
HWND hWnd = ::CreateWindowExW(0, class_name, window_name,
|
||||
WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, wc.hInstance, NULL);
|
||||
if (!hWnd)
|
||||
return false;
|
||||
HDC hDC = ::GetDC(hWnd);
|
||||
if (!hDC)
|
||||
return false;
|
||||
PIXELFORMATDESCRIPTOR pfd = {0};
|
||||
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.dwLayerMask = PFD_MAIN_PLANE;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cDepthBits = 16;
|
||||
int pixel_format = ::ChoosePixelFormat(hDC, &pfd);
|
||||
if(0 == pixel_format)
|
||||
return false;
|
||||
if (!::SetPixelFormat(hDC, pixel_format, &pfd))
|
||||
return false;
|
||||
HGLRC hGLRC = ::wglCreateContext(hDC);
|
||||
if (!hGLRC)
|
||||
return false;
|
||||
::wglMakeCurrent(hDC, hGLRC);
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user