Skip to content

Commit

Permalink
Merge pull request #8 from dthaler/cmake
Browse files Browse the repository at this point in the history
Add cmake support
  • Loading branch information
sanfern authored May 13, 2022
2 parents 1935dbe + 5098d04 commit dfc2b7a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/ci-build-windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ jobs:
- name: Set up git env
run: |
git config --global core.autocrlf false
$gopath = (go env GOPATH)
echo "GOPATH=$gopath" >> $env:GITHUB_ENV
- name: Checkout repository
uses: actions/checkout@v3
Expand Down Expand Up @@ -51,5 +53,8 @@ jobs:
build-tags: WINDOWS

- name: Build
env:
GOPATH: ${{env.GOPATH}}
run: |
go build -tags WINDOWS .
cmake -B build
cmake --build build
36 changes: 36 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
cmake_minimum_required(VERSION 3.10)
project(l3afd)

add_custom_target(swagger ALL
DEPENDS ${CMAKE_SOURCE_DIR}/docs/docs.go
${CMAKE_SOURCE_DIR}/docs/swagger.json
${CMAKE_SOURCE_DIR}/docs/swagger.yaml)

add_custom_command(OUTPUT $ENV{GOPATH}/bin/swag.exe
COMMAND go install github.com/swaggo/swag/cmd/swag@latest
COMMAND go get -u github.com/swaggo/http-swagger
COMMAND go get -u github.com/alecthomas/template)

add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/docs/docs.go
${CMAKE_SOURCE_DIR}/docs/swagger.json
${CMAKE_SOURCE_DIR}/docs/swagger.yaml
DEPENDS ${CMAKE_SOURCE_DIR}/apis/configwatch.go
$ENV{GOPATH}/bin/swag.exe
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND env
COMMAND "$ENV{GOPATH}/bin/swag.exe" init -d "./" -g "apis/configwatch.go")

add_custom_target(build ALL
DEPENDS ${CMAKE_SOURCE_DIR}/l3afd.exe)

if (${WIN32})
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/l3afd.exe
DEPENDS ${CMAKE_SOURCE_DIR}/main.go
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND go build -tags WINDOWS .)
else ()
add_custom_command(OUTPUT ${CMAKE_SOURCE_DIR}/l3afd.exe
DEPENDS ${CMAKE_SOURCE_DIR}/main.go
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
COMMAND go build .)
endif ()
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ For Windows:
go build -tags WINDOWS .
```

On Linux and Windows, one can also build and generate swagger docs by doing:
```
cmake -B build
cmake --build build
```

# Testing

To test on your local machine, do the following.
Expand All @@ -59,4 +65,4 @@ go test -tags WINDOWS ./...
# Contributing

Contributing to L3afd is fun. To get started:
- [Contributing guide](docs/CONTRIBUTING.md)
- [Contributing guide](docs/CONTRIBUTING.md)
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/l3af-project/l3afd
go 1.16

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/cilium/ebpf v0.6.2
github.com/go-chi/chi/v5 v5.0.7
github.com/go-openapi/spec v0.20.6 // indirect
Expand Down

0 comments on commit dfc2b7a

Please sign in to comment.