Skip to content

Conversation

@zachcran
Copy link
Contributor

@zachcran zachcran commented Jul 27, 2025

Is this pull request associated with an issue(s)?

Closes #116

Description

Implements @josephgarnier's suggested fix for the issues described in #116.

TODOs

Testing

It is quite difficult to test this override to message functionality programmatically. However, I have tested this implementation manually with a slightly more extensive set than set forth in the issue and seen no issues. I have also only tested with message( and message(STATUS, though, not the other possible message modes. Here is my testing method (on a Linux system):

  1. Create a new directory for this testing and navigate into it:
    mkdir test_116_fix
    cd test_116_fix
  2. Clone and check out this branch:
    git clone git@github.com:CMakePP/CMakeTest cmaketest
    git checkout 116_message_override_fix
  3. Create test_116_fix/CMakeLists.txt for the testing with the same contents as this file: https://github.com/user-attachments/files/21456416/CMakeLists.txt (contents are pasted below)
  4. Configure the project
    cmake -H. -Bbuild -DFETCHCONTENT_SOURCE_DIR_CMAKE_TEST="$PWD/cmaketest"
  5. Check that the [cmaketest] output matches the [vanilla] output. (I just ran it in two side-by-side terminals and manually compared, but I'm sure you could use diff as well)

Testing Project CMakeLists.txt contents

I understand potential hesitancy to download files from the Internet that you will need to run (even if it is uploaded on GitHub like the link above). I have included the contents of the the testing project CMakeLists.txt below so you can see the file contents before downloading it or for reference if the link above stops working, but without interrupting the flow of the testing steps with a massive file.

Contents of CMakeLists.txt:

cmake_minimum_required(VERSION 3.19)
project(issue_116_testing VERSION 1.0.0 LANGUAGES NONE)

message(STATUS "CMake Vanilla Output")
list(APPEND CMAKE_MESSAGE_INDENT "[vanilla] ")

list(APPEND CMAKE_MESSAGE_INDENT "[string] ")
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
message("")
message("a")
message("a b")
message("a;b")
message("a" "b")
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(APPEND CMAKE_MESSAGE_INDENT "[STATUS] ")
message(STATUS "")
message(STATUS "a")
message(STATUS "a b")
message(STATUS "a;b")
message(STATUS "a" "b")
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)

list(APPEND CMAKE_MESSAGE_INDENT "[quote_var] ")
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
set(input_text "")
message("${input_text}") # should give nothing
set(input_text "a")
message("${input_text}") # should give "a"
set(input_text "a b")
message("${input_text}") # should give "a b"
set(input_text "a;b")
message("${input_text}") # should give "a;b"
set(input_text "a" "b")
message("${input_text}") # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
set(input_text "")
message(STATUS "${input_text}") # should give nothing
set(input_text "a")
message(STATUS "${input_text}") # should give "a"
set(input_text "a b")
message(STATUS "${input_text}") # should give "a b"
set(input_text "a;b")
message(STATUS "${input_text}") # should give "a;b"
set(input_text "a" "b")
message(STATUS "${input_text}") # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)

list(APPEND CMAKE_MESSAGE_INDENT "[unquote_var] ")
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
# set(input_text "")
# message(${input_text}) # ERROR
set(input_text "a")
message(${input_text}) # should give "a"
set(input_text "a b")
message(${input_text}) # should give "a b"
set(input_text "a;b")
message(${input_text}) # should give "a;b"
set(input_text "a" "b")
message(${input_text}) # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(APPEND CMAKE_MESSAGE_INDENT "[STATUS] ")
set(input_text "")
message(STATUS ${input_text}) # should give nothing
set(input_text "a")
message(STATUS ${input_text}) # should give "a"
set(input_text "a b")
message(STATUS ${input_text}) # should give "a b"
set(input_text "a;b")
message(STATUS ${input_text}) # should give "a;b"
set(input_text "a" "b")
message(STATUS ${input_text}) # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)

list(APPEND CMAKE_MESSAGE_INDENT "[unquoted_text] ")
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
# set(input_text)
# message(${input_text}) # Error
set(input_text a)
message(${input_text}) # should give "a"
set(input_text a b)
message(${input_text}) # should give "a b"
set(input_text a;b)
message(${input_text}) # should give "a;b"
set(input_text a b)
message(${input_text}) # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(APPEND CMAKE_MESSAGE_INDENT "[STATUS] ")
# set(input_text)
# message(${input_text}) # Error
set(input_text a)
message(STATUS ${input_text}) # should give "a"
set(input_text a b)
message(STATUS ${input_text}) # should give "a b"
set(input_text a;b)
message(STATUS ${input_text}) # should give "a;b"
set(input_text a b)
message(STATUS ${input_text}) # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)

set(input_list A B C)
message("${input_list}") # would give A;B;C
set(input_list "A" "B" "C")
message("${input_list}") # would give A;B;C
set(input_list "A" "B" "C")
message(${input_list}) # would give ABC
list(POP_BACK CMAKE_MESSAGE_INDENT)


include("cmake/get_cmaketest.cmake")

message(STATUS "CMakeTest Override Output")
list(APPEND CMAKE_MESSAGE_INDENT "[cmaketest] ")

list(APPEND CMAKE_MESSAGE_INDENT "[string] ")
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
message("")
message("a")
message("a b")
message("a;b")
message("a" "b")
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(APPEND CMAKE_MESSAGE_INDENT "[STATUS] ")
message(STATUS "")
message(STATUS "a")
message(STATUS "a b")
message(STATUS "a;b")
message(STATUS "a" "b")
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)

list(APPEND CMAKE_MESSAGE_INDENT "[quote_var] ")
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
set(input_text "")
message("${input_text}") # should give nothing
set(input_text "a")
message("${input_text}") # should give "a"
set(input_text "a b")
message("${input_text}") # should give "a b"
set(input_text "a;b")
message("${input_text}") # should give "a;b"
set(input_text "a" "b")
message("${input_text}") # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
set(input_text "")
message(STATUS "${input_text}") # should give nothing
set(input_text "a")
message(STATUS "${input_text}") # should give "a"
set(input_text "a b")
message(STATUS "${input_text}") # should give "a b"
set(input_text "a;b")
message(STATUS "${input_text}") # should give "a;b"
set(input_text "a" "b")
message(STATUS "${input_text}") # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)

list(APPEND CMAKE_MESSAGE_INDENT "[unquote_var] ")
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
# set(input_text "")
# message(${input_text}) # ERROR
set(input_text "a")
message(${input_text}) # should give "a"
set(input_text "a b")
message(${input_text}) # should give "a b"
set(input_text "a;b")
message(${input_text}) # should give "a;b"
set(input_text "a" "b")
message(${input_text}) # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(APPEND CMAKE_MESSAGE_INDENT "[STATUS] ")
set(input_text "")
message(STATUS ${input_text}) # should give nothing
set(input_text "a")
message(STATUS ${input_text}) # should give "a"
set(input_text "a b")
message(STATUS ${input_text}) # should give "a b"
set(input_text "a;b")
message(STATUS ${input_text}) # should give "a;b"
set(input_text "a" "b")
message(STATUS ${input_text}) # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)

list(APPEND CMAKE_MESSAGE_INDENT "[unquoted_text] ")
list(APPEND CMAKE_MESSAGE_INDENT "[no_STATUS] ")
# set(input_text)
# message(${input_text}) # Error
set(input_text a)
message(${input_text}) # should give "a"
set(input_text a b)
message(${input_text}) # should give "a b"
set(input_text a;b)
message(${input_text}) # should give "a;b"
set(input_text a b)
message(${input_text}) # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(APPEND CMAKE_MESSAGE_INDENT "[STATUS] ")
# set(input_text)
# message(${input_text}) # Error
set(input_text a)
message(STATUS ${input_text}) # should give "a"
set(input_text a b)
message(STATUS ${input_text}) # should give "a b"
set(input_text a;b)
message(STATUS ${input_text}) # should give "a;b"
set(input_text a b)
message(STATUS ${input_text}) # should give "ab"
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)
list(POP_BACK CMAKE_MESSAGE_INDENT)

