-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(add): support FetchContent for cmake (#22)
* add package target * add release workflows * refactor CMakeLists; enhance usability * add alias for library name
- Loading branch information
Showing
10 changed files
with
176 additions
and
59 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,23 @@ | ||
name: Release | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
jobs: | ||
release: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Create build environment | ||
run: cmake -B build-release | ||
- name: Package source code | ||
working-directory: build-release/ | ||
run: cmake --build . --target package | ||
- name: Add packaged source code to release | ||
uses: svenstaro/upload-release-action@v2 | ||
with: | ||
repo_token: ${{ secrets.GITHUB_TOKEN }} | ||
file: build-release/numbers-src.zip | ||
tag: ${{ github.ref }} |
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,28 @@ | ||
#include <iostream> | ||
#include <tuple> | ||
|
||
#include "numbers.h" | ||
|
||
void for_error() { | ||
size_t i; | ||
|
||
// error - infinite loop | ||
for (i = 10; i >= 0; i--) { | ||
printf("[ID %u] Hello, World\n", i); | ||
} | ||
} | ||
|
||
void for_correct() { | ||
using namespace numbers; | ||
|
||
u8 i; | ||
bool flag = false; | ||
for (i = 10; !flag && i >= 0; std::tie(i, flag) = i.overflowing_sub(1)) { | ||
printf("[ID %u] Hello, World\n", i); | ||
} | ||
} | ||
|
||
int main(int argc, char const *argv[]) { | ||
for_correct(); | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
add_subdirectory(numbers) | ||
|
||
add_library(numbers STATIC ${ALL_OBJECT_FILES}) | ||
add_library(${PROJECT_NAME} STATIC ${ALL_OBJECT_FILES}) | ||
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) | ||
|
||
target_include_directories(numbers PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEIR}> | ||
target_include_directories(${PROJECT_NAME} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEIR}> | ||
) |
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
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 |
---|---|---|
@@ -1,11 +1,11 @@ | ||
file(GLOB obj_files "${CMAKE_CURRENT_SOURCE_DIR}/*.cc") | ||
|
||
add_library( | ||
numbers_obj | ||
OBJECT | ||
${obj_files} | ||
numbers_obj | ||
OBJECT | ||
${obj_files} | ||
) | ||
|
||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:numbers_obj> | ||
PARENT_SCOPE) | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:numbers_obj> | ||
PARENT_SCOPE) |
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
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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
add_library( | ||
test_utils | ||
EXCLUDE_FROM_ALL | ||
OBJECT | ||
utils.cc | ||
test_utils | ||
EXCLUDE_FROM_ALL | ||
OBJECT | ||
utils.cc | ||
) | ||
|
||
set(ALL_OBJECT_FILES | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:test_utils> | ||
PARENT_SCOPE) | ||
${ALL_OBJECT_FILES} $<TARGET_OBJECTS:test_utils> | ||
PARENT_SCOPE) |