summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrédéric Desbiens <[email protected]>2026-08-15 17:28:33 -0400
committerGitHub <[email protected]>2026-08-15 17:28:33 -0400
commit09c190a71d83b2ba993a1d2e3e2adbf2c710f3a8 (patch)
tree135c94bf6dff9f2cad4616d932821555ee1380ef
parent1296cf1740e592338ea5203190b8761eb4b80fbf (diff)
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) <[email protected]>
-rw-r--r--ports/linux/gnu/CMakeLists.txt9
-rw-r--r--ports/linux/gnu/example_build/CMakeLists.txt17
-rw-r--r--ports_smp/linux/gnu/CMakeLists.txt7
-rw-r--r--ports_smp/linux/gnu/example_build/CMakeLists.txt17
4 files changed, 49 insertions, 1 deletions
diff --git a/ports/linux/gnu/CMakeLists.txt b/ports/linux/gnu/CMakeLists.txt
index 4b517940..073f4b7e 100644
--- a/ports/linux/gnu/CMakeLists.txt
+++ b/ports/linux/gnu/CMakeLists.txt
@@ -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") \ No newline at end of file
+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()
diff --git a/ports/linux/gnu/example_build/CMakeLists.txt b/ports/linux/gnu/example_build/CMakeLists.txt
new file mode 100644
index 00000000..90d4078a
--- /dev/null
+++ b/ports/linux/gnu/example_build/CMakeLists.txt
@@ -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)
diff --git a/ports_smp/linux/gnu/CMakeLists.txt b/ports_smp/linux/gnu/CMakeLists.txt
index 6ad4d25b..67209ee7 100644
--- a/ports_smp/linux/gnu/CMakeLists.txt
+++ b/ports_smp/linux/gnu/CMakeLists.txt
@@ -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()
diff --git a/ports_smp/linux/gnu/example_build/CMakeLists.txt b/ports_smp/linux/gnu/example_build/CMakeLists.txt
new file mode 100644
index 00000000..90d4078a
--- /dev/null
+++ b/ports_smp/linux/gnu/example_build/CMakeLists.txt
@@ -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)