Skip to content

Commit

Permalink
Fix locale handling when building with cmake
Browse files Browse the repository at this point in the history
* Add `check_symbol_exists` for locale handling (it was commented out before)
* Mac OS: use header "xlocale.h" for checks
* Apply the result of these checks not only to `libconfig`, but also `libconfig++`
* This fixes the build warning "No way to modify calling thread's locale!"
* This also fixes the memory leak on Mac OS as described in issue hyperrealm#212.
  • Loading branch information
thomastrapp committed Nov 9, 2021
1 parent 98a52a4 commit b3a1aed
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,42 @@ set_target_properties(${libname}++
VERSION "${libconfig_VERSION}"
PUBLIC_HEADER "${libinc_cpp}")

#check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE)
#check_symbol_exists(newlocale "locale.h" HAVE_NEWLOCALE)
#check_symbol_exists(freelocale "locale.h" HAVE_FREELOCALE)

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)
endif()

if(APPLE)
check_symbol_exists(uselocale "xlocale.h" HAVE_USELOCALE)
check_symbol_exists(newlocale "xlocale.h" HAVE_NEWLOCALE)
check_symbol_exists(freelocale "xlocale.h" HAVE_FREELOCALE)
else()
check_symbol_exists(uselocale "locale.h" HAVE_USELOCALE)
check_symbol_exists(newlocale "locale.h" HAVE_NEWLOCALE)
check_symbol_exists(freelocale "locale.h" HAVE_FREELOCALE)
endif()

if(HAVE_USELOCALE)
target_compile_definitions(${libname}
PRIVATE "HAVE_USELOCALE")
target_compile_definitions(${libname}
PRIVATE "HAVE_USELOCALE")
target_compile_definitions(${libname}++
PRIVATE "HAVE_USELOCALE")
endif()

if(HAVE_NEWLOCALE)
target_compile_definitions(${libname}
PRIVATE "HAVE_NEWLOCALE")
target_compile_definitions(${libname}
PRIVATE "HAVE_NEWLOCALE")
target_compile_definitions(${libname}++
PRIVATE "HAVE_NEWLOCALE")
endif()

if(HAVE_FREELOCALE)
target_compile_definitions(${libname}
PRIVATE "HAVE_FREELOCALE")
target_compile_definitions(${libname}
PRIVATE "HAVE_FREELOCALE")
target_compile_definitions(${libname}++
PRIVATE "HAVE_FREELOCALE")
endif()

if(MSVC)
Expand Down

0 comments on commit b3a1aed

Please sign in to comment.