set(input_list A B C)
message("${input_list}") # would give A;B;C
set(input_list "A" "B" "C")
message("${input_list}") # would give A;B;C
set(input_list "A" "B" "C")
message(${input_list}) # would give ABC
list(POP_BACK CMAKE_MESSAGE_INDENT)

@zachcran zachcran self-assigned this Jul 27, 2025
@zachcran zachcran marked this pull request as ready for review July 27, 2025 22:23
@zachcran zachcran requested a review from ryanmrichard July 27, 2025 22:23
@zachcran
Copy link
Contributor Author

@josephgarnier Can you pull this branch down and verify that it still works for you, please?

@josephgarnier
Copy link

josephgarnier commented Jul 28, 2025

Wow, great test coverage.

With my fix, I had already noticed a display problem when the exception was thrown. I imagine that the problem also occurs with this PR.

The code:

message(FATAL_ERROR "REMOVE requires exactly 2 arguments, got ${nb_args}!")

displays the status in text:

[cmake] CMake Error at build/x64-Release-Win-GCC/_deps/cmake_test-src/cmake/cmake_test/overrides.cmake:113 (_message):
[cmake]   Testing forcibly stopped, no further tests will be executed.  Details:
[cmake]   Uncaught exception: FATAL_ERROR;REMOVE requires exactly 2 arguments, got 1! # <================
[cmake] Call Stack (most recent call first):
[cmake]   build/x64-Release-Win-GCC/_deps/cmake_test-src/cmake/cmake_test/overrides.cmake:48 (ct_exit)
[cmake]   cmake/modules/Map.cmake:495 (message)
[cmake]   cmake/modules/Map.cmake:192 (_map_remove)
[cmake]   CMakeLists.txt:163 (map)

I don't know enough about the internal mechanics of CMakeTest to have been able to fix it.

@zachcran
Copy link
Contributor Author

zachcran commented Aug 7, 2025

Thanks for the heads up, I didn't think to check when the exception is thrown! I'll check it out.

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.

[BUG] Overloaded message command strip semicolon characters in lists

4 participants