Skip to content

linux/gnu: add cmake for sample - #404

Closed
yf13 wants to merge 4 commits into
eclipse-threadx:masterfrom
yf13:linux-sample-cmake
Closed

linux/gnu: add cmake for sample#404
yf13 wants to merge 4 commits into
eclipse-threadx:masterfrom
yf13:linux-sample-cmake

Conversation

@yf13

@yf13 yf13 commented Sep 2, 2024

Copy link
Copy Markdown

This adds CMake support for linux/gnu/example_build so that to have the sample_threadx target built after the libthreadx.a target, make it easier for people to try the sample on Linux.

@yf13 yf13 changed the title ports/linux/gnu: add cmake for sample program linux/gnu: add cmake for sample Sep 2, 2024
@yf13
yf13 force-pushed the linux-sample-cmake branch from d076032 to 4398acd Compare September 5, 2024 01:43
This allows to build `sample_threadx` together with `libthreadx.a`.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
@yf13
yf13 force-pushed the linux-sample-cmake branch from 4398acd to 17c656e Compare September 5, 2024 10:21
This allows one to build `sample_threadx` with `libthreadx.a` by
adding `-DTHREADX_SAMPLE=1` to cmake command line.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
This allows to build SMP variant `libthreadx.a` with cmake.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
@yf13
yf13 force-pushed the linux-sample-cmake branch 2 times, most recently from 599709d to b70e00e Compare September 21, 2024 03:21
This allows to build SMP variant of `linux/gnu` port, and optionally
with `sample_threadx`.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
@fdesbiens

Copy link
Copy Markdown
Contributor

Thank you for this, and apologies that it sat for so long.

The goal is right and it is still missing: the CMake build produces only the library, so trying ThreadX on Linux means using the Makefile instead. I have opened #622 to add it, derived from your two example_build/CMakeLists.txt files.

I am closing this one rather than rebasing it, and I would rather explain why than leave it looking like a rejection.

Four of the six files here have since arrived on dev by other routes: the top level's SMP selection, common_smp/CMakeLists.txt, ports/linux/gnu/CMakeLists.txt and ports_smp/linux/gnu/CMakeLists.txt. That is what the conflict is. Only the two sample targets were still missing, and those are what #622 carries.

Two details from the superseded part are worth passing back, since they may be useful to you elsewhere.

The SMP switch used if(DEFINED THREADX_SMP), which is true whenever the variable exists at all, so -DTHREADX_SMP=OFF selected the SMP build:

invocation resulting suffix
-DTHREADX_SMP=OFF _smp
no flag (empty)
-DTHREADX_SMP=ON _smp

dev now uses option() with if(THREADX_SMP), which treats OFF as off.

And the path scheme built ports_smp/${THREADX_ARCH}/... with no suffix on the architecture. That works for linux and win64, which predate the naming convention, but not for the ports named <arch>_smp. dev appends the suffix and falls back to the bare name for exactly those two.

One change was needed to your example files themselves: they read common${THREADX_SMP}/inc, which relied on THREADX_SMP being a string suffix. It is a boolean now, so that expands to commonON; #622 uses ${TX_COMMON_DIR} instead, which the top level already resolves.

Both variants now build and run — the non-SMP demo prints its banner and counters, and the SMP one prints the SMP banner. Credit for the idea and the starting point is recorded in #622 and in its commit message. Thank you for the contribution, and for #403, which was merged.

@fdesbiens fdesbiens closed this Aug 15, 2026
fdesbiens added a commit that referenced this pull request Aug 15, 2026
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>
akifejaz pushed a commit to akifejaz/threadx that referenced this pull request Aug 17, 2026
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 eclipse-threadx#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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants