Commit 8d7c4ea43e25a3187662506040b826a167e7110c
1 parent
8234766b
unicode configuration
Showing
3 changed files
with
17 additions
and
6 deletions
CMakeLists.txt
| ... | ... | @@ -23,9 +23,20 @@ project(cxxopts) |
| 23 | 23 | |
| 24 | 24 | set(VERSION "0.0.1") |
| 25 | 25 | |
| 26 | -find_package(PkgConfig) | |
| 26 | +set(CXXOPTS_LINKER_LIBRARIES "") | |
| 27 | 27 | |
| 28 | -pkg_check_modules(ICU REQUIRED icu-uc) | |
| 28 | +set(CXXOPTS_USE_UNICODE_HELP FALSE CACHE BOOL "Use ICU Unicode library") | |
| 29 | + | |
| 30 | +if(CXXOPTS_USE_UNICODE_HELP) | |
| 31 | + | |
| 32 | + find_package(PkgConfig) | |
| 33 | + | |
| 34 | + pkg_check_modules(ICU REQUIRED icu-uc) | |
| 35 | + | |
| 36 | + set(CXXOPTS_LINKER_LIBRARIES "${ICU_LIBRARIES}") | |
| 37 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCXXOPTS_USE_UNICODE") | |
| 38 | + | |
| 39 | +endif() | |
| 29 | 40 | |
| 30 | 41 | add_subdirectory(src) |
| 31 | 42 | ... | ... |
src/CMakeLists.txt
| ... | ... | @@ -21,6 +21,6 @@ |
| 21 | 21 | add_executable(example example.cpp) |
| 22 | 22 | |
| 23 | 23 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall") |
| 24 | -target_link_libraries(example ${ICU_LIBRARIES}) | |
| 24 | +target_link_libraries(example ${CXXOPTS_LINKER_LIBRARIES}) | |
| 25 | 25 | |
| 26 | 26 | install(FILES cxxopts.hpp DESTINATION include) | ... | ... |
src/example.cpp
| ... | ... | @@ -24,8 +24,6 @@ THE SOFTWARE. |
| 24 | 24 | |
| 25 | 25 | #include <iostream> |
| 26 | 26 | |
| 27 | -#define CXXOPTS_USE_UNICODE | |
| 28 | - | |
| 29 | 27 | #include "cxxopts.hpp" |
| 30 | 28 | |
| 31 | 29 | int main(int argc, char* argv[]) |
| ... | ... | @@ -48,8 +46,10 @@ int main(int argc, char* argv[]) |
| 48 | 46 | ("help", "Print help") |
| 49 | 47 | ("int", "An integer", cxxopts::value<int>()) |
| 50 | 48 | ("option_that_is_too_long_for_the_help", "A very long option") |
| 51 | - ("unicode", u8"A help option with non-ascii: à. Here the length of the" | |
| 49 | + #ifdef CXXOPTS_USE_UNICODE | |
| 50 | + ("unicode", u8"A help option with non-ascii: à. Here the size of the" | |
| 52 | 51 | " string should be correct") |
| 52 | + #endif | |
| 53 | 53 | ; |
| 54 | 54 | |
| 55 | 55 | options.add_options("Group") | ... | ... |