From 459c588ddef1e9c5e823576e032144da6eaa0f77 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Thu, 23 Dec 2021 22:23:39 +0100 Subject: [PATCH 1/6] Add test sub-cmake --- CMakeLists.txt | 23 +++++++++++------------ lwmem/CMakeLists.txt | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 lwmem/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ed7aec..f56aa93 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,19 +1,19 @@ cmake_minimum_required(VERSION 3.0.0) + +# Setup project project(LwLibPROJECT VERSION 0.1.0) -include(CTest) -enable_testing() +# Add executable and library +add_executable(${PROJECT_NAME}) -add_executable(${PROJECT_NAME} - lwmem/src/lwmem/lwmem.c - lwmem/src/system/lwmem_sys_win32.c - tests/lwmem_test.c - dev/VisualStudio/main.c +# Add key executable block +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c ) target_include_directories(${PROJECT_NAME} PRIVATE - dev/VisualStudio - lwmem/src/include + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio ) target_compile_definitions(${PROJECT_NAME} PRIVATE @@ -23,6 +23,5 @@ target_compile_definitions(${PROJECT_NAME} PRIVATE LWMEM_DEV ) -set(CPACK_PROJECT_NAME ${PROJECT_NAME}) -set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) -include(CPack) +# Go to sub directory +add_subdirectory(lwmem) diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt new file mode 100644 index 0000000..17df494 --- /dev/null +++ b/lwmem/CMakeLists.txt @@ -0,0 +1,18 @@ +cmake_minimum_required(VERSION 3.0.0) + +# Check definitions of some key things +if(NOT DEFINED LWMEM_SYS_ARCH) + message("Warning: LWMEM_SYS_ARCH not defined. Using default one as \"win32\"") + set(LWMEM_SYS_ARCH "win32") +endif() + +# Add source files +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c + ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_ARCH}.c + ) + +# Add include files +target_include_directories(${PROJECT_NAME} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/src/include + ) From 62d0c40f015e6afd165cc7adadde794d71b90750 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 11:36:53 +0100 Subject: [PATCH 2/6] Allow cmakelists to be invoked as demo project or used by 3rd party as a library --- CMakeLists.txt | 45 +++++++++++++++++++++++++------------------- lwmem/CMakeLists.txt | 23 +++++++++++++++------- 2 files changed, 42 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f56aa93..fdc1cc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,34 @@ cmake_minimum_required(VERSION 3.0.0) # Setup project -project(LwLibPROJECT VERSION 0.1.0) +project(LwMEM VERSION 2.0.1) +set(LWMEM_LIB_NAME lwmem) -# Add executable and library -add_executable(${PROJECT_NAME}) +# ------------------------ +# Configuration used if this is used as +# top-level project CMakeLists.txt file +# This is normally used for development purpose only +if (PROJECT_IS_TOP_LEVEL) + add_executable(${PROJECT_NAME}) -# Add key executable block -target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c - ) + # Add key executable block + target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c + ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c + ) -target_include_directories(${PROJECT_NAME} PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio - ) + target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio + ) -target_compile_definitions(${PROJECT_NAME} PRIVATE - WIN32 - _DEBUG - CONSOLE - LWMEM_DEV - ) + target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE + LWMEM_DEV + ) +endif() -# Go to sub directory -add_subdirectory(lwmem) +# Add subdir with lwmem and link to the project +add_subdirectory("lwmem") +target_link_libraries(${PROJECT_NAME} lwmem) \ No newline at end of file diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index 17df494..c879856 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -1,18 +1,27 @@ -cmake_minimum_required(VERSION 3.0.0) +cmake_minimum_required(VERSION 3.13) + +# Debug message +message("LWMEM: Entering lib source CMakeLists.txt") + +# Set library name +set(LWMEM_LIB_NAME "lwmem") # Check definitions of some key things if(NOT DEFINED LWMEM_SYS_ARCH) - message("Warning: LWMEM_SYS_ARCH not defined. Using default one as \"win32\"") + message("LWMEM: LWMEM_SYS_ARCH not defined. Using default one: \"win32\"") set(LWMEM_SYS_ARCH "win32") endif() -# Add source files -target_sources(${PROJECT_NAME} PUBLIC +# Register library to the system +add_library(${LWMEM_LIB_NAME} INTERFACE) + +# Setup generic source files +target_sources(${LWMEM_LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_ARCH}.c ) -# Add include files -target_include_directories(${PROJECT_NAME} PRIVATE +# Setup include directories +target_include_directories(${LWMEM_LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include - ) + ) \ No newline at end of file From cbc215be11c7eea657537a4b920448885ec02bda Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 13:21:32 +0100 Subject: [PATCH 3/6] Update cmake to allow generation as lib or standalone --- CMakeLists.txt | 1 - lwmem/CMakeLists.txt | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fdc1cc2..4ed276e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.0.0) # Setup project project(LwMEM VERSION 2.0.1) -set(LWMEM_LIB_NAME lwmem) # ------------------------ # Configuration used if this is used as diff --git a/lwmem/CMakeLists.txt b/lwmem/CMakeLists.txt index c879856..0c87659 100644 --- a/lwmem/CMakeLists.txt +++ b/lwmem/CMakeLists.txt @@ -16,7 +16,7 @@ endif() add_library(${LWMEM_LIB_NAME} INTERFACE) # Setup generic source files -target_sources(${LWMEM_LIB_NAME} INTERFACE +target_sources(${LWMEM_LIB_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c ${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_ARCH}.c ) @@ -24,4 +24,4 @@ target_sources(${LWMEM_LIB_NAME} INTERFACE # Setup include directories target_include_directories(${LWMEM_LIB_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}/src/include - ) \ No newline at end of file + ) From d9f91da6df19de7a6e7f9704954350590979a602 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 14:01:17 +0100 Subject: [PATCH 4/6] Update cmake --- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- CMakeLists.txt | 12 +++++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8b95413..214334d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "(Windows) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}\\build\\LwLibPROJECT.exe", + "program": "${workspaceFolder}\\build\\LwMEM.exe", "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 309d100..26e109d 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -46,7 +46,7 @@ { "type": "shell", "label": "Run application", - "command": "${workspaceFolder}\\build\\LwLibPROJECT.exe", + "command": "${workspaceFolder}\\build\\LwMEM.exe", "args": [], "problemMatcher": [], }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ed276e..3655abf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.0.0) project(LwMEM VERSION 2.0.1) # ------------------------ -# Configuration used if this is used as +# Configuration used if cmake uses this as # top-level project CMakeLists.txt file # This is normally used for development purpose only if (PROJECT_IS_TOP_LEVEL) @@ -26,8 +26,10 @@ if (PROJECT_IS_TOP_LEVEL) CONSOLE LWMEM_DEV ) -endif() -# Add subdir with lwmem and link to the project -add_subdirectory("lwmem") -target_link_libraries(${PROJECT_NAME} lwmem) \ No newline at end of file + # Add subdir with lwmem and link to the project + add_subdirectory("lwmem") + target_link_libraries(${PROJECT_NAME} lwmem) +else() + message("LWMEM: For library link, use CMakeLists.txt in /lwmem directory") +endif() \ No newline at end of file From 54c9c1c07cd17cc339d2a515db2ed6bf162ef21c Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 15:19:24 +0100 Subject: [PATCH 5/6] Update cmake --- .vscode/launch.json | 2 +- .vscode/tasks.json | 2 +- CMakeLists.txt | 60 +++++++++++++++++++++++++-------------------- 3 files changed, 35 insertions(+), 29 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 214334d..8b95413 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "(Windows) Launch", "type": "cppdbg", "request": "launch", - "program": "${workspaceFolder}\\build\\LwMEM.exe", + "program": "${workspaceFolder}\\build\\LwLibPROJECT.exe", "miDebuggerPath": "c:\\msys64\\mingw64\\bin\\gdb.exe", "args": [], "stopAtEntry": false, diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 26e109d..309d100 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -46,7 +46,7 @@ { "type": "shell", "label": "Run application", - "command": "${workspaceFolder}\\build\\LwMEM.exe", + "command": "${workspaceFolder}\\build\\LwLibPROJECT.exe", "args": [], "problemMatcher": [], }, diff --git a/CMakeLists.txt b/CMakeLists.txt index 3655abf..287367b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,35 +1,41 @@ cmake_minimum_required(VERSION 3.0.0) # Setup project -project(LwMEM VERSION 2.0.1) +project(LwLibPROJECT VERSION 2.0.1) -# ------------------------ -# Configuration used if cmake uses this as -# top-level project CMakeLists.txt file -# This is normally used for development purpose only -if (PROJECT_IS_TOP_LEVEL) - add_executable(${PROJECT_NAME}) +# ------------------------------------------------- +# This CMakeLists.txt is used only if it is a top-level file. +# Purpose of it is to be able to compile project in standalone way only +# +# When library sources are to be included in another project +# user shall use /lwmem/CMakeLists.txt instead +if (NOT PROJECT_IS_TOP_LEVEL) + message(FATAL_ERROR "This CMakeLists.txt can only be used as top-level. Use /lwmem/CMakeLists.txt for library include purpose") +endif() - # Add key executable block - target_sources(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c - ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c - ) +# Set as executable +add_executable(${PROJECT_NAME}) - target_include_directories(${PROJECT_NAME} PUBLIC - ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio - ) +# Add key executable block +target_sources(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio/main.c + ${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c + ) - target_compile_definitions(${PROJECT_NAME} PUBLIC - WIN32 - _DEBUG - CONSOLE - LWMEM_DEV - ) +# Add key include paths +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio + ) - # Add subdir with lwmem and link to the project - add_subdirectory("lwmem") - target_link_libraries(${PROJECT_NAME} lwmem) -else() - message("LWMEM: For library link, use CMakeLists.txt in /lwmem directory") -endif() \ No newline at end of file +# Compilation definition information +target_compile_definitions(${PROJECT_NAME} PUBLIC + WIN32 + _DEBUG + CONSOLE + LWMEM_DEV + ) + +# Add subdir with lwmem and link to the project +add_subdirectory("lwmem") +target_link_libraries(${PROJECT_NAME} lwmem) \ No newline at end of file From bf4c384854146f54ec9b5d11ce26d17fb7bbe4c3 Mon Sep 17 00:00:00 2001 From: Tilen Majerle Date: Fri, 24 Dec 2021 18:57:03 +0100 Subject: [PATCH 6/6] Update CMake and split development and library --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 287367b..87cf561 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.0.0) # Setup project -project(LwLibPROJECT VERSION 2.0.1) +project(LwLibPROJECT) # ------------------------------------------------- # This CMakeLists.txt is used only if it is a top-level file.