Skip to content

Commit

Permalink
Merge pull request #711 from Nopey/headers
Browse files Browse the repository at this point in the history
Precompiled Headers & Faster CI
  • Loading branch information
Vagabond authored Nov 2, 2024
2 parents 9ba9ee4 + 6574686 commit 95b33e5
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 35 deletions.
34 changes: 18 additions & 16 deletions .github/workflows/compilation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Install clang-format and fd-find
run: |
sudo apt-get update
sudo apt-get -y install clang-format-${{ env.clang-format-version }} fd-find
uses: Eeems-Org/[email protected]
with:
packages: clang-format-${{ env.clang-format-version }} fd-find
- name: Run clang-format style check
run: |
fdfind . -e .c -e .h -X clang-format-${{ env.clang-format-version }} --dry-run --Werror
Expand All @@ -44,18 +44,18 @@ jobs:
fail-fast: false
matrix:
config:
- { name: "gcc 14", cc: gcc-14, tidy: "On" }
- { name: "clang 16", cc: clang-16, tidy: "Off" }
- { name: "gcc 14", cc: gcc-14, tidy: "Off" }
- { name: "clang 18", cc: clang-18, tidy: "On" }

steps:
- uses: actions/checkout@v4

- name: Install Ubuntu Dependencies
run: |
sudo apt-get update
sudo apt-get -y install cmake cmake-data libargtable2-dev libcunit1-dev \
libsdl2-mixer-dev libconfuse-dev libenet-dev libsdl2-dev libxmp-dev libpng-dev \
libepoxy-dev clang-tidy ${{ matrix.config.cc }}
uses: Eeems-Org/[email protected]
with:
packages: cmake cmake-data libargtable2-dev libcunit1-dev
libsdl2-mixer-dev libconfuse-dev libenet-dev libsdl2-dev libxmp-dev libpng-dev
libepoxy-dev clang-tidy-18 ${{ matrix.config.cc }}

- name: Build tests
run: |
Expand Down Expand Up @@ -166,9 +166,9 @@ jobs:
- uses: actions/checkout@v4

- name: Install Ubuntu Dependencies
run: |
sudo apt-get update
sudo apt-get -y install cmake libargtable2-dev libcunit1-dev libsdl2-mixer-dev \
uses: Eeems-Org/[email protected]
with:
packages: cmake libargtable2-dev libcunit1-dev libsdl2-mixer-dev
libconfuse-dev libenet-dev libsdl2-dev libxmp-dev libpng-dev libepoxy-dev

- name: Generate Release
Expand Down Expand Up @@ -305,10 +305,12 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install apt Dependencies
uses: Eeems-Org/[email protected]
with:
packages: mingw-w64 unzip
- name: Install Dependencies
run: |
sudo apt-get update
sudo apt-get -y install mingw-w64 unzip
wget -q https://github.com/omf2097/openomf-win-build/archive/refs/heads/main.zip
unzip -q main.zip && rm main.zip
Expand Down
39 changes: 35 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.7.2)
cmake_minimum_required(VERSION 3.16)
project(OpenOMF C)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake-scripts)

Expand All @@ -17,6 +17,20 @@ OPTION(USE_SANITIZERS "Enable Asan and Ubsan" OFF)
OPTION(USE_TIDY "Use clang-tidy for checks" OFF)
OPTION(USE_FORMAT "Use clang-format for checks" OFF)

set(USE_PCH ON)
# clang-tidy only works with clang when PCH is enabled
if(USE_PCH AND USE_TIDY AND NOT CMAKE_C_COMPILER_ID MATCHES ".*Clang")
message(WARNING "clang-tidy cannot consume precompiled headers from non-clang compiler. Disabling PCH at the cost of higher build times.")
set(USE_PCH OFF)
endif()

function(omf_target_precompile_headers)
if(NOT USE_PCH)
return()
endif()
target_precompile_headers(${ARGN})
endfunction()

