Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
952237b
Allows one to easily link the library with C++ code.
Suthiro Oct 2, 2020
bdce276
Fix fmem.h installation issue
maxirmx Jul 18, 2021
7089841
only build testing on top-level project
Phytolizer Apr 12, 2022
08e3065
alias target
Phytolizer Apr 12, 2022
7fc7c26
target_include_directories for inheritance
Phytolizer Apr 12, 2022
351c627
Merge branch 'pr-5'
Nov 10, 2023
0c6dd73
Merge branch 'pr-2'
Nov 10, 2023
0fe079c
Create cmake-multi-platform.yml
Kreijstal Nov 10, 2023
31aa889
Add test alternative using meson and git
Nov 10, 2023
923107a
Fix CI by adding meson, will it work?
Nov 10, 2023
50c73e8
Change tests and CMake in such a way to not depend on system libraries
Nov 10, 2023
cdced5f
ci debug1
Nov 10, 2023
9426f51
ci debug2
Nov 10, 2023
28ed3e4
ci debug3
Nov 10, 2023
736930c
ci debug4
Nov 10, 2023
664a699
ci debug5
Nov 10, 2023
d829546
ci debug6
Nov 10, 2023
5961ca6
ci debug7
Nov 10, 2023
574e396
ci debug8
Nov 10, 2023
6f578aa
ci debug9
Nov 10, 2023
645b7aa
ci debug10
Nov 10, 2023
2d93420
ci debug11
Nov 10, 2023
3b4340e
ci debug12
Nov 10, 2023
8b5f393
ci debug13
Nov 10, 2023
03c2c5b
ci debug14
Nov 10, 2023
bc0c830
ci debug15
Nov 10, 2023
1ba7c36
ci debug18
Nov 10, 2023
a41e875
ci debug19
Nov 10, 2023
8a597f5
Revert "ci debug19"
Nov 10, 2023
7e23c55
Ci 20
Nov 10, 2023
74feb32
Ci 21
Nov 10, 2023
fc8aaf4
Ci 22
Nov 10, 2023
90f889f
Ci 23
Nov 10, 2023
0aaa232
Ci 24
Nov 10, 2023
b1bdad4
Ci 25
Nov 10, 2023
7973ef9
Ci 26
Nov 10, 2023
ed31c9f
Ci 27
Nov 10, 2023
3dcc0d7
Ci 28
Nov 10, 2023
fd7a77a
Ci 29
Nov 10, 2023
fc64624
Ci 30
Nov 10, 2023
e0f4107
Ci 31
Nov 10, 2023
5f391bd
Ci 32
Nov 10, 2023
4beb013
Ci 33
Nov 10, 2023
89f0e05
Ci 34
Nov 10, 2023
70fab45
Ci 35
Nov 10, 2023
103dbee
Ci 36
Nov 10, 2023
ccc9d37
Ci 37
Nov 10, 2023
f571614
Ci 38
Nov 10, 2023
1a6718a
Ci 39
Nov 10, 2023
846fa10
Ci 40
Nov 10, 2023
c2bd2f4
Ci 41
Nov 10, 2023
317ba14
Ci 42
Nov 10, 2023
1865b97
Ci 43
Nov 10, 2023
da286ff
Ci 44
Nov 10, 2023
f404cec
Ci 51
Kreijstal Nov 10, 2023
d66d69d
Ci 52
Kreijstal Nov 10, 2023
f2635fb
Ci 45
Kreijstal Nov 10, 2023
d901198
Ci 46
Kreijstal Nov 10, 2023
d885d1c
Ci 47
Kreijstal Nov 10, 2023
25f4e46
Ci 48
Kreijstal Nov 10, 2023
95c1f67
Ci 49
Kreijstal Nov 11, 2023
fecf3e0
Ci 50
Kreijstal Nov 11, 2023
4400c3d
Ci 16
Kreijstal Nov 11, 2023
7490523
Ci 17
Kreijstal Nov 11, 2023
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
113 changes: 113 additions & 0 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform.
# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml
name: CMake on multiple platforms

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:
runs-on: ${{ matrix.os }}
env:
BUILD_OUTPUT_DIR: ${{ github.workspace }}/build

strategy:
# Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable.
fail-fast: false

# Set up a matrix to run the following 3 configurations:
# 1. <Windows, Release, latest MinGW compiler toolchain on the default runner image, MSYS Generator>
# 2. <Linux, Release, latest GCC compiler toolchain on the default runner image, default generator>
# 3. <Linux, Release, latest Clang compiler toolchain on the default runner image, default generator>
#
# To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list.
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang]
include:
- os: windows-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: clang


