Skip to content

Commit

Permalink
Improve the CMakeLists library usage
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Sep 4, 2024
1 parent 3cfbb60 commit 19df8ad
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,22 @@ project(LwLibPROJECT)
if(NOT PROJECT_IS_TOP_LEVEL)
add_subdirectory(lwprintf)
else()
# Set as executable
add_executable(${PROJECT_NAME})

# Add key executable block
target_sources(${PROJECT_NAME} PUBLIC
target_sources(${PROJECT_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/dev/main.c
${CMAKE_CURRENT_LIST_DIR}/lwprintf/src/system/lwprintf_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
LWPRINTF_DEV
)

# Compiler options
target_compile_options(${PROJECT_NAME} PRIVATE
-Wall
-Wextra
-Wpedantic
)

# Add subdir with lwprintf and link to the project
set(LWPRINTF_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/dev/lwprintf_opts.h)
add_subdirectory(lwprintf)
target_link_libraries(${PROJECT_NAME} lwprintf)

# Add compile options to the library, which will propagate options to executable through public link
target_compile_definitions(lwprintf PUBLIC WIN32 _DEBUG CONSOLE LWPRINTF_DEV)
target_compile_options(lwprintf PUBLIC -Wall -Wextra -Wpedantic)
endif()

0 comments on commit 19df8ad

Please sign in to comment.