nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
42.97k stars 6.72k forks source link

Typo in `cmake/test.cmake` #3902

Closed m-hilgendorf closed 1 year ago

m-hilgendorf commented 1 year ago

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).
nlohmann commented 1 year ago

Good catch!

akbhuker commented 1 year ago

Hi @nlohmann can you please assign me

nlohmann commented 1 year ago

Go ahead!

akbhuker commented 1 year ago

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

nlohmann commented 1 year ago

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

theevilone45 commented 1 year ago

Hey @nlohmann, can I do it?

nlohmann commented 1 year ago

Go ahead!