Skip to content

Commit

Permalink
[C] Enabled wchar_t and utf-8 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
seleznevae committed Aug 29, 2019
1 parent 5bfabee commit 64dbd4c
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 24 deletions.
8 changes: 4 additions & 4 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..

Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")



# ------------------------------------------------------------------------------
Expand Down
12 changes: 10 additions & 2 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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()

Expand Down
26 changes: 21 additions & 5 deletions lib/fort.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*****************************************************************************/
Expand Down
12 changes: 10 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()

Expand Down
26 changes: 21 additions & 5 deletions src/fort.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*****************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
2 changes: 1 addition & 1 deletion tests/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 64dbd4c

Please sign in to comment.