Skip to content
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

add CMake FetchContent support #34

Open
wants to merge 7 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
34 changes: 34 additions & 0 deletions .github/workflows/darwin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: darwin

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

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
ENET_STATIC: 1
ENET_TEST: 1
ENET_SHARED: 0

jobs:
cmake-x64:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: macos-latest

steps:
- uses: actions/checkout@v2

- name: Configure CMake
# 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
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENET_STATIC=${{env.ENET_STATIC}} -DENET_SHARED=${{env.ENET_SHARED}} -DENET_TEST=${{env.ENET_TEST}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
34 changes: 34 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Linux

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

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
ENET_STATIC: 1
ENET_TEST: 1
ENET_SHARED: 0

jobs:
cmake-x64:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Configure CMake
# 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
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENET_STATIC=${{env.ENET_STATIC}} -DENET_SHARED=${{env.ENET_SHARED}} -DENET_TEST=${{env.ENET_TEST}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
34 changes: 34 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: windows

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

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release
ENET_STATIC: 1
ENET_TEST: 1
ENET_SHARED: 0

jobs:
cmake-x64:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: windows-latest

steps:
- uses: actions/checkout@v2

- name: Configure CMake
# 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
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DENET_STATIC=${{env.ENET_STATIC}} -DENET_SHARED=${{env.ENET_SHARED}} -DENET_TEST=${{env.ENET_TEST}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ compiler:
- clang

script:
- cmake . -DCMAKE_BUILD_TYPE=Release -DENET_TEST=1 -DENET_SHARED=1
- cmake . -DCMAKE_BUILD_TYPE=Release -DENET_TEST=1 -DENET_SHARED=1 -DENET_STATIC=0
- cmake --build .
- ./enet_test

Expand Down
16 changes: 5 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.0)
project(enet C)

# defaults
set(ENET_STATIC ON)
set(ENET_SHARED OFF)
set(ENET_TEST OFF)
option(ENET_STATIC ON)
option(ENET_SHARED OFF)
option(ENET_TEST OFF)

# configure projects
if (ENET_STATIC)
Expand All @@ -25,19 +25,13 @@ if (ENET_SHARED)
endif()

if (ENET_TEST)
add_executable(enet_test test/build.c)
target_include_directories(enet_test PRIVATE ${PROJECT_SOURCE_DIR}/include)

if (WIN32)
target_link_libraries(enet_test PUBLIC winmm ws2_32)
endif()
add_subdirectory(test)
endif()


if(MSVC)
target_compile_options(enet PRIVATE -W3)
else()
target_compile_options(enet PRIVATE -Wno-error)
endif()

target_include_directories(enet PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_include_directories(enet PUBLIC ${PROJECT_SOURCE_DIR}/include)
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,23 @@ $ npm install enet.c --save

Add include path to the library `node_modules/enet.c/include` to your makefile/

## Installation (via CMake >3.11)

Install library by

```cmake
include(FetchContent)

FetchContent_Declare(
enet
GIT_REPOSITORY https://github.com/zpl-c/enet.git
GIT_TAG YOUR_BRANCH_OR_TAG_OF_CHOICE
)
FetchContent_MakeAvailable(enet)
```

and link against the `enet` library in projects that necessitate it.

## Installation (manually)

Download file [include/enet.h](https://raw.githubusercontent.com/zpl-c/enet/master/include/enet.h) and just add to your project.
Expand Down
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.0)
project(enet_test C)

add_executable(enet_test build.c)

target_link_libraries(enet_test PRIVATE enet)
target_include_directories(enet_test PRIVATE enet)

if(MSVC)
target_compile_options(enet_test PRIVATE -W3)
else()
target_compile_options(enet_test PRIVATE -Wno-error)
endif()