Skip to content

Typo in cmake/test.cmake #3902

Description

@m-hilgendorf

Description

At line 260 in cmake/test.cmake there is this code

        include(CheckTypeSize)
        check_type_size("size_t" sizeof_size_t LANGUAGE CXX)
        if(sizeof_size_t AND ${sizeof_size_t} EQUAL 4)
            message(STATUS "Auto-enabling 32bit unit test.")
            set(${build_32bit_var} ON)
        else()
            set(${build_32bit_var} OFF)
        endif()

The conditional check

        if(sizeof_size_t AND ${sizeof_size_t} EQUAL 4)

The first condition if(sizeof_size_t is always TRUE, since it is comparing against the string value "sizeof_size_t". To check if the string is empty (meaning check_type_size could not return a value for size_t) it should be

        if(${sizeof_size_t} AND ${sizeof_size_t} EQUAL 4)

If for some reason the size of size_t is unknown (for example, using exotic toolchains where stddef.h might not be visible during the initial cmake evaluation) this will cause the invocation of cmake to fail.

Reproduction steps

Replace the call to check_type_size with

set(sizeof_size_t "")

Expected vs. actual results

Running cmake . should not fail.

Minimal code example

No response

Error messages

if given arguments:

    "sizeof_size_t" "AND" "EQUAL" "4"

  Unknown arguments specified


### Compiler and operating system

gcc 11.2.0, Linux

### Library version

3.11.2

### Validation

- [X] The bug also occurs if the latest version from the [`develop`](https://github.com/nlohmann/json/tree/develop) branch is used.
- [ ] I can successfully [compile and run the unit tests](https://github.com/nlohmann/json#execute-unit-tests).

Activity

  1. nlohmann commented on Dec 29, 2022

    @nlohmann
    Owner

    Good catch!

  2. akbhuker commented on Feb 3, 2023

    @akbhuker

    Hi @nlohmann can you please assign me

  3. nlohmann commented on Feb 3, 2023

    @nlohmann
    Owner

    Go ahead!

  4. akbhuker commented on Feb 5, 2023

    @akbhuker

    Hi @nlohmann I'm new to CMake can you suggest to me how to setup development environment on my local machine and how to run the project

  5. nlohmann commented on Feb 7, 2023

    @nlohmann
    Owner

    No, I cannot assist you there. Please let me know if I should un-assign you.

  6. theevilone45 commented on Feb 22, 2023

    @theevilone45
    Contributor

    Hey @nlohmann, can I do it?

  7. nlohmann commented on Feb 22, 2023

    @nlohmann
    Owner

    Go ahead!

  8. linked a pull request that will close this issueFix typo in test.cmake #3951on Mar 5, 2023
  9. added this to the Release 3.11.3 milestone on Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions