-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from bbannier/t/cmake
Add CMake setup, test and CI for CC library
- Loading branch information
Showing
5 changed files
with
117 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Test CC library | ||
|
||
on: | ||
push: | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Install LLVM and Clang | ||
uses: KyleMayes/install-llvm-action@v2 | ||
with: | ||
version: "18" | ||
- run: cmake cc/src -B build | ||
- run: cmake --build build | ||
- run: ctest --test-dir build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
cmake_minimum_required(VERSION 3.14) | ||
project(gnumake-tokenpool LANGUAGES CXX) | ||
|
||
add_library( | ||
gnumake-tokenpool | ||
tokenpool-gnu-make-posix.cc | ||
# tokenpool-gnu-make-win32.cc # TODO: Add this file iff building on win32. | ||
tokenpool-gnu-make.cc) | ||
target_include_directories(gnumake-tokenpool PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | ||
|
||
option(GNUMAKE_TOKENPOOL_BUILD_TESTS "build gnumake-tokenpool tests" ON) | ||
|
||
if (GNUMAKE_TOKENPOOL_BUILD_TESTS) | ||
# GoogleTest requires at least C++14 | ||
set(CMAKE_CXX_STANDARD 14) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
include(FetchContent) | ||
FetchContent_Declare( | ||
googletest | ||
URL https://github.com/google/googletest/releases/download/v1.15.2/googletest-1.15.2.tar.gz) | ||
# For Windows: Prevent overriding the parent project's compiler/linker settings | ||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) | ||
FetchContent_MakeAvailable(googletest) | ||
|
||
add_executable(gnumake-tokenpool-test tokenpool_test.cc) | ||
target_link_libraries(gnumake-tokenpool-test gnumake-tokenpool gtest_main) | ||
|
||
enable_testing() | ||
|
||
include(GoogleTest) | ||
gtest_discover_tests(gnumake-tokenpool-test) | ||
endif () |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2016-2018 Google Inc. All Rights Reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "tokenpool-gnu-make.h" | ||
|
||
#include <signal.h> | ||
|
||
// TokenPool implementation for GNU make jobserver - POSIX implementation | ||
// (http://make.mad-scientist.net/papers/jobserver-implementation/) | ||
struct GNUmakeTokenPoolPosix : public GNUmakeTokenPool { | ||
GNUmakeTokenPoolPosix(); | ||
virtual ~GNUmakeTokenPoolPosix(); | ||
|
||
virtual int GetMonitorFd(); | ||
|
||
virtual const char* GetEnv(const char* name) { return getenv(name); } | ||
virtual bool SetEnv(const char* name, const char* value) { | ||
return setenv(name, value, 1) == 0; | ||
} | ||
virtual bool ParseAuth(const char* jobserver); | ||
virtual bool CreatePool(int parallelism, std::string* auth); | ||
virtual int AcquireToken(); | ||
virtual bool ReleaseToken(int token); | ||
|
||
private: | ||
int rfd_; | ||
int wfd_; | ||
|
||
struct sigaction old_act_; | ||
bool restore_; | ||
|
||
static int dup_rfd_; | ||
static void CloseDupRfd(int signum); | ||
|
||
bool CheckFd(int fd); | ||
bool SetAlarmHandler(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters