diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ed7aec..87cf561 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,41 @@ cmake_minimum_required(VERSION 3.0.0) -project(LwLibPROJECT VERSION 0.1.0) -include(CTest) -enable_testing() +# Setup project +project(LwLibPROJECT) -add_executable(${PROJECT_NAME} - lwmem/src/lwmem/lwmem.c - lwmem/src/system/lwmem_sys_win32.c - tests/lwmem_test.c - dev/VisualStudio/main.c +# ------------------------------------------------- +# 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() + +# Set as executable +add_executable(${PROJECT_NAME}) + +# 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 - dev/VisualStudio - lwmem/src/include +# Add key include paths +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_LIST_DIR}/dev/VisualStudio ) -target_compile_definitions(${PROJECT_NAME} PRIVATE +# Compilation definition information +target_compile_definitions(${PROJECT_NAME} PUBLIC WIN32 _DEBUG CONSOLE LWMEM_DEV ) -set(CPACK_PROJECT_NAME ${PROJECT_NAME}) -set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) -include(CPack) +# 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 new file mode 100644 index 0000000..0c87659 --- /dev/null +++ b/lwmem/CMakeLists.txt @@ -0,0 +1,27 @@ +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("LWMEM: LWMEM_SYS_ARCH not defined. Using default one: \"win32\"") + set(LWMEM_SYS_ARCH "win32") +endif() + +# Register library to the system +add_library(${LWMEM_LIB_NAME} INTERFACE) + +# Setup generic source files +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 + ) + +# Setup include directories +target_include_directories(${LWMEM_LIB_NAME} INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/src/include + )