Skip to content

Commit

Permalink
Update CMake and split development and library
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Dec 24, 2021
1 parent 61b5253 commit 6d9b655
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 19 deletions.
49 changes: 30 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,42 @@
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}
lwow/src/lwow/lwow.c
lwow/src/system/lwow_ll_win32.c
lwow/src/system/lwow_sys_win32.c
lwow/src/devices/lwow_device_ds18x20.c
snippets/scan_devices.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 /lwow/CMakeLists.txt instead
if (NOT PROJECT_IS_TOP_LEVEL)
message(FATAL_ERROR "This CMakeLists.txt can only be used as top-level. Use /lwow/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
)

target_include_directories(${PROJECT_NAME} PRIVATE
dev/VisualStudio
lwow/src/include
snippets/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
TEST_CONSOLE_123
LWOW_DEV
)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
# Add subdir with lwow and link to the project
add_subdirectory("lwow")
target_link_libraries(${PROJECT_NAME} lwow)
add_subdirectory("snippets")
target_link_libraries(${PROJECT_NAME} lwow_snippets)
33 changes: 33 additions & 0 deletions lwow/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.13)

# Debug message
message("LWOW: Entering lib source CMakeLists.txt")

# Set library name
set(LWOW_LIB_NAME "lwow")

# Check definitions of some key things
if(NOT DEFINED LWOW_SYS_ARCH)
message("LWOW: LWOW_SYS_ARCH not defined. Using default one: \"win32\"")
set(LWOW_SYS_ARCH "win32")
endif()
if(NOT DEFINED LWOW_LL_ARCH)
message("LWOW: LWOW_LL_ARCH not defined. Using default one: \"win32\"")
set(LWOW_LL_ARCH "win32")
endif()

# Register library to the system
add_library(${LWOW_LIB_NAME} INTERFACE)

# Setup generic source files
target_sources(${LWOW_LIB_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/lwow/lwow.c
${CMAKE_CURRENT_LIST_DIR}/src/system/lwow_sys_${LWOW_SYS_ARCH}.c
${CMAKE_CURRENT_LIST_DIR}/src/system/lwow_ll_${LWOW_LL_ARCH}.c
${CMAKE_CURRENT_LIST_DIR}/src/devices/lwow_device_ds18x20.c
)

# Setup include directories
target_include_directories(${LWOW_LIB_NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/src/include
)
20 changes: 20 additions & 0 deletions snippets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.13)

# Debug message
message("LWOW SNIPPETS: Entering lib source CMakeLists.txt")

# Set library name
set(LWOW_SNIPPETS_LIB_NAME "lwow_snippets")

# Register library to the system
add_library(${LWOW_SNIPPETS_LIB_NAME} INTERFACE)

# Setup generic source files
target_sources(${LWOW_SNIPPETS_LIB_NAME} PUBLIC
${CMAKE_CURRENT_LIST_DIR}/scan_devices.c
)

# Setup include directories
target_include_directories(${LWOW_SNIPPETS_LIB_NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/include
)

0 comments on commit 6d9b655

Please sign in to comment.