hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.13k stars 366 forks source link

CMake `BUILD_SHARED_LIBS` OFF missing `LIBCONFIG_STATIC` definition for `${libname}++` target #237

Closed Challanger524 closed 2 months ago

Challanger524 commented 7 months ago

MSVC: warning C4273: 'config_read': inconsistent dll linkage Clang: warning: 'config_read' redeclared without 'dllimport' attribute: previous 'dllimport' ignored [-Winconsistent-dllimport]

libconfig\lib\CMakeLists.txt simply misses:

if(BUILD_SHARED_LIBS)
    target_compile_definitions(${libname}++ PRIVATE LIBCONFIG_STATIC)
else()
    target_compile_definitions(${libname} PUBLIC LIBCONFIG_STATIC)
    target_compile_definitions(${libname}++ PUBLIC LIBCONFIGXX_STATIC) <-- who forgot LIBCONFIG_STATIC ???
endif()

# must be:
...
target_compile_definitions(${libname}++ PUBLIC LIBCONFIG_STATIC LIBCONFIGXX_STATIC)

Workaround - in your CMake add definition manually:

target_compile_definitions(${LIBCONFIG_}++ PUBLIC LIBCONFIG_STATIC)
Challanger524 commented 7 months ago

And silly frustration, what the history behind "this" target-name split?:

if(MSVC)
    set(libname "libconfig")
else()
    set(libname "config")
endif()

This is so wired to support