From ffce407a38cdc860637454cb50b7f8d53bd23b27 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sun, 13 Apr 2025 12:11:26 -0400 Subject: [PATCH 1/4] feat: modernize --- .gitattributes | 14 -------- .github/workflows/deploy.yml | 13 ++++---- .gitignore | 19 ++--------- .vscode/c_cpp_properties.json | 2 +- .vscode/settings.json | 6 +++- .vscode/tasks.json | 18 ---------- CMakeLists.txt | 62 +++++++++-------------------------- CMakePresets.json | 44 +++++++++++++++++++++++++ README.md | 8 ++--- 9 files changed, 78 insertions(+), 108 deletions(-) delete mode 100644 .gitattributes delete mode 100644 .vscode/tasks.json create mode 100644 CMakePresets.json diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index c6439c8..0000000 --- a/.gitattributes +++ /dev/null @@ -1,14 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 2ee57a9..f3ff27a 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -45,19 +45,18 @@ jobs: run: | embuilder build harfbuzz - - name: Run CMake - run: emcmake cmake -G "Unix Makefiles" . + - name: Configure + run: emcmake cmake --preset release - - name: Make - run: emmake make -j4 + - name: Build + run: cmake --build --preset release - uses: actions/upload-pages-artifact@v3 if: github.ref == 'refs/heads/main' with: - path: ./build + path: ./build/release/target/ - name: Deploy to GitHub Pages - if: github.ref == 'refs/heads/main' id: deployment uses: actions/deploy-pages@v4 @@ -66,7 +65,7 @@ jobs: uses: adsgames/deploy-to-adsgames@v1.1.2 with: project-id: memory - build-dir: ./build/ + build-dir: ./build/release/target/ platform: WEB bucket-access-key: ${{ secrets.LINODE_BUCKET_ACCESS_KEY }} bucket-secret-key: ${{ secrets.LINODE_BUCKET_SECRET_KEY }} diff --git a/.gitignore b/.gitignore index a65361d..b58bd7d 100644 --- a/.gitignore +++ b/.gitignore @@ -39,21 +39,6 @@ Icon .Spotlight-V100 .Trashes -CppCheckResults.xml -CMakeFiles -CMakeCache.txt -Makefile -*.cmake -install_manifest.txt -bin -docs - -.ninja* -build.ninja -*.exe +# Build /build -.idea -Testing/ -compile_commands.json -_deps/ -!/cmake/get_cpm.cmake + diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index b663f36..7ca44dd 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -4,7 +4,7 @@ "name": "Win32", "includePath": ["${default}"], "defines": ["_DEBUG", "UNICODE", "_UNICODE"], - "compileCommands": "${workspaceFolder}/build/compile_commands.json", + "compileCommands": "${workspaceFolder}/build/debug/compile_commands.json", "configurationProvider": "ms-vscode.cmake-tools" } ], diff --git a/.vscode/settings.json b/.vscode/settings.json index f9ba6a0..5fe41f9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -89,5 +89,9 @@ "stop_token": "cpp", "thread": "cpp" }, - "sonarlint.pathToCompileCommands": "${workspaceFolder}\\compile_commands.json" + "sonarlint.connectedMode.project": { + "connectionId": "adsgames", + "projectKey": "AdsGames_memory" + }, + "sonarlint.pathToCompileCommands": "${workspaceFolder}/build/debug/compile_commands.json" } diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 666ecbd..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "Build", - "type": "shell", - "detail": "Run and build memory", - "command": "cd build && cmake --build . && ./Memory", - "windows": { - "command": "cd build && cmake --build . && Memory.exe" - }, - "group": "build", - "problemMatcher": "$gcc" - } - ] -} diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c93330..b3775b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,66 +1,36 @@ cmake_minimum_required(VERSION 3.24) +project(Memory VERSION 0.1.0 LANGUAGES CXX) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) - -# ---- Project ---- - -project ( - Memory - VERSION 0.1.0 - LANGUAGES CXX -) - -# ---- Dependencies ---- +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/target) include(cmake/get_cpm.cmake) CPMAddPackage("gh:adsgames/asw@0.5.7") -# ---- Source code ---- +file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) +file(GLOB_RECURSE HEADERS CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) -file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) -file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) - -# ---- Executable ---- - -add_executable (${PROJECT_NAME} ${SOURCES} ${HEADERS}) +add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS}) target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic) - -# ---- Libs ---- - -if(MINGW) - target_link_libraries(${PROJECT_NAME} -lmingw32) -endif(MINGW) - -target_link_libraries( - ${PROJECT_NAME} - asw -) - -# ---- Emscripten ---- +target_link_libraries(${PROJECT_NAME} PRIVATE asw) if(EMSCRIPTEN) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index") set(CMAKE_EXECUTABLE_SUFFIX ".html") - target_link_libraries( + target_link_options( ${PROJECT_NAME} - -sWASM=1 - -sALLOW_MEMORY_GROWTH=1 + PRIVATE + -sWASM=1 + -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb + "--preload-file ${CMAKE_CURRENT_LIST_DIR}/assets@/assets" + "--use-preload-plugins" + "--shell-file ${CMAKE_CURRENT_LIST_DIR}/index.html" ) +endif() - set_target_properties( - ${PROJECT_NAME} - PROPERTIES - LINK_FLAGS - "--preload-file ${CMAKE_CURRENT_LIST_DIR}/assets@/assets --use-preload-plugins --shell-file ${CMAKE_CURRENT_LIST_DIR}/index.html" - ) -endif(EMSCRIPTEN) - -# ---- Assets ---- - -file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets/) - +file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets/) \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..f1fdd7f --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,44 @@ +{ + "version": 3, + "cmakeMinimumRequired": { + "major": 3, + "minor": 24, + "patch": 0 + }, + "configurePresets": [ + { + "name": "debug", + "hidden": false, + "generator": "Unix Makefiles", + "description": "Debug build", + "binaryDir": "${sourceDir}/build/debug", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + } + }, + { + "name": "release", + "hidden": false, + "generator": "Unix Makefiles", + "description": "Release build", + "binaryDir": "${sourceDir}/build/release", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release" + } + } + ], + "buildPresets": [ + { + "name": "debug", + "description": "Build a debug build", + "displayName": "debug", + "configurePreset": "debug" + }, + { + "name": "release", + "description": "Build a release build", + "displayName": "release", + "configurePreset": "release" + } + ] +} diff --git a/README.md b/README.md index ab83b03..43d881d 100644 --- a/README.md +++ b/README.md @@ -15,13 +15,13 @@ Match all the cards on the table in four different difficulties. Compete against ### CMake ```bash -cmake -B build . -cmake --build ./build +cmake --preset debug +cmake --build --preset debug ``` ### Build Emscripten ```bash -emcmake cmake -B build . -cmake --build ./build +emcmake cmake --preset debug +cmake --build --preset debug ``` From 3c0a57d4097a8bb336a78f01042e55ac4eb327de Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sun, 13 Apr 2025 12:18:06 -0400 Subject: [PATCH 2/4] fix: link flags --- CMakeLists.txt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b3775b5..d11d62f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,18 +18,19 @@ target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic) target_link_libraries(${PROJECT_NAME} PRIVATE asw) if(EMSCRIPTEN) - set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index") - set(CMAKE_EXECUTABLE_SUFFIX ".html") + set_target_properties(${PROJECT_NAME} PROPERTIES + OUTPUT_NAME "index" + SUFFIX ".html" + ) - target_link_options( - ${PROJECT_NAME} - PRIVATE + target_link_options(${PROJECT_NAME} PRIVATE -sWASM=1 -sALLOW_MEMORY_GROWTH=1 -sMAXIMUM_MEMORY=1gb - "--preload-file ${CMAKE_CURRENT_LIST_DIR}/assets@/assets" - "--use-preload-plugins" - "--shell-file ${CMAKE_CURRENT_LIST_DIR}/index.html" + ) + + set_target_properties(${PROJECT_NAME} PROPERTIES + LINK_FLAGS "--preload-file ${CMAKE_CURRENT_LIST_DIR}/assets@/assets --use-preload-plugins --shell-file ${CMAKE_CURRENT_LIST_DIR}/index.html" ) endif() From 474ddcd82d86905d55ae879dd8da21f1f7c7d5d6 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sun, 13 Apr 2025 12:19:56 -0400 Subject: [PATCH 3/4] fix: cache folder --- .github/workflows/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index f3ff27a..0fa2d40 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -33,7 +33,7 @@ jobs: - name: Setup cache uses: actions/cache@v4 with: - path: "_deps" + path: "./build/release/_deps" key: deps-${{ runner.os }} - uses: mymindstorm/setup-emsdk@v14 From c99f2e67f9d63d8775f67d65001c75b65bb870d7 Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sun, 13 Apr 2025 12:26:19 -0400 Subject: [PATCH 4/4] chore: update workflow --- .github/workflows/deploy.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 0fa2d40..8ca88c0 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -52,7 +52,6 @@ jobs: run: cmake --build --preset release - uses: actions/upload-pages-artifact@v3 - if: github.ref == 'refs/heads/main' with: path: ./build/release/target/