Skip to content

Invalid CMake compile definition #1634

@OgreTransporter

Description

@OgreTransporter

add_compile_definitions(JSON_DLL_BUILD)

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

add_library(${SHARED_LIB} SHARED ${PUBLIC_HEADERS} ${JSONCPP_SOURCES})

and not before it. Otherwise, the target cannot be found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions