Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# The directory I like to build under
# Common build directories
/build
/build_x64
/build_x86

# Distribution directories
/dist
/syms

# Dependencies that are downloaded/installed separately
/thirdparty/cef3/*
/thirdparty/cef3/**
!/thirdparty/cef3/README.txt

# IDE files
/.vscode
/.idea

# Misc OS files
**/.DS_Store

# direnv
/.direnv
115 changes: 55 additions & 60 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,99 +1,94 @@
cmake_minimum_required(VERSION 3.15)

# Required for MSVC_RUNTIME_LIBRARY
if(WIN32)
# Required for MSVC_RUNTIME_LIBRARY
cmake_minimum_required(VERSION 3.15)
cmake_policy(SET CMP0091 NEW)
else()
cmake_minimum_required(VERSION 2.8.7)
endif()

project(gmod-html LANGUAGES CXX)
project(gmod_html)

# We can only do release builds
set(CMAKE_CONFIGURATION_TYPES Release Debug)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Match GMod and our prebuilt libraries
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set_property(GLOBAL PROPERTY OS_FOLDERS ON)

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/bin CACHE PATH "..." FORCE)
endif()
set(CEF_VERSION "86.0.24+g85e79d4+chromium-86.0.4240.198")

if(WIN32)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
set(GAME_BIN_DIR .)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
if("${PROJECT_ARCH}" STREQUAL "arm64")
set(CEF_PLATFORM "macosarm64")
else()
set(GAME_BIN_DIR win64)
set(CEF_PLATFORM "macosx64")
endif()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
if(CMAKE_SIZEOF_VOID_P MATCHES 8)
set(CEF_PLATFORM "linux64")
else()
set(CEF_PLATFORM "linux32")
endif()
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
if(CMAKE_SIZEOF_VOID_P MATCHES 8)
set(CEF_PLATFORM "windows64")
else()
set(CEF_PLATFORM "windows32")
endif()
elseif(UNIX AND NOT APPLE)
set(GAME_BIN_DIR linux64)
else()
message(FATAL_ERROR "No GAME_DIR definition")
endif()

# Kind of lame but I'm having PDB timestamp mismatches
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/${GAME_BIN_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/bin/${GAME_BIN_DIR})
set (CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/${GAME_BIN_DIR})
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin/${GAME_BIN_DIR})
# glad
add_subdirectory(thirdparty/glad EXCLUDE_FROM_ALL)

# ImGui
add_subdirectory(thirdparty/imgui-1.74)

# glad
add_subdirectory(thirdparty/glad)
add_subdirectory(thirdparty/imgui-1.74 EXCLUDE_FROM_ALL)

# GLFW
set(GLFW_INSTALL OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(thirdparty/glfw-3.3.2)
add_subdirectory(thirdparty/glfw-3.3.2 EXCLUDE_FROM_ALL)

# Chromium Project
if(WIN32)
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "4")
set(CEF_PATH ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cef3/cef_binary_80.0.4+g74f7b0c+chromium-80.0.3987.122_windows32)
else()
set(CEF_PATH ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cef3/cef_binary_80.0.4+g74f7b0c+chromium-80.0.3987.122_windows64)
endif()
elseif(UNIX AND NOT APPLE)
set(CEF_PATH ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cef3/cef_binary_80.0.4+g74f7b0c+chromium-80.0.3987.122_linux64)
add_definitions(-DPOSIX -DLINUX)
else()
message(FATAL_ERROR "No CEF_PATH")
endif()
set(CEF_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/cef3/cef_binary_${CEF_VERSION}_${CEF_PLATFORM}")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CEF_ROOT}/cmake")

add_subdirectory(${CEF_PATH} EXCLUDE_FROM_ALL)
# OS_WINDOWS, OS_LINUX, and OS_MAC are defined in cef_variables.cmake
find_package(CEF REQUIRED)

# Chromium Import Lib
add_library(libcef_imp SHARED IMPORTED)

