← All tasks
cppopen-source-parsers/jsoncpp #1634Not a task: already works

Invalid CMake compile definition

envgap__open-source-parsers__jsoncpp-1634

01 / FAILURE SIGNATURE

As reported upstream

No identifying execution failure has been captured.
Not a benchmark task.
  • The project already builds and runs before the fix, so there is nothing to repair.

02 / ENVIRONMENT RECIPE

Base commit
ef0877151eb14f2d75fea139b5de34a048733e8b
Manifest
src/lib_json/CMakeLists.txt
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

open-source-parsers/jsoncpp #1634 · read the original issue
https://github.com/open-source-parsers/jsoncpp/blob/b511d9e64956db998b74909df112ac8c8f41d6ff/src/lib_json/CMakeLists.txt#L111
The following part for the shared library is incorrect:
```
    if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12.0)
        add_compile_definitions(JSON_DLL_BUILD)
    else()
        add_definitions(-DJSON_DLL_BUILD)
    endif()
```
What's wrong with that? Both commands add the definition globally to the compiler for the entire project. This means that if the static library is built after the shared library, the compiler will also have the definition there. Fix:
```
target_compile_definitions(${SHARED_LIB} PUBLIC JSON_DLL PRIVATE JSON_DLL_BUILD)
```
Why also `JSON_DLL`? Currently, `JSON_DLL` is not written to the configuration file during export. This means that if you want to use the shared library, you have to set the definition yourself.

However, the fix must be inserted after
https://github.com/open-source-parsers/jsoncpp/blob/b511d9e64956db998b74909df112ac8c8f41d6ff/src/lib_json/CMakeLists.txt#L117
and not before it. Otherwise, the target cannot be found.
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]