build: add some build options to customise library functionality
This commit is contained in:
+17
-2
@@ -9,7 +9,19 @@ set(CMAKE_C_EXTENSIONS OFF)
|
|||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
|
||||||
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
||||||
|
|
||||||
|
if (NOT DEFINED fx_modules)
|
||||||
set(fx_modules core ds serial term cmd io compress)
|
set(fx_modules core ds serial term cmd io compress)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (NOT DEFINED fx_enable_floating_point)
|
||||||
|
set(fx_enable_floating_point 1)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (NOT DEFINED fx_enable_tests)
|
||||||
|
set(fx_enable_tests 1)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
message(STATUS "Floating point support: ${fx_enable_floating_point}")
|
||||||
|
|
||||||
set(fx_system_name ${CMAKE_SYSTEM_NAME})
|
set(fx_system_name ${CMAKE_SYSTEM_NAME})
|
||||||
string(TOLOWER ${fx_system_name} fx_system_name)
|
string(TOLOWER ${fx_system_name} fx_system_name)
|
||||||
@@ -25,7 +37,7 @@ foreach (module ${fx_modules})
|
|||||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module})
|
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module})
|
||||||
message(STATUS "Building unit tests for module ${module}")
|
message(STATUS "Building unit tests for module ${module}")
|
||||||
|
|
||||||
if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c)
|
if (fx_enable_tests AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c)
|
||||||
add_executable(fx-${module}-units
|
add_executable(fx-${module}-units
|
||||||
test/${module}/${module}-units.c
|
test/${module}/${module}-units.c
|
||||||
misc/AllTests.c
|
misc/AllTests.c
|
||||||
@@ -34,12 +46,12 @@ foreach (module ${fx_modules})
|
|||||||
target_link_libraries(fx-${module}-units fx-${module})
|
target_link_libraries(fx-${module}-units fx-${module})
|
||||||
target_include_directories(fx-${module}-units PRIVATE misc/)
|
target_include_directories(fx-${module}-units PRIVATE misc/)
|
||||||
set_target_properties(fx-${module}-units PROPERTIES FOLDER "Tests/${module}")
|
set_target_properties(fx-${module}-units PROPERTIES FOLDER "Tests/${module}")
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
file(GLOB test_sources test/${module}/*.c)
|
file(GLOB test_sources test/${module}/*.c)
|
||||||
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c")
|
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/${module}/${module}-units.c")
|
||||||
|
|
||||||
|
if (fx_enable_tests)
|
||||||
foreach (test_file ${test_sources})
|
foreach (test_file ${test_sources})
|
||||||
get_filename_component(test_name ${test_file} NAME_WE)
|
get_filename_component(test_name ${test_file} NAME_WE)
|
||||||
add_executable(fx-${module}-${test_name} ${test_file})
|
add_executable(fx-${module}-${test_name} ${test_file})
|
||||||
@@ -49,8 +61,10 @@ foreach (module ${fx_modules})
|
|||||||
target_link_libraries(fx-${module}-${test_name} fx-${module})
|
target_link_libraries(fx-${module}-${test_name} fx-${module})
|
||||||
endforeach (test_file)
|
endforeach (test_file)
|
||||||
endif ()
|
endif ()
|
||||||
|
endif ()
|
||||||
endforeach (module)
|
endforeach (module)
|
||||||
|
|
||||||
|
if (fx_enable_tests)
|
||||||
file(GLOB test_sources test/*.c)
|
file(GLOB test_sources test/*.c)
|
||||||
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/units.c")
|
list(REMOVE_ITEM test_sources "${CMAKE_CURRENT_SOURCE_DIR}/test/units.c")
|
||||||
|
|
||||||
@@ -64,3 +78,4 @@ foreach (test_file ${test_sources})
|
|||||||
target_link_libraries(fx-${test_name} fx-${module})
|
target_link_libraries(fx-${test_name} fx-${module})
|
||||||
endforeach (module)
|
endforeach (module)
|
||||||
endforeach (test_file)
|
endforeach (test_file)
|
||||||
|
endif ()
|
||||||
|
|||||||
@@ -50,11 +50,13 @@ function(add_fx_module)
|
|||||||
|
|
||||||
target_compile_definitions(fx-${module_name} PUBLIC
|
target_compile_definitions(fx-${module_name} PUBLIC
|
||||||
${module_preproc_token}
|
${module_preproc_token}
|
||||||
FX_EXPORT=1)
|
FX_EXPORT=1
|
||||||
|
FX_ENABLE_FLOATING_POINT=${fx_enable_floating_point})
|
||||||
target_compile_definitions(fx-${module_name}-s PUBLIC
|
target_compile_definitions(fx-${module_name}-s PUBLIC
|
||||||
${module_preproc_token}
|
${module_preproc_token}
|
||||||
FX_EXPORT=1
|
FX_EXPORT=1
|
||||||
FX_STATIC=1)
|
FX_STATIC=1
|
||||||
|
FX_ENABLE_FLOATING_POINT=${fx_enable_floating_point})
|
||||||
|
|
||||||
set_target_properties(fx-${module_name}
|
set_target_properties(fx-${module_name}
|
||||||
PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
PROPERTIES POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ static uint64_t genrand64_int64(struct fx_random_ctx *context)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FX_ENABLE_FLOATING_POINT == 1
|
||||||
/* generates a random number on [0,1]-real-interval */
|
/* generates a random number on [0,1]-real-interval */
|
||||||
double genrand64_real1(struct fx_random_ctx *context)
|
double genrand64_real1(struct fx_random_ctx *context)
|
||||||
{
|
{
|
||||||
@@ -235,6 +236,7 @@ double genrand64_real3(struct fx_random_ctx *context)
|
|||||||
return ((genrand64_int64(context) >> 12) + 0.5)
|
return ((genrand64_int64(context) >> 12) + 0.5)
|
||||||
* (1.0 / 4503599627370496.0);
|
* (1.0 / 4503599627370496.0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct fx_random_algorithm z__fx_gen_mt19937 = {
|
struct fx_random_algorithm z__fx_gen_mt19937 = {
|
||||||
.gen_name = "mt19937",
|
.gen_name = "mt19937",
|
||||||
|
|||||||
@@ -45,6 +45,11 @@
|
|||||||
|
|
||||||
#include "printf.h"
|
#include "printf.h"
|
||||||
|
|
||||||
|
#if FX_ENABLE_FLOATING_POINT == 0
|
||||||
|
#define PRINTF_SUPPORT_DECIMAL_SPECIFIERS 0
|
||||||
|
#define PRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|||||||
+4
-1
@@ -60,6 +60,7 @@ unsigned long long fx_random_next_int64(struct fx_random_ctx *ctx)
|
|||||||
return ctx->__a->gen_getrand(ctx);
|
return ctx->__a->gen_getrand(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FX_ENABLE_FLOATING_POINT
|
||||||
double fx_random_next_double(struct fx_random_ctx *ctx)
|
double fx_random_next_double(struct fx_random_ctx *ctx)
|
||||||
{
|
{
|
||||||
unsigned long long v = fx_random_next_int64(ctx);
|
unsigned long long v = fx_random_next_int64(ctx);
|
||||||
@@ -69,8 +70,10 @@ double fx_random_next_double(struct fx_random_ctx *ctx)
|
|||||||
|
|
||||||
return (double)(v >> 11) * (1.0 / 9007199254740991.0);
|
return (double)(v >> 11) * (1.0 / 9007199254740991.0);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void fx_random_next_bytes(struct fx_random_ctx *ctx, unsigned char *out, size_t nbytes)
|
void fx_random_next_bytes(
|
||||||
|
struct fx_random_ctx *ctx, unsigned char *out, size_t nbytes)
|
||||||
{
|
{
|
||||||
size_t n_qwords = 0;
|
size_t n_qwords = 0;
|
||||||
n_qwords = nbytes >> 3;
|
n_qwords = nbytes >> 3;
|
||||||
|
|||||||
Reference in New Issue
Block a user