if(WIN32)
set_target_properties(libcef_imp PROPERTIES IMPORTED_LOCATION ${CEF_PATH}/Release/libcef.dll)
set_target_properties(libcef_imp PROPERTIES IMPORTED_IMPLIB ${CEF_PATH}/Release/libcef.lib)
elseif(UNIX AND NOT APPLE)
set_target_properties(libcef_imp PROPERTIES IMPORTED_LOCATION ${CEF_PATH}/Release/libcef.so)
if(GEN_NINJA OR GEN_MAKEFILES)
set(CEF_TARGET_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/out/${CMAKE_BUILD_TYPE}/${CEF_PLATFORM}")
set(INSTALL_OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dist/${CEF_PLATFORM}-${CMAKE_BUILD_TYPE}")
else()
message(FATAL_ERROR "No libcef_imp import library set")
set(CEF_TARGET_OUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/out/$<CONFIGURATION>/${CEF_PLATFORM}")
set(INSTALL_OUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/dist/${CEF_PLATFORM}-$<CONFIGURATION>")
endif()
set(CEF_TARGET_OUT_DIR ${CEF_TARGET_OUT_DIR}/bin/${CEF_PLATFORM})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CEF_TARGET_OUT_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CEF_TARGET_OUT_DIR})

# Chromium Sandbox
add_library(cef_sandbox STATIC IMPORTED)
add_subdirectory(${CEF_LIBCEF_DLL_WRAPPER_PATH} libcef_dll_wrapper EXCLUDE_FROM_ALL)

if(WIN32)
set_target_properties(cef_sandbox PROPERTIES IMPORTED_LOCATION ${CEF_PATH}/Release/cef_sandbox.lib)
else()
message(FATAL_ERROR "No cef_sandbox library set")
endif()
add_subdirectory(${CEF_ROOT}/tests/cefclient EXCLUDE_FROM_ALL)
add_subdirectory(${CEF_ROOT}/tests/cefsimple EXCLUDE_FROM_ALL)
add_subdirectory(${CEF_ROOT}/tests/gtest EXCLUDE_FROM_ALL)
add_subdirectory(${CEF_ROOT}/tests/ceftests EXCLUDE_FROM_ALL)

include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# Match GMod and our prebuilt libraries
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

# Our projects
add_subdirectory(example_host)
add_subdirectory(html)
add_subdirectory(html_stub)
add_subdirectory(html_stub EXCLUDE_FROM_ALL)
add_subdirectory(html_chromium)

if(UNIX)
if(OS_LINUX OR OS_MAC)
add_subdirectory(html_chromium/chromium_process)
endif()

# Disabled for now
#add_subdirectory(example_host EXCLUDE_FROM_ALL)

PRINT_CEF_CONFIG()
51 changes: 37 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
This is pretty much just an abstraction layer around The Chromium Embedded Framework (https://bitbucket.org/chromiumembedded/cef)

## Chromium Embedded Framework Binary Distribution
To work with this project you will need a build of the Chromium Embedded Framework. You can download the builds used by Garry's Mod here if you don't want to compile your own:
To work with this project you will need a build of the Chromium Embedded Framework. You can download prebuilt versions of CEF from Spotify's Automated Builder if you don't want to compile your own:

| Platform | URL |
| -------- | --- |
| Windows x86 | https://files.facepunch.com/willox/7bb55f57-7c70-4140-83d7-2d61d8b57816/cef_binary_80.0.4%2Bg74f7b0c%2Bchromium-80.0.3987.122_windows32.tar.bz2 |
| Windows x64 | https://files.facepunch.com/willox/14ceed65-8809-4fba-97a7-2d524b6d45ec/cef_binary_80.0.4%2Bg74f7b0c%2Bchromium-80.0.3987.122_windows64.tar.bz2 |
| Linux x64 | https://files.facepunch.com/willox/dfd5d7fe-2184-40a9-90b0-49f9eef9a9b5/cef_binary_80.0.4%2Bg74f7b0c%2Bchromium-80.0.3987.122_linux64.tar.bz2 |
| macOS x64 | https://files.facepunch.com/willox/17e19274-4112-4734-ac20-22cd8644bcb4/cef_binary_80.0.4%2Bg74f7b0c%2Bchromium-80.0.3987.122_macosx64.tar.bz2 |
https://cef-builds.spotifycdn.com/index.html

These belong in the `./thirdparty/cef3/` directory (after extraction.) The paths are currently hardcoded into the root `CMakelists.txt` file.
Everything you need is in the **Standard Distribution**. If you need to debug the CEF part, grab the Symbols too. The extracted binary folder belongs in the `./thirdparty/cef3/` directory. The paths are currently hardcoded into the root `CMakelists.txt` file.

## Currently supported CEF version
The current version of CEF that's supported by this library is:

- **86.0.24+g85e79d4+chromium-86.0.4240.198**

This is not the only version that could be supported, but it's the version that's currently configured and tested to work.

## Getting started
### Windows
Expand All @@ -32,28 +34,49 @@ cd build_x64
cmake -G "Visual Studio 16 2019" -A x64 ..
```

After running either of these sets of commands, you can enter your created directory and open the `gmod-html.sln` solution in Visual Studio. Compiling the `INSTALL` project will place a complete build into `<your_build_dir>/bin` by default.
After running either of these sets of commands, you can enter your created directory and open the `gmod-html.sln` solution in Visual Studio. Compiling the `INSTALL` project will place a complete build into the `dist/` folder by default.

If you only have VS Build Tools, use this command in "Developer Command Prompt for VS 2019":
```
msbuild /p:Configuration=Release INSTALL.vcxproj
```

### Linux
#### Requirements
- A version of GCC/G++ or Clang/Clang++ with C++11 support
- CMake 2.8.7 or newer
- CMake 3.15 or newer

#### Compiling
```sh
mkdir build
cd build
cmake -G "Unix Makefiles" ..
cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_POLICY_VERSION_MINIMUM=3.5 ..
make && make install
```

This will place a complete build into `build/bin` by default.
This will place a complete build into the `dist` folder by default.

### macOS
Todo
#### Requirements
- Ninja
- CMake 3.15 or newer

#### Compiling
```sh
mkdir build
cd build
cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -D CMAKE_POLICY_VERSION_MINIMUM=3.5 ..
ninja && ninja install
```

##### Apple Silicon
```sh
cmake -G Ninja -D CMAKE_BUILD_TYPE=Release -D CMAKE_POLICY_VERSION_MINIMUM=3.5 -D CMAKE_APPLE_SILICON_PROCESSOR=x86_64 ..
```

This will place a complete build into the `dist` folder by default.

## TODO
- Improve the CMake files. We don't use them for GMod builds so they're a bit wonky.
- Get the example_host into workable condition. It's disabled at the moment
- Cleanup. Everything is quite messy.
- macOS. These builds require quite a few unique things so they're not handled by the CMake scripts at all at the moment. It's still technically possible to get the builds working, though.
Expand Down
39 changes: 9 additions & 30 deletions example_host/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set(TARGET example_host)
set(SOURCES
Main.cpp
Window.cpp
Expand All @@ -9,36 +10,14 @@ set(SOURCES
HtmlPanel.cpp
HtmlPanel.h)

if(WIN32)
set(SOURCES
${SOURCES}
../html_chromium/chromium_process/ChromiumApp.cpp
../html_chromium/chromium_process/ChromiumApp.h
../html_chromium/chromium_process/Windows.cpp)
endif()

# Lame
include_directories(${CEF_PATH})
add_executable(${TARGET} ${SOURCES})
SET_EXECUTABLE_TARGET_PROPERTIES(${TARGET})

add_executable(example_host WIN32 ${SOURCES})
target_link_libraries(example_host glfw glad imgui html libcef_imp libcef_dll_wrapper)
target_link_libraries(example_host optimized cef_sandbox)
add_dependencies(${TARGET} html_chromium html chromium_process glfw glad imgui)
target_compile_definitions(${TARGET} PRIVATE IMGUI_IMPL_OPENGL_LOADER_GLAD)
target_link_libraries(${TARGET} glfw glad imgui html)

if(WIN32)
target_link_libraries(example_host
shlwapi
winmm
wsock32
comctl32
rpcrt4
version
DbgHelp
Psapi
wbemuuid
OleAut32
SetupAPI
Propsys
Cfgmgr32
PowrProf
Delayimp.lib)
if(OS_LINUX)
set_target_properties(${TARGET} PROPERTIES INSTALL_RPATH "$ORIGIN")
set_target_properties(${TARGET} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE)
endif()
9 changes: 6 additions & 3 deletions html/html/JSValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class JSValue

JSValue()
: _type( Type::Undefined )
, _bool( false )
{}

JSValue( bool value )
Expand Down Expand Up @@ -79,6 +80,7 @@ class JSValue

JSValue( const JSValue& other )
: _type( other._type )
, _bool( false )
{
switch ( _type )
{
Expand All @@ -104,6 +106,7 @@ class JSValue

JSValue( JSValue&& other ) noexcept
: _type( other._type )
, _bool( false )
{
switch ( _type )
{
Expand Down Expand Up @@ -237,17 +240,17 @@ class JSValue

//

const bool HashMap_Begin( const char*& pKey, size_t& keySize, const JSValue*& pValue ) const
bool HashMap_Begin( const char*& pKey, size_t& keySize, const JSValue*& pValue ) const
{
return _pHashMap->Begin( pKey, keySize, pValue );
}

const bool HashMap_Next( const char*& pKey, size_t& keySize, const JSValue*& pValue ) const
bool HashMap_Next( const char*& pKey, size_t& keySize, const JSValue*& pValue ) const
{
return _pHashMap->Next( pKey, keySize, pValue );
}

const size_t HashMap_Size() const
size_t HashMap_Size() const
{
return _pHashMap->Size();
}
Expand Down
Loading