From cc2423a617f90a633367462e28bfe884ce7f094f Mon Sep 17 00:00:00 2001 From: Allan Legemaate Date: Sat, 12 Apr 2025 16:44:21 -0400 Subject: [PATCH] fix: cpm --- .gitignore | 1 + .vscode/c_cpp_properties.json | 12 +++++++++++ .vscode/tasks.json | 4 ++-- CMakeLists.txt | 39 +++++++++++++++++++++-------------- README.md | 10 ++++----- cmake/get_cpm.cmake | 24 +++++++++++++++++++++ sonar-project.properties | 3 --- src/ui/InputBox.cpp | 2 +- 8 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 cmake/get_cpm.cmake delete mode 100644 sonar-project.properties diff --git a/.gitignore b/.gitignore index 088631a..a65361d 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,4 @@ build.ninja Testing/ compile_commands.json _deps/ +!/cmake/get_cpm.cmake diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..b663f36 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,12 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": ["${default}"], + "defines": ["_DEBUG", "UNICODE", "_UNICODE"], + "compileCommands": "${workspaceFolder}/build/compile_commands.json", + "configurationProvider": "ms-vscode.cmake-tools" + } + ], + "version": 4 +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index dbc313e..666ecbd 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,9 +7,9 @@ "label": "Build", "type": "shell", "detail": "Run and build memory", - "command": "cmake --build . && cd build && ./Memory", + "command": "cd build && cmake --build . && ./Memory", "windows": { - "command": "cmake --build . && cd build && Memory.exe" + "command": "cd build && cmake --build . && Memory.exe" }, "group": "build", "problemMatcher": "$gcc" diff --git a/CMakeLists.txt b/CMakeLists.txt index 55706a9..8c93330 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,31 +1,35 @@ -cmake_minimum_required(VERSION 3.11) +cmake_minimum_required(VERSION 3.24) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build) 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 ---- -include(FetchContent) +include(cmake/get_cpm.cmake) +CPMAddPackage("gh:adsgames/asw@0.5.7") -project (Memory) +# ---- Source code ---- -# Source code file(GLOB_RECURSE SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) file(GLOB_RECURSE HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/src/*.h) -add_executable (${PROJECT_NAME} ${SOURCES} ${HEADERS}) +# ---- Executable ---- +add_executable (${PROJECT_NAME} ${SOURCES} ${HEADERS}) target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -pedantic) -FetchContent_Declare( - asw - GIT_REPOSITORY https://github.com/adsgames/asw.git - GIT_TAG v0.5.4 - GIT_SHALLOW TRUE -) -FetchContent_MakeAvailable(asw) +# ---- Libs ---- -# Link Libs if(MINGW) target_link_libraries(${PROJECT_NAME} -lmingw32) endif(MINGW) @@ -35,7 +39,8 @@ target_link_libraries( asw ) -# Emscripten support +# ---- Emscripten ---- + if(EMSCRIPTEN) set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "index") set(CMAKE_EXECUTABLE_SUFFIX ".html") @@ -55,5 +60,7 @@ if(EMSCRIPTEN) ) endif(EMSCRIPTEN) -file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${CMAKE_BINARY_DIR}/build/assets/) +# ---- Assets ---- + +file(COPY ${CMAKE_CURRENT_LIST_DIR}/assets/ DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/assets/) diff --git a/README.md b/README.md index 2830f56..ab83b03 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,16 @@ Match all the cards on the table in four different difficulties. Compete against ## Setup -### Build +### CMake ```bash -cmake . -make +cmake -B build . +cmake --build ./build ``` ### Build Emscripten ```bash -emcmake cmake . -make +emcmake cmake -B build . +cmake --build ./build ``` diff --git a/cmake/get_cpm.cmake b/cmake/get_cpm.cmake new file mode 100644 index 0000000..9c27c51 --- /dev/null +++ b/cmake/get_cpm.cmake @@ -0,0 +1,24 @@ +# SPDX-License-Identifier: MIT +# +# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors + +set(CPM_DOWNLOAD_VERSION 0.40.8) +set(CPM_HASH_SUM "78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791") + +if(CPM_SOURCE_CACHE) + set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +elseif(DEFINED ENV{CPM_SOURCE_CACHE}) + set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +else() + set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake") +endif() + +# Expand relative path. This is important if the provided path contains a tilde (~) +get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE) + +file(DOWNLOAD + https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake + ${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM} +) + +include(${CPM_DOWNLOAD_LOCATION}) diff --git a/sonar-project.properties b/sonar-project.properties deleted file mode 100644 index f6c0dfb..0000000 --- a/sonar-project.properties +++ /dev/null @@ -1,3 +0,0 @@ -sonar.projectKey=AdsGames_memory -sonar.organization=adsgames -sonar.sources=./src diff --git a/src/ui/InputBox.cpp b/src/ui/InputBox.cpp index 3d43bd6..9488252 100644 --- a/src/ui/InputBox.cpp +++ b/src/ui/InputBox.cpp @@ -38,7 +38,7 @@ void InputBox::update() { for (unsigned int i = 0; i <= text.length(); i++) { const int textSize = asw::util::getTextSize(font, text.substr(0, i)).x; - const int distance = abs(textSize + x + 6 - asw::input::mouse.x); + const int distance = std::abs(textSize + x + 6 - asw::input::mouse.x); if (distance < closest) { textIterator = i;