From 00956bd716791025c3e676f1821df6a24e1e9df7 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Mon, 13 Dec 2021 09:40:04 +0100 Subject: [PATCH] Add Cmake support --- .gitignore | 51 +++++++++++++++++++++------------ .vscode/c_cpp_properties.json | 24 ++++++++++++++++ .vscode/launch.json | 20 +++++++++++++ .vscode/tasks.json | 54 +++++++++++++++++++++++++++++++++++ CMakeLists.txt | 28 ++++++++++++++++++ tests/lwmem_test.c | 7 ++++- 6 files changed, 165 insertions(+), 19 deletions(-) create mode 100644 .vscode/c_cpp_properties.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json create mode 100644 CMakeLists.txt diff --git a/.gitignore b/.gitignore index a872aad..4674b8a 100644 --- a/.gitignore +++ b/.gitignore @@ -24,26 +24,29 @@ *.i *.txt !docs/*.txt +!CMakeLists.txt RTE/ -# IAR Settings -**/settings/*.crun -**/settings/*.dbgdt -**/settings/*.cspy -**/settings/*.cspy.* -**/settings/*.xcl -**/settings/*.dni -**/settings/*.wsdt -**/settings/*.wspos +*debug -# IAR Debug Exe -**/Exe/*.sim +# IAR Settings +**/settings/*.crun +**/settings/*.dbgdt +**/settings/*.cspy +**/settings/*.cspy.* +**/settings/*.xcl +**/settings/*.dni +**/settings/*.wsdt +**/settings/*.wspos -# IAR Debug Obj -**/Obj/*.pbd -**/Obj/*.pbd.* -**/Obj/*.pbi -**/Obj/*.pbi.* +# IAR Debug Exe +**/Exe/*.sim + +# IAR Debug Obj +**/Obj/*.pbd +**/Obj/*.pbd.* +**/Obj/*.pbi +**/Obj/*.pbi.* *.TMP /docs_src/x_Doxyfile.doxy @@ -69,6 +72,7 @@ RTE/ [Dd]ebugPublic/ [Rr]elease/ [Rr]eleases/ +[Dd]ebug*/ x64/ x86/ bld/ @@ -76,6 +80,7 @@ bld/ [Oo]bj/ [Ll]og/ _build/ +build/ # Visual Studio 2015/2017 cache/options directory .vs/ @@ -274,7 +279,7 @@ ClientBin/ *.publishsettings orleans.codegen.cs -# Including strong name files can present a security risk +# Including strong name files can present a security risk # (https://github.com/github/gitignore/pull/2483#issue-259490424) #*.snk @@ -370,7 +375,7 @@ __pycache__/ # OpenCover UI analysis results OpenCover/ -# Azure Stream Analytics local run output +# Azure Stream Analytics local run output ASALocalRun/ # MSBuild Binary and Structured Log @@ -383,3 +388,13 @@ log_file.txt project.ioc mx.scratch *.tilen majerle + + +# Altium +Project outputs* +History/ +*.SchDocPreview +*.$$$Preview + +# VSCode projects +project_vscode_compiled.exe \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..24189a2 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,24 @@ +{ + "version": 4, + "configurations": [ + { + "name": "Win32", + "includePath": [ + "${workspaceFolder}\\dev\\VisualStudio\\", + "${workspaceFolder}\\lwmem\\src\\include\\" + ], + "defines": [ + "WIN32", + "_DEBUG", + "UNICODE", + "_UNICODE", + "LWMEM_DEV" + ], + "compilerPath": "c:\\msys64\\mingw64\\bin\\gcc.exe", + "cStandard": "gnu17", + "cppStandard": "gnu++14", + "intelliSenseMode": "windows-gcc-x86", + "configurationProvider": "ms-vscode.cmake-tools" + } + ] +} \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4ac3256 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,20 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppvsdbg", + "request": "launch", + "program": "${workspaceFolder}\\build\\LwPRINTF.exe", + "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..15543ce --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,54 @@ +{ + "version": "2.0.0", + + /* For this builds, you need + * + * - Ninja build system + * - MSYS2 compiler with ninja support + * - C/C++ extension for VSCode + * - CMake-Tools extension for VSCode + */ + "tasks": [ + { + "type": "cppbuild", + "label": "Build project", + "command": "cmake", + "args": [ + "--build", + "\"build\"" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + } + }, + { + "type": "shell", + "label": "Clean project", + "command": "cmake", + "args": [ + "--build", + "\"build\"", + "--target", + "clean" + ], + "options": { + "cwd": "${workspaceFolder}" + }, + "problemMatcher": [] + }, + { + "type": "shell", + "label": "Run application", + "command": "${workspaceFolder}\\build\\LwMEM.exe", + "args": [], + "problemMatcher": [], + }, + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3de45fb --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,28 @@ +cmake_minimum_required(VERSION 3.0.0) +project(LwMEM VERSION 0.1.0) + +include(CTest) +enable_testing() + +add_executable(${PROJECT_NAME} + lwmem/src/lwmem/lwmem.c + lwmem/src/system/lwmem_sys_win32.c + tests/lwmem_test.c + dev/VisualStudio/main.c + ) + +target_include_directories(${PROJECT_NAME} PRIVATE + dev/VisualStudio + lwmem/src/include + ) + +target_compile_definitions(${PROJECT_NAME} PRIVATE + WIN32 + _DEBUG + CONSOLE + LWMEM_DEV + ) + +set(CPACK_PROJECT_NAME ${PROJECT_NAME}) +set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) +include(CPack) diff --git a/tests/lwmem_test.c b/tests/lwmem_test.c index a4b6f66..c837244 100644 --- a/tests/lwmem_test.c +++ b/tests/lwmem_test.c @@ -1,4 +1,5 @@ #include "lwmem/lwmem.h" +#include /* Assert check */ #define ASSERT(x) do { \ @@ -11,7 +12,11 @@ /********************************************/ /* Test case helpers */ -#define IS_ALLOC_IN_REGION(ptr, region) ASSERT((unsigned char *)(ptr) >= (region)->start_addr && (unsigned char *)(ptr) < ((unsigned char *)(region)->start_addr + (region)->size)) +#define UINT_PTR_CAST(x) ((uintptr_t)(x)) +#define IS_ALLOC_IN_REGION(ptr, region) ASSERT( \ + UINT_PTR_CAST(ptr) >= UINT_PTR_CAST((region)->start_addr) \ + && UINT_PTR_CAST(ptr) < (UINT_PTR_CAST((region)->start_addr) + (region)->size) \ +) /********************************************/ /* Configuration for default lwmem instance */