@@ -10,6 +10,7 @@ set(QDLDL_VERSION "${QDLDL_VERSION_MAJOR}.${QDLDL_VERSION_MINOR}.${QDLDL_VERSION
10
10
project (qdldl VERSION ${QDLDL_VERSION} )
11
11
12
12
include ( CMakeDependentOption )
13
+ include ( CheckCXXCompilerFlag )
13
14
14
15
option ( QDLDL_BUILD_STATIC_LIB "Build the static library" ON )
15
16
option ( QDLDL_BUILD_SHARED_LIB "Build the shared library" ON )
@@ -24,6 +25,14 @@ cmake_dependent_option( QDLDL_UNITTESTS
24
25
OFF # Default to off
25
26
QDLDL_BUILD_STATIC_LIB OFF ) # Force off if the static library isn't built
26
27
28
+ # Dev options
29
+ option ( QDLDL_DEV_COVERAGE "Include coverage information in the library" OFF )
30
+ option ( QDLDL_DEV_ANALYSIS "Run the compiler static analysis checks" OFF )
31
+ option ( QDLDL_DEV_ASAN "Build with ASAN" OFF )
32
+
33
+ mark_as_advanced ( OSQP_DEV_COVERAGE )
34
+ mark_as_advanced ( OSQP_DEV_ANALYSIS )
35
+
27
36
# Set the output folder where your program will be created
28
37
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR} /out)
29
38
set (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR} /out)
@@ -62,14 +71,35 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) # -fPIC
62
71
# Add compiler options if we are not on windows
63
72
if (NOT MSVC )
64
73
65
- if (COVERAGE )
74
+ if (QDLDL_DEV_COVERAGE )
66
75
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage" )
67
76
68
77
if (FORTRAN)
69
78
set (CMAKE_FORTRAN_FLAGS "${CMAKE_FORTRAN_FLAGS} --coverage" )
70
79
endif (FORTRAN)
71
80
endif ()
72
81
82
+ if (QDLDL_DEV_ANALYSIS)
83
+ check_cxx_compiler_flag( "-fanalyzer" COMPILER_SUPPORTS_FANALYZER )
84
+
85
+ if ( COMPILER_SUPPORTS_FANALYZER )
86
+ set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fanalyzer" )
87
+
88
+ message ( STATUS "Enabling -fanalyzer static analysis" )
89
+ endif ()
90
+ endif ()
91
+
92
+ if (OSQP_ASAN)
93
+ set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer" )
94
+ set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -D_GLIBCXX_SANITIZE_VECTOR -fsanitize=address -fno-optimize-sibling-calls -fsanitize-address-use-after-scope -fno-omit-frame-pointer" )
95
+
96
+ # ASAN shouldn't be used with these options (https://github.com/google/sanitizers/wiki/AddressSanitizer#faq)
97
+ set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-stack-protector -U_FORTIFY_SOURCE" )
98
+ set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-stack-protector -U_FORTIFY_SOURCE" )
99
+
100
+ message ( STATUS "Enabling ASAN" )
101
+ endif ()
102
+
73
103
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3" )
74
104
set (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g" )
75
105
endif (NOT MSVC )
0 commit comments