Skip to content

Add support for building with CMake #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ generated_proto/
demoinfogo.exe
demoinfogo.opensdf
protobuf-2.5.0/
test.dem
test.dem
/out
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.19)

project(csgo-demoinfo)

find_package(protobuf CONFIG REQUIRED)

add_subdirectory(demoinfogo)
42 changes: 42 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": 4,
"configurePresets": [
{
"name": "base",
"hidden": true,
"generator": "Ninja",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"CMAKE_C_COMPILER": "cl",
"CMAKE_CXX_COMPILER": "cl",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_PREFIX_PATH": "${sourceDir}/vendor/out/protobuf/${presetName};",
"CMAKE_EXPORT_COMPILE_COMMANDS": true
}
},
{
"name": "Debug",
"inherits": [
"base"
],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreadedDebug"
}
},
{
"name": "Release",
"inherits": [
"base"
],
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded"
}
}
]
}
46 changes: 46 additions & 0 deletions demoinfogo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Build protocol buffers.
#
add_library(demoinfogo-proto OBJECT STATIC
"${CMAKE_CURRENT_LIST_DIR}/cstrike15_usermessages_public.proto"
"${CMAKE_CURRENT_LIST_DIR}/netmessages_public.proto"
)

target_link_libraries(demoinfogo-proto PUBLIC protobuf::libprotobuf)

set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_proto")

target_include_directories(demoinfogo-proto PUBLIC "$<BUILD_INTERFACE:${PROTO_BINARY_DIR}>")

protobuf_generate(
TARGET demoinfogo-proto
IMPORT_DIRS "${CMAKE_CURRENT_LIST_DIR}"
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}"
)

# Build the executable.
#
add_executable(demoinfogo
demofile.cpp
demofile.h

demofilebitbuf.cpp
demofilebitbuf.h

demofiledump.cpp
demofiledump.h

demofilepropdecode.cpp
demofilepropdecode.h

demoinfogo.cpp
)

target_include_directories(demoinfogo PUBLIC ${CMAKE_CURRENT_LIST_DIR} ${CMAKE_CURRENT_BINARY_DIR})

target_link_libraries(demoinfogo demoinfogo-proto)

# Install the executable.
#
install(TARGETS demoinfogo
RUNTIME DESTINATION "bin"
)
33 changes: 32 additions & 1 deletion demoinfogo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Demos and network messages in CS:GO use Google's Protocol Buffers (protobuf). Pr
Building demoinfogo
-------------------

### Windows
### Windows

In order to build demoinfogo on Windows, follow these steps:

Expand All @@ -19,6 +19,37 @@ In order to build demoinfogo on Windows, follow these steps:
5. Open `demoinfogo/demoinfogo.vcxproj` in Microsoft Visual Studio 2010. Building the Release configuration creates the binary `demoinfogo/demoinfogo.exe`


### CMake on Windows

Build and install the following libraries using CMake.

* protobuf v21.12: https://github.com/protocolbuffers/protobuf/releases/tag/v21.12. **Note:** You can build with `-Dprotobuf_WITH_ZLIB=OFF` as ZLIB support is not needed.*

These libraries must be installed into `csgo-demoinfo/vendor/out/{library name}/{preset name}`. For example:

```
csgo-demoinfogo/
...
vendor/
out/
protobuf/
Release/
Debug/
```

To build `demoinfogo` with CMake (in `Release` mode), open a Visual Studio developer console and follow these steps:

```
cmake --preset Release
cmake --build out/build/Release --target install
```

The program can be invoked with:

```
.\out\install\Release\bin\demoinfogo.exe
```

Working with Network Messages
-----------------------------

Expand Down
2 changes: 2 additions & 0 deletions demoinfogo/cstrike15_usermessages_public.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
//
//=============================================================================

syntax = "proto2";

// We care more about speed than code size
option optimize_for = SPEED;

Expand Down
3 changes: 2 additions & 1 deletion demoinfogo/netmessages_public.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
// There is an important difference between the signed int types (sint32 and sint64)
// and the "standard" int types (int32 and int64) when it comes to encoding negative
// numbers. If you use int32 or int64 as the type for a negative number, the
// resulting varint is always ten bytes long it is, effectively, treated like a
// resulting varint is always ten bytes long - it is, effectively, treated like a
// very large unsigned integer. If you use one of the signed types, the resulting
// varint uses ZigZag encoding, which is much more efficient.

syntax = "proto2";

// Commenting this out allows it to be compiled for SPEED or LITE_RUNTIME.
// option optimize_for = SPEED;
Expand Down