# These flags are used for all builds
set(CMAKE_C_STANDARD 11)
if(MSVC)
Expand All @@ -35,9 +49,15 @@ add_definitions(-DV_MAJOR=${VERSION_MAJOR} -DV_MINOR=${VERSION_MINOR} -DV_PATCH=

# Enable AddressSanitizer if requested
if(USE_SANITIZERS)
add_compile_options("-fsanitize=address,undefined")
add_link_options("-fsanitize=address,undefined")
message(STATUS "Development: Asan and Ubsan enabled")
if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
add_compile_options("-fsanitize=address")
add_link_options("-fsanitize=address")
message(STATUS "Development: Asan enabled. Ubsan is unsupported by MSVC.")
else()
add_compile_options("-fsanitize=address,undefined")
add_link_options("-fsanitize=address,undefined")
message(STATUS "Development: Asan and Ubsan enabled")
endif()
else()
message(STATUS "Development: Asan and Ubsan disabled")
endif()
Expand Down Expand Up @@ -173,8 +193,19 @@ include_directories(${COREINCS})
# this can then be reused in tests and main executable to speed things up
add_library(openomf_core OBJECT ${OPENOMF_SRC})
target_link_libraries(openomf_core PRIVATE ${XMP_LIBRARY})
omf_target_precompile_headers(openomf_core PUBLIC
"<SDL.h>"
"<enet/enet.h>"
"<epoxy/gl.h>"
)
set(CORELIBS openomf_core ${CORELIBS})

if(WIN32 AND NOT MINGW)
omf_target_precompile_headers(openomf_core PUBLIC
"<windows.h>"
)
endif()

# Set icon for windows executable
if(WIN32)
SET(ICON_RESOURCE "resources/icons/openomf.rc")
Expand Down
16 changes: 7 additions & 9 deletions src/game/utils/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,16 @@
#define SERIAL_BUF_RESIZE_INC 64

// taken from http://stackoverflow.com/questions/10620601/portable-serialisation-of-ieee754-floating-point-values
float htonf(float val) {
static uint32_t serial_htonf(float val) {
uint32_t rep;
memcpy(&rep, &val, sizeof rep);
rep = htonl(rep);
memcpy(&val, &rep, sizeof rep);
return val;
return rep;
}

float ntohf(float val) {
uint32_t rep;
memcpy(&rep, &val, sizeof rep);
static float serial_ntohf(uint32_t rep) {
rep = ntohl(rep);
float val;
memcpy(&val, &rep, sizeof rep);
return val;
}
Expand Down Expand Up @@ -89,7 +87,7 @@ void serial_write_uint32(serial *s, uint32_t v) {
}

void serial_write_float(serial *s, float v) {
float t = htonf(v);
uint32_t t = serial_htonf(v);
serial_write(s, (char *)&t, sizeof(t));
}

Expand Down Expand Up @@ -147,7 +145,7 @@ uint32_t serial_read_uint32(serial *s) {
}

float serial_read_float(serial *s) {
float v;
uint32_t v;
serial_read(s, (char *)&v, sizeof(v));
return ntohf(v);
return serial_ntohf(v);
}
4 changes: 2 additions & 2 deletions tools/bktool/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void bk_keylist(void) {
printf("* background\n");
}

void bk_info(sd_bk_file *bk) {
void bk_getinfo(sd_bk_file *bk) {
printf("BK File information:\n");
printf(" * File ID: %d\n", bk->file_id);
printf(" * Palettes: %d\n", bk->palette_count);
Expand Down Expand Up @@ -881,7 +881,7 @@ int main(int argc, char *argv[]) {
} else if(keylist->count > 0) {
bk_keylist();
} else {
bk_info(&bk);
bk_getinfo(&bk);
}
}

Expand Down
5 changes: 1 addition & 4 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
},
{
"name": "sdl2-mixer",
"default-features": false,
"features": [
"wavpack"
]
"default-features": false
},
"libxmp",
"libepoxy",
Expand Down

0 comments on commit 95b33e5

Please sign in to comment.