@@ -7,76 +7,35 @@ project(
7
7
VERSION 0.2.0
8
8
)
9
9
10
- option (BUILD_TESTS "Build test programs for the library" OFF )
11
-
12
- option (SUPPORT_FLOAT_SPECIFIERS "Support decimal notation floating-point conversion specifiers (%f,%F)" ON )
13
- if (NOT SUPPORT_FLOAT_SPECIFIERS)
14
- add_definitions (-DPRINTF_DISABLE_FLOAT_SPECIFIERS)
15
- endif ()
16
-
17
- option (SUPPORT_EXPONENTIAL_SPECIFIERS "Support exponential floating point format conversion specifiers (%e,%E,%g,%G)" ON )
18
- if (NOT SUPPORT_EXPONENTIAL_SPECIFIERS)
19
- add_definitions (-DPRINTF_DISABLE_EXPONENTIAL_SPECIFIERS)
20
- endif ()
10
+ option (BUILD_TESTS "Build test programs for the library" OFF )
11
+ option (BUILD_STATIC_LIBRARY "Build the library as static rather than shared" OFF )
21
12
22
- option (SUPPORT_LONG_LONG "Support long long integral types (allows for the ll length modifier and affects %p)" ON )
23
- if (NOT SUPPORT_LONG_LONG)
24
- add_definitions (-DPRINTF_DISABLE_LONG_LONG)
25
- endif ()
13
+ # Boolean options which go into config.h
26
14
15
+ option (SUPPORT_FLOAT_SPECIFIERS "Support decimal notation floating-point conversion specifiers (%f,%F)" ON )
16
+ option (SUPPORT_EXPONENTIAL_SPECIFIERS "Support exponential floating point format conversion specifiers (%e,%E,%g,%G)" ON )
17
+ option (SUPPORT_LONG_LONG "Support long long integral types (allows for the ll length modifier and affects %p)" ON )
27
18
option (SUPPORT_PTRDIFF_LENGTH_MODIFIER "Support the pointer difference specifier (%t)" ON )
28
- if (NOT SUPPORT_PTRDIFF_LENGTH_MODIFIER)
29
- add_definitions (-DPRINTF_DISABLE_PTRDIFF_LENGTH_MODIFIER)
30
- endif ()
31
-
32
- option (ALIAS_STANDARD_FUNCTION_NAMES "Alias the standard library function names (printf, sprintf etc.) to the library's functions" ON )
33
- if (NOT ALIAS_STANDARD_FUNCTION_NAMES)
34
- add_definitions (-DPRINTF_ALIAS_STANDARD_FUNCTION_NAMES)
35
- endif ()
36
-
37
- # Numeric defines
38
-
39
- set (NTOA_BUFFER_SIZE "32" CACHE STRING "Integer to string (ntoa) conversion buffer size" )
40
- string (REGEX MATCH "^[0-9]+([eE][0-9]+)?$" NTOA_BUFFER_SIZE "${NTOA_BUFFER_SIZE} " )
41
- if ("${NTOA_BUFFER_SIZE} " STREQUAL "" )
42
- message (FATAL_ERROR "An (integral) buffer size for converting integers to floating-point values must be specified." )
43
- else ()
44
- add_definitions (-DPRINTF_NTOA_BUFFER_SIZE=${NTOA_BUFFER_SIZE} )
45
- endif ()
46
-
47
- set (PRINTF_FTOA_BUFFER_SIZE "32" CACHE STRING "Float to string (ftoa) conversion buffer size" )
48
- string (REGEX MATCH "^[0-9]+$" PRINTF_FTOA_BUFFER_SIZE "${PRINTF_FTOA_BUFFER_SIZE} " )
49
- if ("${PRINTF_FTOA_BUFFER_SIZE} " STREQUAL "" )
50
- message (FATAL_ERROR "An (integral) buffer size for converting floating-point values to strings must be specified." )
51
- else ()
52
- add_definitions (-DPRINTF_FTOA_BUFFER_SIZE=${PRINTF_FTOA_BUFFER_SIZE} )
53
- endif ()
19
+ option (ALIAS_STANDARD_FUNCTION_NAMES "Alias the standard library function names (printf, sprintf etc.) to the library's functions" ON )
54
20
55
- set (DEFAULT_FLOAT_PRECISION "6" CACHE STRING "Default precision when printing floating-point values" )
56
- string (REGEX MATCH "^[0-9]+$" DEFAULT_FLOAT_PRECISION "${DEFAULT_FLOAT_PRECISION} " )
57
- if ("${DEFAULT_FLOAT_PRECISION} " STREQUAL "" )
58
- message (FATAL_ERROR "An (integral) default floating-point precision value must be specified." )
59
- else ()
60
- add_definitions (-DPRINTF_DEFAULT_FLOAT_PRECISION=${DEFAULT_FLOAT_PRECISION} )
61
- endif ()
21
+ # Numeric defines which go into config.h
62
22
23
+ set (NTOA_BUFFER_SIZE "32" CACHE STRING "Integer to string (ntoa) conversion buffer size" )
24
+ set (PRINTF_FTOA_BUFFER_SIZE "32" CACHE STRING "Float to string (ftoa) conversion buffer size" )
25
+ set (DEFAULT_FLOAT_PRECISION "6" CACHE STRING "Default precision when printing floating-point values" )
63
26
set (FLOAT_NOTATION_THRESHOLD "1e9" CACHE STRING "Largest floating-point value for which printing with %f uses non-exponential notation" )
64
- string (REGEX MATCH "^[0-9]+([eE][0-9]+)?$" FLOAT_NOTATION_THRESHOLD "${FLOAT_NOTATION_THRESHOLD} " )
65
- if ("${FLOAT_NOTATION_THRESHOLD} " STREQUAL "" )
66
- message (FATAL_ERROR "The %f notation switch threshold must be an integer." )
67
- else ()
68
- add_definitions (-DPRINTF_FLOAT_NOTATION_THRESHOLD=${FLOAT_NOTATION_THRESHOLD} )
69
- endif ()
70
-
71
- option (BUILD_STATIC_LIBRARY "Build the library as static rather than shared" OFF )
72
-
73
27
74
28
if (BUILD_STATIC_LIBRARY)
75
29
add_library (mpaland-printf STATIC printf.c)
76
30
else ()
77
31
add_library (mpaland-printf SHARED printf.c)
78
32
endif ()
79
33
34
+ set (GENERATED_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR} /include" )
35
+ configure_file ("printf_config.h.in" "${GENERATED_INCLUDE_DIR} /printf_config.h" @ONLY)
36
+ target_compile_definitions (mpaland-printf PRIVATE PRINTF_INCLUDE_CONFIG_H)
37
+ target_include_directories (mpaland-printf PRIVATE "$<BUILD_INTERFACE:${GENERATED_INCLUDE_DIR} >" )
38
+
80
39
set_property (TARGET mpaland-printf PROPERTY C_STANDARD 99)
81
40
set_property (TARGET mpaland-printf PROPERTY C_STANDARD_REQUIRED ON )
82
41
set_property (TARGET mpaland-printf PROPERTY C_EXTENSIONS OFF )
@@ -95,7 +54,7 @@ set_target_properties(mpaland-printf PROPERTIES
95
54
96
55
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC" )
97
56
target_compile_options (mpaland-printf PRIVATE /W4)
98
- elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
57
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
99
58
CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
100
59
target_compile_options (mpaland-printf PRIVATE -Wall -Wextra -pedantic)
101
60
endif ()
@@ -106,15 +65,15 @@ if (BUILD_TESTS)
106
65
endif ()
107
66
108
67
if (UNIX )
109
- add_custom_target (mpaland-printf-sizes
68
+ add_custom_target (mpaland-printf-sizes
110
69
COMMAND size -A -t $<TARGET_FILE:mpaland-printf> > mpaland-printf_sizes.txt
111
70
DEPENDS mpaland-printf
112
71
BYPRODUCTS mpaland-printf_sizes.txt
113
72
COMMENT Prints the sizes of the different sections of the ELF file: text, dat, vss etc.)
114
73
115
- add_custom_target (mpaland-printf-symbols
74
+ add_custom_target (mpaland-printf-symbols
116
75
COMMAND nm --numeric-sort --print-size "$<TARGET_FILE:mpaland-printf>" > mpaland-printf_symbols.txt
117
- COMMAND bash -c "nm --numeric-sort --print-size $<TARGET_FILE:mpaland-printf> | c++filt > mpaland-printf_cpp_symbols.txt"
76
+ COMMAND bash -c "nm --numeric-sort --print-size $<TARGET_FILE:mpaland-printf> | c++filt > mpaland-printf_cpp_symbols.txt"
118
77
VERBATIM
119
78
DEPENDS mpaland-printf
120
79
BYPRODUCTS mpaland-printf_symbols.txt mpaland-printf_cpp_symbols.txt
0 commit comments