diff --git a/CMakeLists.txt b/CMakeLists.txt index 8649b1a..5e2e732 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,11 +17,11 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Options # ---------------------------------------------- # Use floats instead of doubles -option (DFLOAT "Use float numbers instead of doubles" OFF) +set(DFLOAT OFF CACHE BOOL "Use float numbers instead of doubles") message(STATUS "Floats are ${DFLOAT}") # Use long integers for indexing -option (DLONG "Use long integers (64bit) for indexing" ON) +set(DLONG ON CACHE BOOL "Use long integers (64bit) for indexing") if (NOT (CMAKE_SIZEOF_VOID_P EQUAL 8)) message(STATUS "Disabling long integers (64bit) on 32bit machine") set(DLONG OFF) @@ -50,8 +50,22 @@ endif (NOT MSVC) # Generate header file with the global options # --------------------------------------------- -configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/qdldl_configure.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/include/qdldl_configure.h + +# numeric types +if(DFLOAT) + set(QDLDL_FLOAT_TYPE "float") +else() + set(QDLDL_FLOAT_TYPE "double") +endif() + +if(DLONG) + set(QDLDL_INT_TYPE "long long") +else() + set(QDLDL_INT_TYPE "int") +endif() + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure/qdldl_types.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/include/qdldl_types.h NEWLINE_STYLE LF) @@ -65,6 +79,7 @@ set( set( qdldl_headers include/qdldl.h + include/qdldl_types.h ) diff --git a/README.md b/README.md index 5ef03cf..19e3863 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ QDLDL uses its own internal types for integers, floats and booleans (`QDLDL_int, - `DFLOAT` (default false): uses float numbers instead of doubles - `DLONG` (default true): uses long integers for indexing (for large matrices) -Note that the `QDLDL_bool` type is defined as the standard `bool` type for C standards >= C99. Before the `bool` type was not defined and for earlier standards QDLDL sets `QDLDL_bool = QDLDL_int`. +Note that the `QDLDL_bool` type is defined as the standard `_Bool` type for C standards >= C99. In earlier C standards the `_Bool` type was not defined and QDLDL sets `QDLDL_bool = QDLDL_int`. ## Linking QDLDL diff --git a/configure/qdldl_configure.h.in b/configure/qdldl_configure.h.in deleted file mode 100644 index e7fc1bf..0000000 --- a/configure/qdldl_configure.h.in +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef OSQP_CONFIGURE_H -# define OSQP_CONFIGURE_H - -# ifdef __cplusplus -extern "C" { -# endif /* ifdef __cplusplus */ - -/* DFLOAT */ -#cmakedefine DFLOAT - -/* DLONG */ -#cmakedefine DLONG - -# ifdef __cplusplus -} -# endif /* ifdef __cplusplus */ - -#endif /* ifndef OSQP_CONFIGURE_H */ diff --git a/configure/qdldl_types.h.in b/configure/qdldl_types.h.in new file mode 100644 index 0000000..0ff31a2 --- /dev/null +++ b/configure/qdldl_types.h.in @@ -0,0 +1,24 @@ +#ifndef QDLDL_TYPES_H +# define QDLDL_TYPES_H + +# ifdef __cplusplus +extern "C" { +# endif /* ifdef __cplusplus */ + +// QDLDL integer and float types + +typedef @QDLDL_INT_TYPE@ QDLDL_int; /* for indices */ +typedef @QDLDL_FLOAT_TYPE@ QDLDL_float; /* for numerical values */ + +// Use bool for logical type if available +#if __STDC_VERSION__ >= 199901L +typedef _Bool QDLDL_bool; +#else +typedef int QDLDL_bool; +#endif + +# ifdef __cplusplus +} +# endif /* ifdef __cplusplus */ + +#endif /* ifndef QDLDL_TYPES_H */ diff --git a/include/.gitignore b/include/.gitignore index c5bfa1c..26e99d0 100644 --- a/include/.gitignore +++ b/include/.gitignore @@ -1 +1 @@ -qdldl_configure.h +qdldl_types.h diff --git a/include/qdldl.h b/include/qdldl.h index 9cb1e0b..63b65d1 100644 --- a/include/qdldl.h +++ b/include/qdldl.h @@ -1,32 +1,8 @@ #ifndef QDLDL_H -# define QDLDL_H - -// Include qdldl configure options -#include "qdldl_configure.h" - -// Custom types -// Integers -# ifdef DLONG // long integers -typedef long long QDLDL_int; /* for indices */ -# else // standard integers -typedef int QDLDL_int; /* for indices */ -# endif /* ifdef DLONG */ - -// Doubles -# ifndef DFLOAT // Doubles -typedef double QDLDL_float; /* for numerical values */ -# else // Floats -typedef float QDLDL_float; /* for numerical values */ -# endif /* ifndef DFLOAT */ - -// Define bool if standard > C89 -#if __STDC_VERSION__ >= 199901L -#include -typedef bool QDLDL_bool; -#else -typedef QDLDL_int QDLDL_bool; -#endif +#define QDLDL_H +// Include qdldl type options +#include "qdldl_types.h" # ifdef __cplusplus extern "C" {