-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat(add): support FetchContent for cmake #22
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,28 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
set(BUILD_SHARED_LIBS OFF) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(version 0.0.3) | ||
|
||
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_TOP_LEVEL) | ||
project(numbers VERSION ${version} LANGUAGES CXX) | ||
|
||
if (PROJECT_IS_TOP_LEVEL) | ||
message(STATUS "Project is top level") | ||
endif() | ||
set(BUILD_SHARED_LIBS OFF) | ||
|
||
option(NUMBERS_TEST "Build and perform numbers tests" ${PROJECT_IS_TOP_LEVEL}) | ||
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_IN_ROOT) | ||
|
||
set(version 0.0.2) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ${PROJECT_IS_IN_ROOT}) | ||
|
||
project(numbers VERSION ${version} LANGUAGES CXX) | ||
if(PROJECT_IS_IN_ROOT) | ||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
message(STATUS "Project ${PROJECT_NAME} is in root") | ||
endif() | ||
|
||
# Check if the compiler supports C++17 | ||
if(NOT CMAKE_CXX_STANDARD OR CMAKE_CXX_STANDARD LESS 17) | ||
message(FATAL_ERROR "Error: ${PROJECT_NAME} is a library for C++17 and later versions.") | ||
endif() | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
option(NUMBERS_TEST "Build and perform ${PROJECT_NAME} tests" ${PROJECT_IS_IN_ROOT}) | ||
option(NUMBERS_EXAMPLE "Build and perform ${PROJECT_NAME} examples" ${PROJECT_IS_IN_ROOT}) | ||
|
||
# Includes. | ||
set(SRC_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/src/include) | ||
|
@@ -25,14 +31,29 @@ include_directories(${SRC_INCLUDE_DIR}) | |
|
||
add_subdirectory(src) | ||
|
||
if (NUMBERS_TEST) | ||
message(STATUS "Building and running tests") | ||
set(THIRD_PARTY_INCLUDE_DIR | ||
${PROJECT_SOURCE_DIR}/third_party | ||
) | ||
include_directories(${THIRD_PARTY_INCLUDE_DIR}) | ||
if(NUMBERS_EXAMPLE) | ||
add_subdirectory(examples) | ||
endif() | ||
|
||
add_subdirectory(examples) | ||
add_subdirectory(third_party) | ||
add_subdirectory(tests) | ||
if(NUMBERS_TEST) | ||
message(STATUS "Building and running tests") | ||
set(THIRD_PARTY_INCLUDE_DIR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We still need to learn how to configure the library so that it can be included by other libraries using |
||
${PROJECT_SOURCE_DIR}/third_party | ||
) | ||
include_directories(${THIRD_PARTY_INCLUDE_DIR}) | ||
|
||
add_subdirectory(third_party) | ||
add_subdirectory(tests) | ||
|
||
# Provide only the minimum source files needed by downstream users | ||
set(package_files src/ CMakeLists.txt LICENSE.txt) | ||
set(packaged_zip ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-src.zip) | ||
add_custom_command( | ||
OUTPUT ${packaged_zip} | ||
COMMAND ${CMAKE_COMMAND} -E tar c ${packaged_zip} --format=zip -- ${package_files} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||
COMMENT "The source files have been packaged into ${packaged_zip}" | ||
DEPENDS ${package_files} | ||
) | ||
add_custom_target(package DEPENDS ${packaged_zip}) | ||
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
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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It needs test.