Repository navigation
chore: Add boilerplate CMake project and Taskfile tasks to lint CMake files. #7
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
Changes from 5 commits
3666123
591bb13
13e4277
cd6d93d
cf15a8e
24d4792
03ddcfb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # yamllint disable-line rule:line-length | ||
| # yaml-language-server: $schema=https://raw.githubusercontent.com/BlankSpruce/gersemi/master/gersemi/configuration.schema.json | ||
|
|
||
| line_length: 100 | ||
| list_expansion: "favour-expansion" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # CMake 3.22.1 is the default on Ubuntu 22.04 | ||
| cmake_minimum_required(VERSION 3.22.1) | ||
|
|
||
| project( | ||
| spider | ||
| LANGUAGES | ||
| C | ||
| CXX | ||
| VERSION 0.1.0 | ||
| ) | ||
|
|
||
| # Enable exporting compile commands | ||
| set(CMAKE_EXPORT_COMPILE_COMMANDS | ||
| ON | ||
| CACHE BOOL | ||
| "Enable/Disable output of compile commands during generation." | ||
| FORCE | ||
| ) | ||
|
|
||
| # Set the default build type to Release if not specified | ||
| if(NOT CMAKE_BUILD_TYPE) | ||
| set(SPIDER_DEFAULT_BUILD_TYPE "Release") | ||
| message(STATUS "No build type specified. Setting to '${SPIDER_DEFAULT_BUILD_TYPE}'.") | ||
| set(CMAKE_BUILD_TYPE | ||
| "${SPIDER_DEFAULT_BUILD_TYPE}" | ||
| CACHE STRING | ||
| "Choose the type of build." | ||
| FORCE | ||
| ) | ||
| endif() | ||
|
|
||
| add_executable(spider) | ||
| target_compile_features(spider PRIVATE cxx_std_20) | ||
| target_sources(spider PRIVATE src/spider/spider.cpp) | ||
|
Contributor
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. 🛠️ Refactor suggestion Consider organizing target properties more systematically. The target configuration could be enhanced with:
add_executable(spider)
+
+# Specify C++ standard through a target property
target_compile_features(spider PRIVATE cxx_std_20)
+
+# Group source files for better organization
+set(SPIDER_SOURCES
+ src/spider/spider.cpp
+)
+target_sources(spider PRIVATE ${SPIDER_SOURCES})
+
+# Add include directories if needed
+target_include_directories(spider
+ PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+)
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| gersemi>=0.16.2 | ||
| yamllint>=1.35.1 |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,12 +6,28 @@ vars: | |||||||||||||||||||||||||||||||||||||||
| tasks: | ||||||||||||||||||||||||||||||||||||||||
| check: | ||||||||||||||||||||||||||||||||||||||||
| cmds: | ||||||||||||||||||||||||||||||||||||||||
| - task: "cmake-check" | ||||||||||||||||||||||||||||||||||||||||
| - task: "yml-check" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| fix: | ||||||||||||||||||||||||||||||||||||||||
| cmds: | ||||||||||||||||||||||||||||||||||||||||
| - task: "cmake-fix" | ||||||||||||||||||||||||||||||||||||||||
| - task: "yml-fix" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| cmake-check: | ||||||||||||||||||||||||||||||||||||||||
| deps: ["venv"] | ||||||||||||||||||||||||||||||||||||||||
| cmds: | ||||||||||||||||||||||||||||||||||||||||
| - task: "cmake" | ||||||||||||||||||||||||||||||||||||||||
| vars: | ||||||||||||||||||||||||||||||||||||||||
| FLAGS: "--check" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| cmake-fix: | ||||||||||||||||||||||||||||||||||||||||
| deps: ["venv"] | ||||||||||||||||||||||||||||||||||||||||
| cmds: | ||||||||||||||||||||||||||||||||||||||||
| - task: "cmake" | ||||||||||||||||||||||||||||||||||||||||
| vars: | ||||||||||||||||||||||||||||||||||||||||
| FLAGS: "--in-place" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| yml: | ||||||||||||||||||||||||||||||||||||||||
| aliases: | ||||||||||||||||||||||||||||||||||||||||
| - "yml-check" | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -22,6 +38,14 @@ tasks: | |||||||||||||||||||||||||||||||||||||||
| . "{{.G_LINT_VENV_DIR}}/bin/activate" | ||||||||||||||||||||||||||||||||||||||||
| yamllint --strict . | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| cmake: | ||||||||||||||||||||||||||||||||||||||||
| internal: true | ||||||||||||||||||||||||||||||||||||||||
| requires: | ||||||||||||||||||||||||||||||||||||||||
| vars: ["FLAGS"] | ||||||||||||||||||||||||||||||||||||||||
| cmd: |- | ||||||||||||||||||||||||||||||||||||||||
| . "{{.G_LINT_VENV_DIR}}/bin/activate" | ||||||||||||||||||||||||||||||||||||||||
| find . -name CMakeLists.txt -print0 | xargs -0 gersemi {{.FLAGS}} | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+52
Contributor
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. 🛠️ Refactor suggestion Consider enhancing the cmake task's robustness. While the implementation is functional, consider these improvements:
Here's a suggested improvement: - find . -name CMakeLists.txt -print0 | xargs -0 gersemi {{.FLAGS}}
+ find . -name CMakeLists.txt \
+ -not -path "*/build/*" \
+ -not -path "*/third_party/*" \
+ -print0 | \
+ xargs -0 -r gersemi {{.FLAGS}}The 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
| venv: | ||||||||||||||||||||||||||||||||||||||||
| internal: true | ||||||||||||||||||||||||||||||||||||||||
| vars: | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -32,6 +56,7 @@ tasks: | |||||||||||||||||||||||||||||||||||||||
| - "{{.TASKFILE}}" | ||||||||||||||||||||||||||||||||||||||||
| - "lint-requirements.txt" | ||||||||||||||||||||||||||||||||||||||||
| generates: ["{{.CHECKSUM_FILE}}"] | ||||||||||||||||||||||||||||||||||||||||
| run: "once" | ||||||||||||||||||||||||||||||||||||||||
| deps: | ||||||||||||||||||||||||||||||||||||||||
| - ":init" | ||||||||||||||||||||||||||||||||||||||||
| - task: ":utils:validate-checksum" | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #include <iostream> | ||
|
|
||
| int main() { | ||
| std::cout << "Hello, world!" << std::endl; | ||
| return 0; | ||
| } |
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.
🛠️ Refactor suggestion
Consider adding build type options validation.
The build type configuration could benefit from validating allowed values and documenting available options.
if(NOT CMAKE_BUILD_TYPE) set(SPIDER_DEFAULT_BUILD_TYPE "Release") message(STATUS "No build type specified. Setting to '${SPIDER_DEFAULT_BUILD_TYPE}'.") set(CMAKE_BUILD_TYPE "${SPIDER_DEFAULT_BUILD_TYPE}" CACHE STRING - "Choose the type of build." + "Choose the type of build (Debug/Release/RelWithDebInfo/MinSizeRel)." FORCE ) + # Provide drop-down in CMake GUIs + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "RelWithDebInfo" "MinSizeRel") endif()📝 Committable suggestion