Skip to content

Commit df31667

Browse files
committed
Improve the CMakeLists library usage
1 parent 61e43d6 commit df31667

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

CMakeLists.txt

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,21 @@ project(LwLibPROJECT C)
66
if(NOT PROJECT_IS_TOP_LEVEL)
77
add_subdirectory(lwrb)
88
else()
9-
# Set as executable
109
add_executable(${PROJECT_NAME})
11-
12-
# Add key executable block
13-
target_sources(${PROJECT_NAME} PUBLIC
10+
target_sources(${PROJECT_NAME} PRIVATE
1411
${CMAKE_CURRENT_LIST_DIR}/dev/main.c
1512
)
16-
17-
# Add key include paths
1813
target_include_directories(${PROJECT_NAME} PUBLIC
1914
${CMAKE_CURRENT_LIST_DIR}/dev
2015
)
2116

22-
# Compilation definition information
23-
target_compile_definitions(${PROJECT_NAME} PUBLIC
24-
WIN32
25-
_DEBUG
26-
CONSOLE
27-
)
28-
29-
# Compiler options
30-
target_compile_options(${PROJECT_NAME} PRIVATE
31-
-Wall
32-
-Wextra
33-
-Wpedantic
34-
)
35-
3617
# Add subdir with lwrb and link to project
3718
set(LWRB_COMPILE_DEFINITIONS LWRB_DEV)
3819
add_subdirectory(lwrb)
3920
target_link_libraries(${PROJECT_NAME} lwrb)
4021
target_link_libraries(${PROJECT_NAME} lwrb_ex)
22+
23+
# Add compile options to the library, which will propagate options to executable through public link
24+
target_compile_definitions(lwrb PUBLIC WIN32 _DEBUG CONSOLE LWRB_DEV)
25+
target_compile_options(lwrb PUBLIC -Wall -Wextra -Wpedantic)
4126
endif()

lwrb/library.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#
1+
#
22
# LIB_PREFIX: LWRB
33
#
44
# This file provides set of variables for end user
@@ -14,12 +14,12 @@
1414
set(LWRB_CUSTOM_INC_DIR ${CMAKE_CURRENT_BINARY_DIR}/lib_inc)
1515

1616
# Library core sources
17-
set(lwrb_core_SRCS
17+
set(lwrb_core_SRCS
1818
${CMAKE_CURRENT_LIST_DIR}/src/lwrb/lwrb.c
1919
)
2020

2121
# Library extended sources
22-
set(lwrb_ex_SRCS
22+
set(lwrb_ex_SRCS
2323
${CMAKE_CURRENT_LIST_DIR}/src/lwrb/lwrb_ex.c
2424
)
2525

@@ -42,3 +42,4 @@ target_sources(lwrb_ex PRIVATE ${lwrb_ex_SRCS})
4242
target_include_directories(lwrb_ex PUBLIC ${lwrb_include_DIRS})
4343
target_compile_options(lwrb_ex PRIVATE ${LWRB_COMPILE_OPTIONS})
4444
target_compile_definitions(lwrb_ex PRIVATE ${LWRB_COMPILE_DEFINITIONS} LWRB_EXTENDED)
45+
target_link_libraries(lwrb_ex PUBLIC lwrb)

0 commit comments

Comments
 (0)