diff --git a/CMakeLists.txt b/CMakeLists.txt index e34551bb..6af60776 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,10 +1,14 @@ cmake_minimum_required(VERSION 3.10) +if(DEFINED CMAKE_TOOLCHAIN_FILE AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.14") + set(X_VCPKG_APPLOCAL_DEPS_INSTALL ON CACHE BOOL "Install vcpkg runtime dependencies with executables") +endif() + project ( libcimbar ) enable_testing() if (MSVC) - add_compile_options(/FI "iso646.h") + add_compile_options(/FI "iso646.h" /utf-8) endif() set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE) @@ -39,6 +43,16 @@ else() # if not wasm, go find opencv. 3 or 4 should both work include_directories(${OpenCV_INCLUDE_DIRS}) endif() +if(MSVC) + find_package(glfw3 CONFIG REQUIRED) + find_package(unofficial-angle CONFIG REQUIRED) + set(PLATFORM_GL unofficial::angle::libGLESv2 unofficial::angle::libEGL) + get_target_property(ANGLE_EGL_RELEASE_DLL unofficial::angle::libEGL IMPORTED_LOCATION_RELEASE) + get_target_property(ANGLE_EGL_DEBUG_DLL unofficial::angle::libEGL IMPORTED_LOCATION_DEBUG) +else() + set(PLATFORM_GL GL) +endif() + if(DEFINED BUILD_PORTABLE_LINUX) find_package(PkgConfig REQUIRED) pkg_check_modules(OPENCV4 REQUIRED opencv4) @@ -105,4 +119,9 @@ foreach(proj ${PROJECTS}) add_subdirectory(${proj} build/${proj}) endforeach() +if(MSVC) + install(FILES "${ANGLE_EGL_RELEASE_DLL}" DESTINATION bin CONFIGURATIONS Release RelWithDebInfo MinSizeRel) + install(FILES "${ANGLE_EGL_DEBUG_DLL}" DESTINATION bin CONFIGURATIONS Debug) +endif() + diff --git a/README.md b/README.md index 91e0bd13..c9cf0534 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,18 @@ make install By default, libcimbar will try to install build products under `./dist/bin/`. +### Windows (MSVC + vcpkg) + +Install Visual Studio with the Desktop development with C++ workload, CMake 3.14 or newer, and [vcpkg](https://github.com/microsoft/vcpkg). Set `VCPKG_ROOT` to the vcpkg checkout, then configure and build from PowerShell: + +``` +cmake -S . -B build-windows -A x64 "-DCMAKE_TOOLCHAIN_FILE=$env:VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake" +cmake --build build-windows --config Release --target cimbar_send cimbar_recv cimbar_recv2 --parallel +cmake --install build-windows --config Release +``` + +The included `vcpkg.json` installs OpenCV, GLFW, and ANGLE during configuration. The executables and their runtime DLLs are installed under `./dist/bin/`. + To build cimbar.js (what cimbar.org uses), see [WASM](WASM.md). ## Usage diff --git a/src/exe/cimbar/CMakeLists.txt b/src/exe/cimbar/CMakeLists.txt index d15b563e..9b49362b 100644 --- a/src/exe/cimbar/CMakeLists.txt +++ b/src/exe/cimbar/CMakeLists.txt @@ -23,11 +23,13 @@ target_link_libraries(cimbar ${CPPFILESYSTEM} ) -add_custom_command( - TARGET cimbar POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ cimbar.dbg - COMMAND ${CMAKE_STRIP} -g $ -) +if(NOT MSVC) + add_custom_command( + TARGET cimbar POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ cimbar.dbg + COMMAND ${CMAKE_STRIP} -g $ + ) +endif() install( TARGETS cimbar diff --git a/src/exe/cimbar_extract/CMakeLists.txt b/src/exe/cimbar_extract/CMakeLists.txt index 7c613f17..3ea49c61 100644 --- a/src/exe/cimbar_extract/CMakeLists.txt +++ b/src/exe/cimbar_extract/CMakeLists.txt @@ -18,11 +18,13 @@ target_link_libraries(cimbar_extract ${OPENCV_LIBS} ) -add_custom_command( - TARGET cimbar_extract POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ cimbar_extract.dbg - COMMAND ${CMAKE_STRIP} -g $ -) +if(NOT MSVC) + add_custom_command( + TARGET cimbar_extract POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ cimbar_extract.dbg + COMMAND ${CMAKE_STRIP} -g $ + ) +endif() install( TARGETS cimbar_extract diff --git a/src/exe/cimbar_recv/CMakeLists.txt b/src/exe/cimbar_recv/CMakeLists.txt index 8517d706..a92e4797 100644 --- a/src/exe/cimbar_recv/CMakeLists.txt +++ b/src/exe/cimbar_recv/CMakeLists.txt @@ -16,17 +16,26 @@ target_link_libraries(cimbar_recv cimbar_js extractor - GL + ${PLATFORM_GL} glfw ${OPENCV_LIBS} opencv_videoio ) -add_custom_command( - TARGET cimbar_recv POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ cimbar_recv.dbg - COMMAND ${CMAKE_STRIP} -g $ -) +if(MSVC) + add_custom_command( + TARGET cimbar_recv POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + ) +else() + add_custom_command( + TARGET cimbar_recv POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ cimbar_recv.dbg + COMMAND ${CMAKE_STRIP} -g $ + ) +endif() install( TARGETS cimbar_recv diff --git a/src/exe/cimbar_recv2/CMakeLists.txt b/src/exe/cimbar_recv2/CMakeLists.txt index 32d4a7eb..8550c97b 100644 --- a/src/exe/cimbar_recv2/CMakeLists.txt +++ b/src/exe/cimbar_recv2/CMakeLists.txt @@ -16,15 +16,29 @@ target_link_libraries(cimbar_recv2 cimbar_js extractor - GL + ${PLATFORM_GL} glfw ${OPENCV_LIBS} opencv_videoio ) -add_custom_command( - TARGET cimbar_recv2 POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ cimbar_recv2.dbg - COMMAND ${CMAKE_STRIP} -g $ +if(MSVC) + add_custom_command( + TARGET cimbar_recv2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + ) +else() + add_custom_command( + TARGET cimbar_recv2 POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ cimbar_recv2.dbg + COMMAND ${CMAKE_STRIP} -g $ + ) +endif() + +install( + TARGETS cimbar_recv2 + DESTINATION bin ) diff --git a/src/exe/cimbar_send/CMakeLists.txt b/src/exe/cimbar_send/CMakeLists.txt index f9a2ca2c..3a7f3e47 100644 --- a/src/exe/cimbar_send/CMakeLists.txt +++ b/src/exe/cimbar_send/CMakeLists.txt @@ -16,11 +16,20 @@ target_link_libraries(cimbar_send cimbar_js ) -add_custom_command( - TARGET cimbar_send POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy $ cimbar_send.dbg - COMMAND ${CMAKE_STRIP} -g $ -) +if(MSVC) + add_custom_command( + TARGET cimbar_send POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy_if_different + $ + $ + ) +else() + add_custom_command( + TARGET cimbar_send POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ cimbar_send.dbg + COMMAND ${CMAKE_STRIP} -g $ + ) +endif() install( TARGETS cimbar_send diff --git a/src/lib/cimbar_js/CMakeLists.txt b/src/lib/cimbar_js/CMakeLists.txt index 14ada453..e60f4430 100644 --- a/src/lib/cimbar_js/CMakeLists.txt +++ b/src/lib/cimbar_js/CMakeLists.txt @@ -29,6 +29,10 @@ else() ) endif() +if(MSVC) + target_compile_definitions(cimbar_js PUBLIC CIMBAR_USE_ANGLE) +endif() + target_link_libraries(cimbar_js cimb_translator @@ -111,7 +115,7 @@ if(DEFINED USE_WASM) else() # if no wasm, ignore all that and add in GLFW libraries target_link_libraries(cimbar_js - GL + ${PLATFORM_GL} glfw ) endif() diff --git a/src/lib/gui/window_glfw.h b/src/lib/gui/window_glfw.h index 091fc62a..df81e263 100644 --- a/src/lib/gui/window_glfw.h +++ b/src/lib/gui/window_glfw.h @@ -30,6 +30,13 @@ class window_glfw return; } +#ifdef CIMBAR_USE_ANGLE + glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); + glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); +#endif + _w = glfwCreateWindow(width, height, title.c_str(), NULL, NULL); if (!_w) { diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 00000000..756b23a5 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,13 @@ +{ + "name": "libcimbar", + "version-string": "0.6.7c", + "builtin-baseline": "ddd110b8a05cda14b8f1b0333a1d80c4fb6f16cd", + "dependencies": [ + { + "name": "angle", + "platform": "windows & !mingw" + }, + "glfw3", + "opencv4" + ] +}