mirror of
https://github.com/eclipse-threadx/threadx.git
synced 2026-10-06 06:59:08 +08:00
Added a CMake target for the Linux sample program (#622)
The CMake build produced libthreadx.a and nothing else, so trying ThreadX on
Linux meant using the Makefile beside the port instead. Build the demo the
Makefile builds, for the linux port and its SMP counterpart.
The target is behind an option that defaults off, so an ordinary build is
unchanged and still produces just the library. -DTHREADX_SAMPLE=ON adds it:
cmake -S . -B build -DTHREADX_ARCH=linux -DTHREADX_TOOLCHAIN=gnu \
-DTHREADX_SAMPLE=ON
cmake --build build --target sample_threadx
The include path uses TX_COMMON_DIR rather than naming common or common_smp,
since the top level already resolves which of the two applies.
Verified by building and running both variants. Non-SMP prints
**** ThreadX Linux Demonstration **** (c) 1996-2020 Microsoft Corporation
and SMP prints the SMP banner, both with the demo's thread counters advancing. A
default configure with no THREADX_SAMPLE has no sample_threadx target and still
produces libthreadx.a, so nothing existing moves.
Derived from the two example_build files in #404 by Yanfeng Liu, which had the
same goal. That change also rewrote the top level's SMP selection, added
common_smp/CMakeLists.txt and added ports_smp/linux/gnu/CMakeLists.txt; all three
have since arrived on dev by other routes, so only the sample targets were still
missing. The include path needed adjusting because the original depended on
THREADX_SMP being a string suffix, which it no longer is.
Assisted-by: Claude Code (Opus 5) <noreply@anthropic.com>
This commit is contained in:
@@ -19,4 +19,11 @@ target_include_directories(${PROJECT_NAME}
|
||||
${CMAKE_CURRENT_LIST_DIR}/inc
|
||||
)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC "-D_GNU_SOURCE -DTX_LINUX_DEBUG_ENABLE")
|
||||
target_compile_definitions(${PROJECT_NAME} PUBLIC "-D_GNU_SOURCE -DTX_LINUX_DEBUG_ENABLE")
|
||||
|
||||
# The demo program beside the port. Off by default so the ordinary build
|
||||
# produces just the library; -DTHREADX_SAMPLE=ON adds the sample_threadx target.
|
||||
option(THREADX_SAMPLE "Build the sample program for this port" OFF)
|
||||
if(THREADX_SAMPLE)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/example_build)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Build the sample_threadx program that ports/linux/gnu/Makefile builds, so the
|
||||
# CMake build can produce a runnable demo rather than only the library.
|
||||
#
|
||||
# Guarded by THREADX_SAMPLE in the parent so the default build stays a pure
|
||||
# library build.
|
||||
|
||||
add_executable(sample_threadx)
|
||||
|
||||
target_sources(sample_threadx PRIVATE ${CMAKE_CURRENT_LIST_DIR}/sample_threadx.c)
|
||||
|
||||
target_include_directories(sample_threadx
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../inc
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../../${TX_COMMON_DIR}/inc
|
||||
)
|
||||
|
||||
target_link_libraries(sample_threadx PRIVATE threadx)
|
||||
@@ -31,3 +31,10 @@ target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}/inc
|
||||
)
|
||||
|
||||
# The demo program beside the port. Off by default so the ordinary build
|
||||
# produces just the library; -DTHREADX_SAMPLE=ON adds the sample_threadx target.
|
||||
option(THREADX_SAMPLE "Build the sample program for this port" OFF)
|
||||
if(THREADX_SAMPLE)
|
||||
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/example_build)
|
||||
endif()
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
# Build the sample_threadx program that ports/linux/gnu/Makefile builds, so the
|
||||
# CMake build can produce a runnable demo rather than only the library.
|
||||
#
|
||||
# Guarded by THREADX_SAMPLE in the parent so the default build stays a pure
|
||||
# library build.
|
||||
|
||||
add_executable(sample_threadx)
|
||||
|
||||
target_sources(sample_threadx PRIVATE ${CMAKE_CURRENT_LIST_DIR}/sample_threadx.c)
|
||||
|
||||
target_include_directories(sample_threadx
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/../inc
|
||||
${CMAKE_CURRENT_LIST_DIR}/../../../../${TX_COMMON_DIR}/inc
|
||||
)
|
||||
|
||||
target_link_libraries(sample_threadx PRIVATE threadx)
|
||||
Reference in New Issue
Block a user