From 64dbd4c2c472f0f7d95ed4b3d18a46bdd929673d Mon Sep 17 00:00:00 2001 From: seleznevae Date: Thu, 29 Aug 2019 09:12:58 +0300 Subject: [PATCH] [C] Enabled wchar_t and utf-8 by default --- .cirrus.yml | 8 ++++---- .travis.yml | 6 +++--- CMakeLists.txt | 10 ++++++++-- lib/CMakeLists.txt | 12 ++++++++++-- lib/fort.h | 26 +++++++++++++++++++++----- src/CMakeLists.txt | 12 ++++++++++-- src/fort.h | 26 +++++++++++++++++++++----- tests/CMakeLists.txt | 1 + tests/tests.h | 2 +- 9 files changed, 79 insertions(+), 24 deletions(-) diff --git a/.cirrus.yml b/.cirrus.yml index d1b627a..3e99e28 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -14,14 +14,14 @@ main_task: # Basic c build - cd lib - - cc -Wall -Wextra -Werror --std=gnu89 -DFT_CONGIG_HAVE_WCHAR fort.c -c -o fort.o + - cc -Wall -Wextra -Werror --std=gnu89 fort.c -c -o fort.o - rm fort.o - cd .. # Basic c++ build - cd lib - cp fort.c fort.cpp - - c++ -Wall -Wextra -Werror -DFT_CONGIG_HAVE_WCHAR fort.cpp -c -o fort.o + - c++ -Wall -Wextra -Werror fort.cpp -c -o fort.o - rm fort.o - rm fort.cpp - cd .. @@ -47,10 +47,10 @@ main_task: - cd .. - rm -r build/* - # Test without WCHAR support + # Test without WCHAR and UTF-8 support - mkdir -p build - cd build - - cmake .. -DFORT_ENABLE_WCHAR=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" + - cmake .. -DFORT_ENABLE_WCHAR=OFF -DFORT_ENABLE_UTF8=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" - cmake --build . --target all - ls - ctest -VV diff --git a/.travis.yml b/.travis.yml index b6f2a92..a7de3d8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -144,7 +144,7 @@ script: # basic build with old c standard (use gnu89 instead of c89 because some functions are not defines in c89) - cd lib - - ${CC} -Wall -Wextra -Werror --std=gnu89 -DFT_CONGIG_HAVE_WCHAR fort.c -c -o fort.o + - ${CC} -Wall -Wextra -Werror --std=gnu89 fort.c -c -o fort.o - rm fort.o - cd .. @@ -199,12 +199,12 @@ script: - ls - ctest -VV - # Test without WCHAR support + # Test without WCHAR and UTF-8 support - cd .. - rm -r build/* - mkdir -p build - cd build - - cmake .. -DFORT_ENABLE_WCHAR=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" + - cmake .. -DFORT_ENABLE_WCHAR=OFF -DFORT_ENABLE_UTF8=OFF -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_STANDARD=99 -DCMAKE_CXX_STANDARD=11 -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS}" -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS}" - cmake --build . --target all - ls - ctest -VV diff --git a/CMakeLists.txt b/CMakeLists.txt index 1296368..fce4144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,6 +14,7 @@ include(${CMAKE_ROOT}/Modules/ExternalProject.cmake) option(FORT_ENABLE_ASTYLE "Enable astyle" OFF) option(FORT_ENABLE_WCHAR "Enable wchar support" ON) +option(FORT_ENABLE_UTF8 "Enable utf8 support" ON) set(FORT_BUILD_TYPE "common" CACHE STRING "Build type") set_property(CACHE FORT_BUILD_TYPE PROPERTY STRINGS @@ -137,11 +138,16 @@ endforeach() # ------------------------------------------------------------------------------ # Add WChar support for the build # ------------------------------------------------------------------------------ -if(FORT_ENABLE_WCHAR) - add_definitions(-DFT_CONGIG_HAVE_WCHAR) +if(NOT FORT_ENABLE_WCHAR) + add_definitions(-DFT_CONGIG_DISABLE_WCHAR) +endif() +if(NOT FORT_ENABLE_UTF8) + add_definitions(-DFT_CONGIG_DISABLE_UTF8) endif() set(FORT_HAVE_WCHAR "${FORT_ENABLE_WCHAR}" CACHE STRING "fort option") +set(FORT_HAVE_UTF8 "${FORT_ENABLE_UTF8}" CACHE STRING "fort option") + # ------------------------------------------------------------------------------ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 3a411b9..e065284 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,4 +1,5 @@ option(FORT_HAVE_WCHAR "Enable wchar support" ON) +option(FORT_HAVE_UTF8 "Enable UTF8 support" ON) add_library(fort fort.c) @@ -12,10 +13,17 @@ set_target_properties(fort PROPERTIES VERSION ${libfort_VERSION} SOVERSION ${libfort_SOVERSION}) -if(FORT_HAVE_WCHAR) +if(NOT FORT_HAVE_WCHAR) target_compile_definitions(fort PRIVATE - -DFT_CONGIG_HAVE_WCHAR + -DFT_CONGIG_DISABLE_WCHAR + ) +endif() + +if(NOT FORT_HAVE_UTF8) + target_compile_definitions(fort + PRIVATE + -DFT_CONGIG_DISABLE_UTF8 ) endif() diff --git a/lib/fort.h b/lib/fort.h index a93f012..c6317df 100644 --- a/lib/fort.h +++ b/lib/fort.h @@ -53,21 +53,37 @@ SOFTWARE. /***************************************************************************** * Configuration *****************************************************************************/ +///** +// * libfort configuration macros +// * (to enable/disable some options this macros should be defined/undefined) +// */ +///** #define FT_CONGIG_HAVE_WCHAR */ + +//#if defined(FT_CONGIG_HAVE_WCHAR) +//#define FT_HAVE_WCHAR +//#endif + +//#define FT_CONGIG_HAVE_UTF8 +//#if defined(FT_CONGIG_HAVE_UTF8) +//#define FT_HAVE_UTF8 +//#endif + /** * libfort configuration macros - * (to enable/disable some options this macros should be defined/undefined) + * (to disable wchar_t/utf-8 support this macros should be defined) */ -/** #define FT_CONGIG_HAVE_WCHAR */ +/** #define FT_CONGIG_DISABLE_WCHAR */ +/** #define FT_CONGIG_DISABLE_UTF8 */ -#if defined(FT_CONGIG_HAVE_WCHAR) +#if !defined(FT_CONGIG_DISABLE_WCHAR) #define FT_HAVE_WCHAR #endif -#define FT_CONGIG_HAVE_UTF8 -#if defined(FT_CONGIG_HAVE_UTF8) +#if !defined(FT_CONGIG_DISABLE_UTF8) #define FT_HAVE_UTF8 #endif + /***************************************************************************** * RETURN CODES *****************************************************************************/ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5b2115a..26e4798 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,5 @@ option(FORT_HAVE_WCHAR "Enable wchar support" ON) +option(FORT_HAVE_UTF8 "Enable UTF8 support" ON) option(FORT_TEST_BUILD "Export some internal symbols for tests" ON) add_library(fort_dev @@ -17,10 +18,17 @@ target_include_directories(fort_dev ${CMAKE_CURRENT_SOURCE_DIR} ) -if(FORT_HAVE_WCHAR) +if(NOT FORT_HAVE_WCHAR) target_compile_definitions(fort_dev PRIVATE - -DFT_CONGIG_HAVE_WCHAR + -DFT_CONGIG_DISABLE_WCHAR + ) +endif() + +if(NOT FORT_HAVE_UTF8) + target_compile_definitions(fort_dev + PRIVATE + -DFT_CONGIG_DISABLE_UTF8 ) endif() diff --git a/src/fort.h b/src/fort.h index a93f012..c6317df 100644 --- a/src/fort.h +++ b/src/fort.h @@ -53,21 +53,37 @@ SOFTWARE. /***************************************************************************** * Configuration *****************************************************************************/ +///** +// * libfort configuration macros +// * (to enable/disable some options this macros should be defined/undefined) +// */ +///** #define FT_CONGIG_HAVE_WCHAR */ + +//#if defined(FT_CONGIG_HAVE_WCHAR) +//#define FT_HAVE_WCHAR +//#endif + +//#define FT_CONGIG_HAVE_UTF8 +//#if defined(FT_CONGIG_HAVE_UTF8) +//#define FT_HAVE_UTF8 +//#endif + /** * libfort configuration macros - * (to enable/disable some options this macros should be defined/undefined) + * (to disable wchar_t/utf-8 support this macros should be defined) */ -/** #define FT_CONGIG_HAVE_WCHAR */ +/** #define FT_CONGIG_DISABLE_WCHAR */ +/** #define FT_CONGIG_DISABLE_UTF8 */ -#if defined(FT_CONGIG_HAVE_WCHAR) +#if !defined(FT_CONGIG_DISABLE_WCHAR) #define FT_HAVE_WCHAR #endif -#define FT_CONGIG_HAVE_UTF8 -#if defined(FT_CONGIG_HAVE_UTF8) +#if !defined(FT_CONGIG_DISABLE_UTF8) #define FT_HAVE_UTF8 #endif + /***************************************************************************** * RETURN CODES *****************************************************************************/ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 275b8dc..928c11d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,4 +1,5 @@ option(FORT_HAVE_WCHAR "Enable wchar support" ON) +option(FORT_HAVE_UTF8 "Enable UTF8 support" ON) option(FORT_TEST_BUILD "Export some internal symbols for tests" ON) diff --git a/tests/tests.h b/tests/tests.h index ee0cd90..0e50c2e 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -14,7 +14,7 @@ #define THEN(...) #define SCENARIO(...) -#if defined(FT_CONGIG_HAVE_WCHAR) +#if !defined(FT_CONGIG_DISABLE_WCHAR) #define FT_HAVE_WCHAR #endif