Skip to content

Check for locale support in CMake #551

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Gachapen
Copy link
Contributor

@Gachapen Gachapen commented Nov 7, 2016

This should improve #527 by checking for locale support at configure time.

Example output from our Android build with this change:

-- Looking for C++ include clocale
-- Looking for C++ include clocale - found
-- Check size of lconv
-- Check size of lconv - done
-- Performing Test HAVE_DECIMAL_POINT
-- Performing Test HAVE_DECIMAL_POINT - Failed
-- Looking for localeconv
-- Looking for localeconv - not found
CMake Warning at third_party/jsoncpp/src/lib_json/CMakeLists.txt:25 (message):
  Locale functionality is not supported

I would also like to suggest changing NO_LOCALE_SUPPORT to JSONCPP_NO_LOCALE_SUPPORT as to not clutter the global namespace. But this would break builds relying on NO_LOCALE_SUPPORT, so I didn't implement it.

check_type_size(lconv LCONV_SIZE LANGUAGE CXX)
set(CMAKE_EXTRA_INCLUDE_FILES "")
check_struct_has_member(lconv decimal_point clocale HAVE_DECIMAL_POINT LANGUAGE CXX)
check_cxx_symbol_exists(localeconv clocale HAVE_LOCALECONV)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frustrating how inconsistent the CMake API is with regards to setting language and adding headers.

@Gachapen
Copy link
Contributor Author

Gachapen commented Nov 7, 2016

I see both gcc and clang in travis fail HAVE_DECIMAL_POINT, I should look into this. It did not fail for me with clang 3.9. Travis is using clang 3.4.

@Gachapen
Copy link
Contributor Author

Gachapen commented Nov 7, 2016

I nailed it down to a change in CMake 3.0 where they added the LANGUAGE option to check_struct_has_member. Before this change, it always compiled with the C compiler, not C++.

I see some options, but not sure which is best:

  • Upgrade the Travis CMake to >=3.0 and drop support for older versions.
  • Change the check to use the locale.h header instead of clocale so that it can compile it with the C compiler. (lconv in the C header and C++ header might not be the same)
  • Add the updated check_struct_has_member module to the jsoncpp project to fix the check. (updates to the system cmake won't affect the check_struct_has_member anymore)

@Gachapen
Copy link
Contributor Author

Gachapen commented Nov 7, 2016

I implemented the second option as it seems to be the least problematic. Now, I misread the build log. It wasn't only HAVE_DECIMAL_POINT that failed, but also the lconv size check. Possibly because of the same reason. I'll investigate more....

@Gachapen Gachapen force-pushed the detect_locale_support branch from 67685ed to 3559236 Compare November 7, 2016 20:30
@Gachapen
Copy link
Contributor Author

Gachapen commented Nov 7, 2016

I amended my previous commit with a proper fix for the problem. It's not pretty, but it's the best I could do if we want to support older CMake versions.

@cdunn2001
Copy link
Contributor

I would also like to suggest changing NO_LOCALE_SUPPORT to JSONCPP_NO_LOCALE_SUPPORT as to not clutter the global namespace. But this would break builds relying on NO_LOCALE_SUPPORT, so I didn't implement it.

Could you include that amendment in this PR? Don't worry too much about build-breakage. But if you fallback to NO_LOCALE_SUPPORT when JSONCPP_NO_LOCALE_SUPPORT is undefined, that might be good for now.

@Gachapen Gachapen force-pushed the detect_locale_support branch from 3559236 to 5a82131 Compare November 8, 2016 08:48
@Gachapen
Copy link
Contributor Author

Gachapen commented Nov 8, 2016

I squashed my two first commits, and added a commit for JSONCPP_NO_LOCALE_SUPPORT. I think it makes more sense to separate them.

@cdunn2001 cdunn2001 merged commit f880a94 into open-source-parsers:master Nov 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants