Skip to content

Commit

Permalink
Add noa_add_default_options
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Jun 10, 2024
1 parent e3d086c commit 26f9de8
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ To run the targets:
cmake --build <dir> [<options>] --target doxygen
```

#### `noa_add_default_options`

Configure a target with an opinionated set of strict compiler options.

```cmake
noa_add_default_options([visibility] [target])
```

For example:

```cmake
noa_add_default_options(PUBLIC my_lib)
````
#### `noa_sanitizer`
Provides a unified interface for setting up a set of compiler sanitizers
Expand Down
1 change: 1 addition & 0 deletions cmake/noa.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ include("${NOA_DIRECTORY}/variables.cmake")
include("${NOA_DIRECTORY}/defaults.cmake")
include("${NOA_DIRECTORY}/library.cmake")
include("${NOA_DIRECTORY}/compiler/sanitizer.cmake")
include("${NOA_DIRECTORY}/compiler/options.cmake")
include("${NOA_DIRECTORY}/options/enum.cmake")
include("${NOA_DIRECTORY}/commands/copy-file.cmake")
include("${NOA_DIRECTORY}/targets/clang-format.cmake")
Expand Down
74 changes: 74 additions & 0 deletions cmake/noa/compiler/options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
function(noa_add_default_options visibility target)
if(NOA_COMPILER_MSVC)
# See https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category
target_compile_options("${target}" ${visibility}
/options:strict
/permissive-
/W4
/WL
/MP
/sdl)
else()
target_compile_options("${target}" ${visibility}
-Wall
-Wextra
-Wpedantic
-Wshadow
-Wdouble-promotion
-Wconversion
-Wunused-parameter
-Wtrigraphs
-Wunreachable-code
-Wmissing-braces
-Wparentheses
-Wswitch
-Wunused-function
-Wunused-label
-Wunused-parameter
-Wunused-variable
-Wunused-value
-Wempty-body
-Wuninitialized
-Wshadow
-Wconversion
-Wenum-conversion
-Wfloat-conversion
-Wimplicit-fallthrough
-Wsign-compare
# TODO: Enable this flag for safety
-Wno-sign-conversion
-Wunknown-pragmas
-Wnon-virtual-dtor
-Woverloaded-virtual
-Winvalid-offsetof

# Assume that signed arithmetic overflow of addition, subtraction and
# multiplication wraps around using twos-complement representation
# See https://users.cs.utah.edu/~regehr/papers/overflow12.pdf
# See https://www.postgresql.org/message-id/[email protected]
-fwrapv)
endif()

if(NOA_COMPILER_LLVM)
target_compile_options("${target}" ${visibility}
-Wbool-conversion
-Wint-conversion
-Wpointer-sign
-Wconditional-uninitialized
-Wconstant-conversion
-Wnon-literal-null-conversion
-Wshorten-64-to-32
-Wdeprecated-implementations
-Winfinite-recursion
-Wnewline-eof
-Wfour-char-constants
-Wselector
-Wundeclared-selector
-Wdocumentation
-Wmove
-Wc++11-extensions
-Wcomma
-Wno-exit-time-destructors
-Wrange-loop-analysis)
endif()
endfunction()

0 comments on commit 26f9de8

Please sign in to comment.