mirror of
https://github.com/MaJerle/lwmem.git
synced 2025-01-13 21:42:53 +08:00
Improve the CMakeLists library usage
This commit is contained in:
parent
756a7bce1d
commit
05942ae576
@ -6,10 +6,7 @@ project(LwLibPROJECT)
|
||||
if(NOT PROJECT_IS_TOP_LEVEL)
|
||||
add_subdirectory(lwmem)
|
||||
else()
|
||||
# Set as executable
|
||||
add_executable(${PROJECT_NAME})
|
||||
|
||||
# Add key executable block
|
||||
target_sources(${PROJECT_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/dev/main.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c
|
||||
@ -17,31 +14,17 @@ else()
|
||||
# win32 port
|
||||
${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c
|
||||
)
|
||||
|
||||
# Add key include paths
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
${CMAKE_CURRENT_LIST_DIR}/dev
|
||||
)
|
||||
|
||||
# Compilation definition information
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC
|
||||
WIN32
|
||||
_DEBUG
|
||||
CONSOLE
|
||||
LWMEM_DEV
|
||||
)
|
||||
|
||||
# Compiler options
|
||||
target_compile_options(${PROJECT_NAME} PRIVATE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
)
|
||||
|
||||
# Add subdir with lwmem and link to the project
|
||||
set(LWMEM_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/dev/lwmem_opts.h)
|
||||
add_subdirectory(lwmem)
|
||||
target_link_libraries(${PROJECT_NAME} lwmem)
|
||||
target_link_libraries(${PROJECT_NAME} lwmem_cpp)
|
||||
target_link_libraries(${PROJECT_NAME} PUBLIC lwmem_cpp)
|
||||
|
||||
# Add compile options to the library, which will propagate options to executable through public link
|
||||
target_compile_definitions(lwmem PUBLIC WIN32 _DEBUG CONSOLE LWMEM_DEV)
|
||||
target_compile_options(lwmem PUBLIC -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
|
@ -1,4 +1,4 @@
|
||||
#
|
||||
#
|
||||
# LIB_PREFIX: LWMEM
|
||||
#
|
||||
# This file provides set of variables for end user
|
||||
@ -16,12 +16,12 @@
|
||||
set(LWMEM_CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib_inc)
|
||||
|
||||
# Library core sources
|
||||
set(lwmem_core_SRCS
|
||||
set(lwmem_core_SRCS
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.c
|
||||
)
|
||||
|
||||
# C++ extension
|
||||
set(lwmem_core_cpp_SRCS
|
||||
set(lwmem_core_cpp_SRCS
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/lwmem/lwmem.cpp
|
||||
)
|
||||
|
||||
@ -33,9 +33,9 @@ set(lwmem_include_DIRS
|
||||
|
||||
# Add system port
|
||||
if(DEFINED LWMEM_SYS_PORT)
|
||||
set(lwmem_core_SRCS ${lwmem_core_SRCS}
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_PORT}.c
|
||||
)
|
||||
set(lwmem_core_SRCS ${lwmem_core_SRCS}
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/system/lwmem_sys_${LWMEM_SYS_PORT}.c
|
||||
)
|
||||
endif()
|
||||
|
||||
# Register core library
|
||||
@ -51,6 +51,7 @@ target_sources(lwmem_cpp PRIVATE ${lwmem_core_SRCS})
|
||||
target_include_directories(lwmem_cpp PUBLIC ${lwmem_include_DIRS})
|
||||
target_compile_options(lwmem_cpp PRIVATE ${LWMEM_COMPILE_OPTIONS})
|
||||
target_compile_definitions(lwmem_cpp PRIVATE ${LWMEM_COMPILE_DEFINITIONS})
|
||||
target_link_libraries(lwmem_cpp PUBLIC lwmem)
|
||||
|
||||
# Create config file if user didn't provide one info himself
|
||||
if(NOT LWMEM_OPTS_FILE)
|
||||
@ -59,5 +60,5 @@ if(NOT LWMEM_OPTS_FILE)
|
||||
else()
|
||||
message(STATUS "Using custom lwmem_opts.h file from ${LWMEM_OPTS_FILE}")
|
||||
endif()
|
||||
configure_file(${LWMEM_OPTS_FILE} ${LWMEM_CUSTOM_INC_DIR}/lwmem_opts.h COPYONLY)
|
||||
|
||||
configure_file(${LWMEM_OPTS_FILE} ${LWMEM_CUSTOM_INC_DIR}/lwmem_opts.h COPYONLY)
|
||||
|
Loading…
x
Reference in New Issue
Block a user