steps:
- uses: actions/checkout@v3
# Add Meson installation steps here
- name: Install Meson (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt-get update
sudo apt-get install -y meson

- name: Install MinGW and Meson (Windows)
if: matrix.os == 'windows-latest'
uses: msys2/setup-msys2@v2
with:
msystem: MINGW64
install: mingw-w64-x86_64-meson mingw-w64-x86_64-libgit2 mingw-w64-x86_64-gcc mingw-w64-x86_64-ninja base-devel git mingw-w64-x86_64-cmake
upgrade: true


- name: Configure CMake (Windows)
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
if: matrix.os == 'windows-latest'
run: |
cmake -B $BUILD_OUTPUT_DIR -G"MSYS Makefiles" -S $BUILD_OUTPUT_DIR/..
shell: msys2 {0}

- name: Configure CMake (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: >
cmake -B $BUILD_OUTPUT_DIR
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}



- name: Build (Windows)
if: matrix.os == 'windows-latest'
shell: msys2 {0}
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build $BUILD_OUTPUT_DIR --config ${{ matrix.build_type }}

- name: Build (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: cmake --build $BUILD_OUTPUT_DIR --config ${{ matrix.build_type }}

- name: Test (Ubuntu)
working-directory: ${{ env.BUILD_OUTPUT_DIR }}
if: matrix.os == 'ubuntu-latest'
run: |
ctest --build-config ${{ matrix.build_type }} --output-on-failure
if [ $? -ne 0 ]; then
cat Testing/Temporary/LastTest.log
exit 1
fi

- name: Test (Windows)
working-directory: ${{ env.BUILD_OUTPUT_DIR }}
if: matrix.os == 'windows-latest'
shell: msys2 {0}
run: |
export PATH="$BUILD_OUTPUT_DIR/Criterion/src:$BUILD_OUTPUT_DIR/Criterion/subprojects/nanomsg:$BUILD_OUTPUT_DIR/Criterion/subprojects/nanopb:$BUILD_OUTPUT_DIR/Criterion/subprojects/boxfort/src:$BUILD_OUTPUT_DIR/Criterion/subprojects/libgit2:$PATH"
ctest --build-config ${{ matrix.build_type }} --output-on-failure
if [ $? -ne 0 ]; then
cat Testing/Temporary/LastTest.log
exit 1
fi
72 changes: 63 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ else ()
message (FATAL_ERROR "No memory stream implementation found")
endif ()

include_directories (include src ${PROJECT_BINARY_DIR}/gen)
add_library (fmem ${SOURCES})
add_library (fmem::fmem ALIAS fmem)
target_include_directories (fmem PUBLIC include src "${PROJECT_BINARY_DIR}/gen")

get_property (FMEM_LIBTYPE
TARGET fmem
Expand Down Expand Up @@ -115,13 +116,66 @@ install(TARGETS fmem
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})

install(FILES
fmem.h
${PROJECT_BINARY_DIR}/gen/fmem-export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
${PROJECT_BINARY_DIR}/gen/fmem.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Check if this is the main project and BUILD_TESTING was not already set by the user
if("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}" AND NOT DEFINED BUILD_TESTING)
message(WARNING "Detected that we're only compiling this project. BUILD_TESTING was not explicitly set, defaulting to BUILD_TESTING=ON. To disable testing, set BUILD_TESTING=OFF.")
endif()

include (CTest)

if (BUILD_TESTING)
find_package (Criterion REQUIRED)
add_subdirectory (test)
endif ()
if (WIN32)
set(LIB_EXT ".dll.a")
else()
set(LIB_EXT ".a")
endif()

if ("${CMAKE_SOURCE_DIR}" STREQUAL "${PROJECT_SOURCE_DIR}" AND BUILD_TESTING)
find_package(Criterion QUIET)
if (NOT CRITERION_FOUND)
find_program(MESON_FOUND meson)

if(NOT MESON_FOUND)
message(STATUS "Meson not found. Attempting to call meson --version for debugging.")
execute_process(
COMMAND meson --version
RESULT_VARIABLE MESON_VERSION_RESULT
OUTPUT_VARIABLE MESON_VERSION_OUTPUT
ERROR_QUIET
)
if(MESON_VERSION_RESULT EQUAL 0)
message(STATUS "Meson version: ${MESON_VERSION_OUTPUT}")
else()
message(WARNING "Meson not found or not callable from the shell.")
endif()
endif()
if (MESON_FOUND)
message(STATUS "Criterion not installed, cloning and building from source.")

# Clone Criterion into the project root directory
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/Criterion")
execute_process(COMMAND git clone --depth=1 https://github.com/Snaipe/Criterion.git "${PROJECT_SOURCE_DIR}/Criterion")
endif()

# Set include directories and library paths
set(CRITERION_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/Criterion/include")
set(CRITERION_LIBRARIES "${CMAKE_BINARY_DIR}/Criterion/src/libcriterion${LIB_EXT}")

# Check if criterion.h exists in the provided include directory
if(EXISTS "${CRITERION_INCLUDE_DIRS}/criterion/criterion.h")
message(STATUS "Found criterion.h in: ${CRITERION_INCLUDE_DIRS}/criterion")
else()
message(FATAL_ERROR "criterion.h not found in: ${CRITERION_INCLUDE_DIRS}/criterion")
endif()
# Build Criterion in a subdirectory within the main build directory
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir "${PROJECT_SOURCE_DIR}/Criterion" meson "${CMAKE_BINARY_DIR}/Criterion")
execute_process(COMMAND ${CMAKE_COMMAND} -E chdir "${PROJECT_SOURCE_DIR}/Criterion" meson compile -C "${CMAKE_BINARY_DIR}/Criterion")

else()
message(FATAL_ERROR "Meson build system not found. Unable to build Criterion from source.")
endif()
endif()

add_subdirectory(test)
endif()
8 changes: 6 additions & 2 deletions include/fmem.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ struct fmem_reserved {
};

typedef struct fmem_reserved fmem;

#ifdef __cplusplus
extern "C" {
#endif
FMEM_API void fmem_init(fmem *file);
FMEM_API void fmem_term(fmem *file);
FMEM_API FILE *fmem_open(fmem *file, const char *mode);
FMEM_API void fmem_mem(fmem *file, void **mem, size_t *size);

#ifdef __cplusplus
}
#endif
#endif /* !FMEM_H_ */
50 changes: 47 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,52 @@
set (TEST_SOURCES tests.c)
if (WIN32)
set(LIB_EXT ".dll.a")
else()
set(LIB_EXT ".a")
endif()

# Append additional libraries to CRITERION_LIBRARIES if they exist
if(EXISTS "${CMAKE_BINARY_DIR}/Criterion/subprojects/nanomsg/libnanomsg${LIB_EXT}")
list(APPEND CRITERION_LIBRARIES "${CMAKE_BINARY_DIR}/Criterion/subprojects/nanomsg/libnanomsg${LIB_EXT}")
endif()

include_directories (SYSTEM ${CRITERION_INCLUDE_DIRS})
if(EXISTS "${CMAKE_BINARY_DIR}/Criterion/subprojects/nanopb/libprotobuf_nanopb_static${LIB_EXT}")
list(APPEND CRITERION_LIBRARIES "${CMAKE_BINARY_DIR}/Criterion/subprojects/nanopb/libprotobuf_nanopb_static${LIB_EXT}")
endif()

add_executable (unit_tests ${TEST_SOURCES})
target_link_libraries (unit_tests fmem ${CRITERION_LIBRARIES})
if(EXISTS "${CMAKE_BINARY_DIR}/Criterion/subprojects/boxfort/src/libboxfort${LIB_EXT}")
list(APPEND CRITERION_LIBRARIES "${CMAKE_BINARY_DIR}/Criterion/subprojects/boxfort/src/libboxfort${LIB_EXT}")
endif()

if(EXISTS "${CMAKE_BINARY_DIR}/Criterion/subprojects/libgit2/libgit2${LIB_EXT}")
list(APPEND CRITERION_LIBRARIES "${CMAKE_BINARY_DIR}/Criterion/subprojects/libgit2/libgit2${LIB_EXT}")
else()
# Execute the find program to locate libgit2.a don't write libgit2${LIB_EXT} because FIND: Parameter format not correct
execute_process(
COMMAND find "${CMAKE_BINARY_DIR}/Criterion" -name libgit2${LIB_EXT}
OUTPUT_VARIABLE FOUND_LIBGIT2
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# If found, append to CRITERION_LIBRARIES
if(FOUND_LIBGIT2)
message(STATUS "Found libgit2.a at: ${FOUND_LIBGIT2}")
list(APPEND CRITERION_LIBRARIES "${FOUND_LIBGIT2}")
else()
message(WARNING "libgit2.a not found in Criterion subprojects.")
endif()
endif()


include_directories(SYSTEM "${CRITERION_INCLUDE_DIRS}")

# Add a debug message for test sources
message(STATUS "Adding executable for unit_tests with sources: ${TEST_SOURCES}")

add_executable (unit_tests "${TEST_SOURCES}")
# Add a debug message
message(STATUS "Linking unit_tests with libraries: fmem, ${CRITERION_LIBRARIES}")

target_link_libraries (unit_tests fmem "${CRITERION_LIBRARIES}")

add_test (unit_tests unit_tests)