Issue
I know the build philosophy of CMake is "dependency" based and not necessarily in the order of how tasks are noted down in the CMake list.
But when it comes to message(STATUS ...)
I need them to display in order, otherwise they don't make sense.
Can I somehow tell CMake to run this sequentially?
Example:
message(STATUS "[LOG] COMPILER_PREFIX =${COMPILER_PREFIX}")
message(STATUS "[LOG] CMAKE_SOURCE_DIR =${CMAKE_SOURCE_DIR}")
message(STATUS "[LOG] CMAKE_C_COMPILER =${CMAKE_C_COMPILER}")
message(STATUS "[LOG] CMAKE_C_FLAGS =${CMAKE_C_FLAGS}")
message(STATUS "[LOG] CMAKE_C_LINK_EXECUTABLE =${CMAKE_C_LINK_EXECUTABLE}")
message(STATUS "[LOG] CMAKE_EXE_LINKER_FLAGS =${CMAKE_EXE_LINKER_FLAGS}")
message(STATUS "[LOG] CMAKE_AR =${CMAKE_AR}")
message(STATUS "[LOG] Definitions: ")
get_directory_property(defs DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
foreach (def ${defs})
message([STATUS] " -D${def}")
endforeach ()
get_property(dirs TARGET ${PROJECT_NAME} PROPERTY INCLUDE_DIRECTORIES)
message(STATUS "[LOG] Includes: ")
foreach (dir ${dirs})
message([STATUS] " ${dir}")
endforeach ()
get_property(libs TARGET ${PROJECT_NAME} PROPERTY LINK_LIBRARIES)
message(STATUS "[LOG] Libraries:")
foreach (libs ${libs})
message([STATUS] " ${libs}")
endforeach ()
The prints as follows:
[STATUS] -DDUMMY
[STATUS] -D__SL__
[STATUS] -DMCU
-- [LOG] COMPILER_PREFIX =
-- [LOG] CMAKE_SOURCE_DIR = /home/dummy/workspace/project
-- [LOG] CMAKE_C_COMPILER = gcc
[STATUS] /home/dummy/workspace/project/inc
-- [LOG] CMAKE_C_FLAGS =-std=gnu11 -Wextra -Wall -Wno-unused-parameter
[STATUS] -lgcc
[STATUS] -lc
[STATUS] -lgcc
[STATUS] -lc
....
Solution
This is mixing stdout and stderr outputs and will not print "in order".
From the CMake documentation for v3.25:
The CMake command-line tool displays STATUS to TRACE messages on stdout with the message preceded by two hyphens and a space. All other message types are sent to stderr and are not prefixed with hyphens.
So when using message([<mode>] "message text" ...)
choose a single mode instead of mixing them.
Answered By - fdk1342 Answer Checked By - Gilberto Lyons (WPSolving Admin)