Skip to content

Commit

Permalink
Improve CMakeLists.txt and add a GitHub workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jerinphilip committed Sep 23, 2022
1 parent e5a9911 commit c787e48
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 13 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: "Build"
'on':
push:
branches:
- main
- master
tags:
- "v*.*.*"
pull_request:
branches:
- '**'

jobs:
build-ubuntu:
strategy:
matrix:
include:
- os: ubuntu-22.04
cuda: "on"
cmake_args: |
-DTASK_SPOOLER_COMPILE_CUDA=on
- os: ubuntu-22.04
cuda: "off"
cmake_args: ""

fail-fast: false

name: "cmake / ${{ matrix.os }} / cuda-${{ matrix.cuda }}"
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: "Install CUDA"
if: ${{ matrix.cuda == 'on' }}
run: |
sudo apt-get update
sudo apt-get -y install nvidia-cuda-toolkit
- name: "Build"
run: |
mkdir build
cd build
cmake .. ${{ matrix.cmake_args }}
make
build-macos:
strategy:
matrix:
os: [macos-12.0]
fail-fast: false

name: "cmake / ${{ matrix.os }}"
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
with:
submodules: recursive

- name: "Build"
run: |
mkdir build
cd build
cmake ..
make
36 changes: 23 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ project(Task-Spooler C)

set(CMAKE_C_STANDARD 11)

set(CMAKE_CUDA_COMPILER $ENV{CUDA_HOME}/bin/nvcc)
enable_language(CUDA)
include_directories($ENV{CUDA_HOME}/include)
option(TASK_SPOOLER_COMPILE_CUDA "Compile CUDA support (NVML)" OFF)

# VERSIONING
execute_process(
COMMAND git rev-parse --is-inside-work-tree
OUTPUT_VARIABLE GIT_REPO OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (GIT_REPO)
execute_process (
COMMAND bash -c "echo $(git describe --dirty --always --tags) | tr - +"
Expand All @@ -20,32 +19,43 @@ if (GIT_REPO)
add_definitions(-DTS_VERSION=${git_version})
endif()

if (CPU)
message("Installing a CPU version...")
add_definitions(-DCPU)
endif()

set(target ts)
add_executable(
${target}

set(TASK_SPOOLER_SOURCES
client.c
env.c
error.c
execute.c
gpu.c
info.c
jobs.c
list.c
mail.c
main.c
msg.c
msgdump.c
print.c
server.c
server_start.c
signals.c
tail.c
tail.c)

if(TASK_SPOOLER_COMPILE_CUDA)
set(TASK_SPOOLER_SOURCES ${TASK_SPOOLER_SOURCES} gpu.c)
endif(TASK_SPOOLER_COMPILE_CUDA)

add_executable(
${target}
main.c
${TASK_SPOOLER_SOURCES}
)

add_executable(makeman man.c)

target_link_libraries(${target} nvidia-ml)
if(TASK_SPOOLER_COMPILE_CUDA)
find_package(CUDAToolkit)
target_link_libraries(${target} CUDA::nvml)
else(TASK_SPOOLER_COMPILE_CUDA)
message("Installing a CPU version...")
target_compile_definitions(${target} PUBLIC CPU)
endif(TASK_SPOOLER_COMPILE_CUDA)

0 comments on commit c787e48

Please sign in to comment.