{"id":13342948,"url":"https://github.com/jonathanpoelen/cpp-compiler-options","last_synced_at":"2025-12-24T05:38:01.392Z","repository":{"id":40555701,"uuid":"120681355","full_name":"jonathanpoelen/cpp-compiler-options","owner":"jonathanpoelen","description":"Compilation options for different versions of Clang, GCC, MSVC, ICC and Emscripten. Provided a generator and different file formats (cmake, xmake, meson, premake5, bjam/b2, ...)","archived":false,"fork":false,"pushed_at":"2024-11-19T23:53:56.000Z","size":2710,"stargazers_count":23,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-20T00:27:11.651Z","etag":null,"topics":["b2","build-system","clang","cmake","cpp","gcc","meson","premake","xmake"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonathanpoelen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-07T22:44:53.000Z","updated_at":"2024-11-19T23:54:02.000Z","dependencies_parsed_at":"2024-07-21T17:32:41.958Z","dependency_job_id":"7b94327f-6941-4ca7-ab0d-e446da5143cb","html_url":"https://github.com/jonathanpoelen/cpp-compiler-options","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanpoelen%2Fcpp-compiler-options","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanpoelen%2Fcpp-compiler-options/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanpoelen%2Fcpp-compiler-options/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanpoelen%2Fcpp-compiler-options/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonathanpoelen","download_url":"https://codeload.github.com/jonathanpoelen/cpp-compiler-options/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243150693,"owners_count":20244446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["b2","build-system","clang","cmake","cpp","gcc","meson","premake","xmake"],"created_at":"2024-07-29T19:30:08.559Z","updated_at":"2025-12-24T05:38:01.382Z","avatar_url":"https://github.com/jonathanpoelen.png","language":"Lua","readme":"\nCompilation options for different versions of Clang, GCC, MSVC, Emscripten, ICC and ICX. Provided a generator and different file formats (build system and compiler).\n\nThe `output` directory contains files for `cmake`, `xmake`, `premake5`, `meson`, `bjam`/`b2`, `scons` and command-line options for `gcc`/`g++`, `clang`/`clang++` and `msvc`. If a version of the compiler is not present, then there is no difference compared to an older version.\n\nEach build system also has a branch with only the files it needs.\n\nHere is an example with gcc:\n\n```cpp\nint main()\n{\n  int x;\n  return x; // used but uninitialized\n}\n```\n\n$ `g++ main.cpp`\n\n\u003e No output\n\n$ `g++ main.cpp @cpp-compiler-options/output/cpp/gcc/gcc-6.1-warnings`\n\n```\nmain.cpp: In function ‘int main()’:\nmain.cpp:4:10: warning: ‘x’ is used uninitialized in this function [-Wuninitialized]\n    4 |   return x; // used but not initialized\n      |          ^\n```\n\n(`@file` is a special option of gcc and clang for read command-line options from file.)\n\n\n\u003c!-- toc --\u003e\n1. [Options](#options)\n    1. [To know](#to-know)\n    2. [Sanitizers](#sanitizers)\n    3. [Recommended options](#recommended-options)\n2. [Use generated files](#use-generated-files)\n    1. [CMake](#cmake)\n    2. [xmake](#xmake)\n    3. [Meson](#meson)\n    4. [Premake5](#premake5)\n    5. [Bjam/B2 (Boost.Build)](#bjamb2-boostbuild)\n    6. [SCons](#scons)\n    7. [Bash alias for gcc/clang](#bash-alias-for-gccclang)\n3. [Generators](#generators)\n    1. [generators/compiler.lua](#generatorscompilerlua)\n    2. [generators/list_options.lua](#generatorslist_optionslua)\n    3. [generators/{cmake,xmake,meson,premake5,bjam,scons}.lua](#generatorscmakexmakemesonpremake5bjamsconslua)\n4. [How to add or modify options?](#how-to-add-or-modify-options)\n    1. [Flags](#flags)\n    2. [Compilers and linkers](#compilers-and-linkers)\n    3. [Platform](#platform)\n    4. [Options and levels](#options-and-levels)\n    5. [Conditions](#conditions)\n    6. [if_mt](#if_mt)\n    7. [Others](#others)\n\u003c!-- /toc --\u003e\n\n# Options\n\nSupported options are listed below by category.\nThe same option can be found in several categories.\n\nFor a full description of options and values,\nsee [C++ Compiler Options reference](https://jonathanpoelen.github.io/cpp-compiler-options/)\nor use the `list_options.lua` generator.\n\nThe first value corresponds to the one used by default,\nand the value `default` has no associated behavior.\n\nOptions with a default value other than `default` are listed below.\n\n\u003c!-- ./compiler-options.lua generators/list_options.lua --color --categorized --\u003e\n```ini\n# Warning options:\n\nwarnings = on default off essential extensive\nwarnings_as_error = default off on basic\nbidi_char_warnings = any default any_and_ucn unpaired unpaired_and_ucn\nconversion_warnings = on default off sign float conversion all\ncovered_switch_default_warnings = on default off\nmsvc_crt_secure_no_warnings = on default off\nnoexcept_warnings = default off on\nreproducible_build_warnings = default off on\nshadow_warnings = off default on local compatible_local all\nsuggest_attributes = on default off common analysis unity all\nswitch_warnings = on default off exhaustive_enum mandatory_default exhaustive_enum_and_mandatory_default\nunsafe_buffer_usage_warnings = default on off\nwindows_abi_compatibility_warnings = off default on\n\n\n# Pedantic options:\n\npedantic = on default off as_error\nstl_fix = on default off\n\n\n# Debug options:\n\nsymbols = default hidden strip_all gc_sections nodebug debug minimal_debug full_debug btf codeview ctf ctf1 ctf2 vms vms1 vms2 vms3 dbx lldb sce dwarf\nstl_hardening = default off fast extensive debug debug_with_broken_abi\nsanitizers = default off on with_minimal_code_size extra extra_with_minimal_code_size address address_with_minimal_code_size thread undefined undefined_minimal_runtime scudo_hardened_allocator\nvar_init = default uninitialized pattern zero\nemcc_debug = default off on slow\nndebug = with_optimization_1_or_above default off on\noptimization = default 0 g 1 2 3 fast size z\n\n\n# Optimization options:\n\ncpu = default generic native\nlto = default off on full thin_or_nothing whole_program whole_program_and_full_lto\noptimization = default 0 g 1 2 3 fast size z\noptimization_warnings = default off on\n\n\n# C++ options:\n\nexceptions = default off on\nrtti = default off on\n\n\n# Hardening options:\n\nhardened = default off on all\nstl_hardening = default off fast extensive debug debug_with_broken_abi\n\n\n# Static Analyzer options:\n\nanalyzer = default off on with_external_headers\nanalyzer_too_complex_warning = default off on\nanalyzer_verbosity = default 0 1 2 3\n\n\n# Other options:\n\ncolor = default auto never always\ncoverage = default off on\ndiagnostics_format = default fixits patch print_source_range_info\ndiagnostics_show_template = default tree without_elided_types tree_without_elided_types\nlinker = default bfd gold lld mold native\nmsvc_diagnostics_format = caret default classic column\nmsvc_isystem = default anglebrackets include_and_caexcludepath external_as_include_system_flag assumed\nmsvc_isystem_with_template_instantiations_treated_as_non_external = default off on\nwindows_bigobj = on default\n```\n\u003c!-- ./compiler-options.lua --\u003e\n\nIf not specified:\n\n- `bidi_char_warnings` is `any`\n- `msvc_diagnostics_format` is `caret`\n- `ndebug` is `with_optimization_1_or_above`\n- The following values are `off`:\n  - `shadow_warnings`\n  - `windows_abi_compatibility_warnings`\n- The following values are `on`:\n  - `conversion_warnings`\n  - `covered_switch_default_warnings`\n  - `msvc_crt_secure_no_warnings`\n  - `pedantic`\n  - `stl_fix`\n  - `suggest_attributes`\n  - `switch_warnings`\n  - `warnings`\n  - `windows_bigobj`\n\n\u003c!-- enddefault --\u003e\n\n## To know\n\n- `msvc_isystem=external_as_include_system_flag` is only available with `cmake`.\n- `stl_hardening=debug`\n  - msvc: unlike `stl_hardening=debug_with_broken_abi`, STL debugging is not enabled by this option, as it breaks the ABI (only hardening mode is enabled on recent versions). However, as the `_DEBUG` macro can be defined in many different ways, STL debugging can be activated and the ABI broken.\n\n\n## Sanitizers\n\nSome sanitizers activated at compile time are only realistically active in the presence of a configuration in an environment variable.\n`sanitizers=on` does not include these sanitizers, unlike `sanitizers=extra`.\nThe environment variables to use are as follows:\n\n```sh\n# cl (Windows)\nASAN_OPTIONS=detect_stack_use_after_return=1\n\n# gcc / clang (see -fsanitize=pointer-subtract and -fsanitize=pointer-compare)\nASAN_OPTIONS=detect_invalid_pointer_pairs=2\n\n# macOS\nASAN_OPTIONS=detect_leaks=1\n```\n\nSee\n[AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer),\n[UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html),\n[-fsanitize=pointer-compare](https://gcc.gnu.org/onlinedocs/gcc/Instrumentation-Options.html#index-fsanitize_003dpointer-compare) with GCC and\n[-fsanitize-address-use-after-return](https://learn.microsoft.com/en-us/cpp/sanitizers/asan-building#fsanitize-address-use-after-return-compiler-option-experimental) with cl compiler\nfor more details.\n\nSee [AddressSanitizer Flags](https://github.com/google/sanitizers/wiki/AddressSanitizerFlags#run-time-flags)\nfor a list of supported options.\nA useful pre-set to enable more aggressive diagnostics compared to the default behavior is given below:\n\n```sh\nASAN_OPTIONS=\\\nstrict_string_checks=1:\\\ndetect_stack_use_after_return=1:\\\ncheck_initialization_order=1:\\\nstrict_init_order=1:\\\nalloc_dealloc_mismatch=1\n```\n\n## Recommended options\n\nSome of the recommendations here are already made by build systems.\nThese include `ndebug`, `symbols` and `optimization`.\n\ncategory | options\n---------|---------\ndebug | `emcc_debug=on` or `slow` (useless if Emscripten is not used)\u003cbr\u003e`optimization=g` or `default`\u003cbr\u003e`sanitizers=on` or `with_minimal_code_size`\u003cbr\u003e`stl_hardening=debug_with_broken_abi` or `debug`\u003cbr\u003e`symbols=debug` or `full_debug`\u003cbr\u003e`var_init=pattern`\nrelease | `cpu=native`\u003cbr\u003e`lto=on`\u003cbr\u003e`ndebug=on`\u003cbr\u003e`optimization=3`\u003cbr\u003e`rtti=off`\u003cbr\u003e`symbols=strip_all`\nsecurity | `hardened=on`\u003cbr\u003e`stl_hardening=fast` or `extensive`\nreally strict warnings | `pedantic=as_error`\u003cbr\u003e`suggest_attributes=common`\u003cbr\u003e`warnings=extensive`\u003cbr\u003e`conversion_warnings=all`\u003cbr\u003e`shadow_warnings=local`\u003cbr\u003e`switch_warnings=exhaustive_enum`\u003cbr\u003e`windows_abi_compatibility_warnings=on`\n\n\n# Use generated files\n\nThis is what enabled of sanitizers looks like with the different build systems available:\n\n$ `cmake -DJLN_SANITIZERS=on`\n\n$ `xmake f --jln-sanitizers=on`\n\n$ `premake5 --jln-sanitizers=on`\n\n$ `meson -Djln_sanitizers=on`\n\n$ `bjam -s jln_sanitizers=on`\n\n$ `scons jln_sanitizers=on`\n\n(`jln` is a parameterizable prefix: `./compiler-options.lua generators/cmake.lua [prefix]`)\n\n\n## CMake\n\n```cmake\n# launch example: cmake -DJLN_SANITIZERS=on\ninclude(output/cpp/cmake)\n\n# init default values\n# jln_init_flags(\n#     [\u003cjln-option\u003e \u003cdefault_value\u003e]...\n#     [AUTO_PROFILE on]\n#     [VERBOSE on]\n#     [BUILD_TYPE type [\u003cjln-option\u003e \u003cdefault_value\u003e]...]...\n# )\n# AUTO_PROFILE: enables options based on CMAKE_BUILD_TYPE\n#               (assumes \"Debug\" if CMAKE_BUILD_TYPE is empty)\n# BUILD_TYPE: enables following options only if ${CMAKE_BUILD_TYPE}\n#             has the same value (CMAKE_BUILD_TYPE assumed to Debug if empty)\njln_init_flags(\n  SUGGESTIONS on      # set SUGGESTIONS default value to \"on\"\n  BUILD_TYPE debug\n    SANITIZERS on     # set SANITIZERS default value to \"on\" only in Debug build\n  BUILD_TYPE release\n    LTO on            # set LTO default value to \"on\" only in Release build\n)\n\n\n# jln_target_interface(\n#     \u003clibname\u003e {INTERFACE|PUBLIC|PRIVATE}\n#     [\u003cjln-option\u003e \u003cvalue\u003e]...\n#     [DISABLE_OTHERS {on|off}]\n#     [BUILD_TYPE type [\u003cjln-option\u003e \u003cvalue\u003e]...]...\n# )\njln_target_interface(mytarget1 INTERFACE WARNINGS very_strict) # set WARNINGS to \"very_strict\"\n\n\n# jln_flags(\n#     CXX_VAR \u003cout-variable\u003e\n#     LINK_VAR \u003cout-variable\u003e\n#     [\u003cjln-option\u003e \u003cvalue\u003e]...\n#     [DISABLE_OTHERS {on|off}]\n#     [BUILD_TYPE type [\u003cjln-option\u003e \u003cvalue\u003e]...]...\n# )\njln_flags(CXX_VAR CXX_FLAGS LINK_VAR LINK_FLAGS WARNINGS very_strict)\n\ntarget_link_libraries(mytarget2 INTERFACE ${LINK_FLAGS})\ntarget_compile_options(mytarget2 INTERFACE ${CXX_FLAGS})\n\n# NOTE: for C, jln_ prefix function becomes jln_c_ and CXX_VAR becomes C_VAR\n```\n\n\n## xmake\n\nCopy `output/cpp/xmake_options.lua` to `myproj/cpp/xmake.lua` and `output/cpp/xmake` to `myproj/cpp/flags.lua`. `cpp` is an arbitrary directory name, this can be changed.\n\n```lua\n-- launch example: xmake f --jln-sanitizers=on\n\nincludes'cpp'\n\n-- Registers new command-line options and set default values\njln_cxx_init_options({warnings='very_strict', warnings_as_error='basic'})\n\n-- Set options for a specific mode (see also jln_cxx_rule())\n-- When the first parameter is nil or unspecified, a default configuration is used.\njln_cxx_init_modes({\n  debug={\n    stl_hardening='debug_with_broken_abi',\n  },\n  release={\n    function() ... end, -- callback for release mode\n    lto='on',\n  },\n  -- ...\n})\n\ntarget('hello1')\n  set_kind('binary')\n  add_files('src/hello.cpp')\n\n\n\n-- Create a new rule. Options are added to the current configuration\njln_cxx_rule('custom_rule', {warnings_as_error='on'})\n\ntarget('hello2')\n  set_kind('binary')\n  add_rules('custom_rule')\n  add_files('src/hello.cpp')\n\n\n\ntarget('hello3')\n  set_kind('binary')\n  -- Custom configuration when jln_cxx_rule() or jln_cxx_modes() are not enough\n  on_load(function(target)\n    import'cpp.flags'\n    -- see also get_flags() and create_options()\n    local flags = flags.set_flags(target, {elide_type='on'})\n    print(flags)\n  end)\n  add_files('src/hello.cpp')\n\n\n-- NOTE: for C, jln_cxx_ prefix become jln_c_\n```\n\n\n## Meson\n\nCopy `output/cpp/meson_options.txt` and rename `output/cpp/meson` to `meson_jln_flags/meson.build`.\n\n```meson\n# launch example: meson -Djln_sanitizers=on\n# note: `meson --warnlevel=0` implies `--Djln_warnings=off`\n\nproject('test', 'cpp')\n\n# default options (without prefix)\n# optional\njln_default_flags = {'rtti': 'off'}\n\n# options for specific buildtype (added to default options)\n# optional.\njln_buildtype_flags = {\n  'debug': {'rtti': 'on'},\n}\n\n# Use a default configuration when jln_buildtype_flags is unspecified.\n# optional.\njln_use_profile_buildtype = true\n\n# optional\njln_custom_flags = [\n  {'rtti': 'off', 'optimization': '3'}, # (0) opti flags\n  {'debug': 'on'}, # (1) debug flags\n  # { ... } # (2)\n  # etc\n]\n\n# declare jln_link_flags, jln_cpp_flags, jln_custom_cpp_flags and jln_custom_link_flags\nsubdir('meson_jln_flags')\n\nmy_opti_cpp_flags = jln_custom_cpp_flags[0] # (0) opti flags (see above)\nmy_opti_link_flags = jln_custom_link_flags[0]\nmy_debug_cpp_flags = jln_custom_cpp_flags[1] # (1) debug flags (see above)\nmy_debug_link_flags = jln_custom_link_flags[1]\n# my_... = jln_custom_cpp_flags[2] # (2)\n# my_... = jln_custom_link_flags[2]\n# etc\n\nexecutable('demo', 'main.cpp', link_args: jln_link_flags, cpp_args: jln_cpp_flags)\n\n# NOTE: for C, jln_ prefix becomes jln_c_\n```\n\n\n## Premake5\n\n```lua\n-- launch example: premake5 --jln-sanitizers=on\n\ninclude \"output/cpp/premake5\"\n\n-- Registers new command-line options and set default values\njln_newoptions({warnings='very_strict'})\n\n    -- getoptions(values = {}, disable_others = false, print_compiler = false)\n    -- `values`: table. ex: {warnings='on'}\n    -- `values` can have 3 additional fields:\n    --  - `cxx`: compiler name (otherwise deducted from --cxx and --toolchain)\n    --  - `cxx_version` (otherwise deducted from cxx)\n    --  - `ld`: linker name\n    -- `disable_others`: boolean\n    -- `print_compiler`: boolean\n    -- return {cxxflags=table, ldflags=table}\n    -- Note: with C language, cxxflags, cxx and cxx_version become cflags, cc and cc_version\n    local options = flags.getoptions({elide_type='on'})\n    for _,opt in ipairs(options.cxxflags) do target:add('cxxflags', opt, {force=true}) end\n    for _,opt in ipairs(options.ldflags) do target:add('ldflags', opt, {force=true}) end\n\n    -- or equivalent (return also options)\n    flags.setoptions(target, {elide_type='on'})\n\n    -- return the merge of the default values and new value table\n    local values = flags.tovalues({elide_type='on'}, --[[disable_others:bool]])\n    print(values)\n\n-- jln_getoptions(values = {}, disable_others = false, print_compiler = false)\n-- `values`: table. ex: {warnings='on'}\n-- `values` can have 3 additional fields:\n--  - `cxx`: compiler name\n--  - `cxx_version` (otherwise deducted from cxx)\n--  - `ld`: linker name\n-- `disable_others`: boolean\n-- `print_compiler`: boolean\n-- return {buildoptions=table, linkoptions=table}\n-- Note: with C language, cxx and cxx_version become cc and cc_version\nlocal mylib_options = jln_getoptions({elide_type='on'})\nbuildoptions(mylib_options.buildoptions)\nlinkoptions(mylib_options.linkoptions)\n\n-- or equivalent\njln_setoptions({elide_type='on'})\n\n-- returns the merge of the default values and new value table\nlocal values = jln_tovalues({elide_type='on'}, --[[disable_others:bool]])\nprint(values)\n\n-- NOTE: for C, jln_ prefix function becomes jln_c_\n```\n\n\n## Bjam/B2 (Boost.Build)\n\n```jam\n# launch example: bjam -s jln_sanitizers=on\n\ninclude output/cpp/bjam ;\n\n# rule jln_flags ( properties * )\n\nproject name : requirements\n  \u003cjln-lto-default\u003eon # enable jln-lto\n  \u003cjln-hardened-default\u003eon\n  \u003cconditional\u003e@jln_flags\n: default-build release ;\n\nexe test : test.cpp : \u003cjln-hardened-incidental\u003eoff # incidental version of \u003cjln-hardened\u003eoff\n\n# NOTE: for C, jln_flags becomes jln_c_flags\n```\n\n\n## SCons\n\n```py\n# launch example: scons jln_sanitizers=on\n\nimport jln_options as jln\n\njln.set_global_flags({'rtti': 'off'})\n\nvars = Variables(None, ARGUMENTS)\njln.add_variables(vars, {'debug':'on'}) # default value of debug to on\n\n# get_flags(variables[, env]) -\u003e {flags=[...], linkflags=[...]}\nflags1 = jln.get_flags(vars)\nflags2 = jln.get_flags({'debug':'on'})\n```\n\n\n## Bash alias for gcc/clang\n\nThe scripts below add 4 aliases with `warnings=on`, `pedantic=on` and `color=always`.\n\n- `gw++` for g++\n- `cw++` for clang++\n\n```sh\nfor comp in g++ clang++ ; do\n  version=$($comp --version | sed -E '1!d;s/.*([0-9]\\.[0-9]\\.[0-9]).*/\\1/g')\n  echo \"alias ${comp:0:1}w++='$comp \"$(./compiler-options.lua generators/compiler.lua \"$comp-$version\" warnings pedantic color=always)\\'\ndone \u003e\u003e ~/.bashrc\n```\n\n- `gwcc` for gcc\n- `cwcc` for clang\n\n```sh\nfor comp in gcc clang ; do\n  version=$($comp --version | sed -E '1!d;s/.*([0-9]\\.[0-9]\\.[0-9]).*/\\1/g')\n  echo \"alias ${comp:0:1}wcc='$comp \"$(./compiler-options.lua -c generators/compiler.lua \"$comp-$version\" warnings pedantic color=always)\\'\ndone \u003e\u003e ~/.bashrc\n```\n\n\n# Generators\n\nUsage:\n\n```\n./compiler-options.lua [-h] [-p] [-c] [-o outfilebase]\n                       [-t [-]{platform|compiler|linker}=name[,...]]\n                       [-f [-]{option_name[=value_name][,...]}]\n                       [-d option_name=value_name[,...]]\n                       {generator} [options...]\n```\n\n```bash\n./compiler-options.lua -f debug,warning generators/cmake.lua # only with debug and warning\n./compiler-options.lua -f -debug,warning generators/cmake.lua # without debug nor warning\n```\n\n- `-p` Print an AST.\n- `-c` for C, default is C++.\n- `-t` Restrict to a list of platform, compiler or linker. When the list is prefixed with '-', values are removed from current AST.\n- `-f` Restrict to a list of option/value. When the list is prefixed with `-`, options/values are removed.\n- `-d` Set new default value. An empty string for `value_name` is equivalent to `default`.\n\n## generators/compiler.lua\n\nSee `./compiler-options.lua generators/compiler.lua -h` for detailed usage information.\n\n## generators/list_options.lua\n\n$ `./compiler-options.lua generators/list_options.lua [--profile] [--color]`\n\nChecks and displays options and their values.\n\n## generators/{cmake,xmake,meson,premake5,bjam,scons}.lua\n\nGenerators for different build system.\n\n$ `./compiler-options.lua [-o filebase] {generator} [option-prefix]`\n\n\n# How to add or modify options?\n\nEdit `compiler-options.lua` file.\n\nThe `MakeAST` function contains the options tree.\n\n`_koptions` of `Vbase` contains the list of available options.\n`_opts_by_category` a categorization of these options.\n\n\n## Flags\n\n- `c`, `cxx`, `flag`, `link`, `fl`\n\n```lua\nc'-Wall' -- C only\ncxx'-Wall' -- C++ only\nflag'-Wall' -- C and C++\nlink'-flto' -- Link option\nfl'xxx' -- is a alias of {flag'xxx',link'xxx'}\n```\n\n\n## Compilers and linkers\n\n- `gcc` for gcc or g++\n- `clang` for clang or clang++\n- `clang_cl` for clang-cl\n- `clang_emcc` refers to the version of clang used by emcc\n- `clang_like` refers to `clang`, `clang_cl` and `clang_emcc`\n- `msvc` for cl\n- `icc`\n- `icl`\n- `lld_link` for lld-link\n- `ld64`\n\n`icx`, `icpx`, `dpcpp` are equivalent to `clang`.\n\nWith `mingw`, the compiler is `gcc`.\n\nversion can be specified with `vers` or a compiler name and a parameter of the form `{operator}{major}.{minor}`.\n\n```lua\ngcc { ... } -- for gcc only\ngcc'\u003e=5' { ... } -- for \u003e= gcc-5\ngcc'\u003e=5.3' { ... } -- for \u003e= gcc-5.3\ngcc'\u003c5.3' { ... } -- for \u003c gcc-5.3\n\ngcc'\u003e=5.3' { ... } -- equivalent to `gcc { vers'\u003e=5.3' { ... } }`\n```\n\n## Platform\n\n- `linux`\n- `windows`\n- `macos`\n- `mingw` with `gcc` as compiler\n\n\n## Options and levels\n\n- `opt'name' { ... }`\n- `lvl'name' { ... }`\n\n```lua\nopt'warnings' { -- if warnings is enabled (not `warnings=default`)\n  lvl'off' { cxx'-w' } -- for `warnings=off`\n}\n```\n\n- `has_opt'name' { ... }`\n\n```lua\nopt'warnings' {\n  has_opt'symbols' { -- if symbols is enabled (not `symbols=default`)\n    lvl'off' { cxx'-w' } -- for `warnings=off`\n  }\n}\n\nhas_opt'debug':with('gdb', 'on') { -- if debug is 'on' or 'gdb'\n  ...\n}\nhas_opt'debug':without('gdb', 'on') { -- if debug is not 'default', 'on' or 'gdb'\n  ...\n}\n```\n\n- `reset_opt'name'` for disabled an option\n\n```lua\nvers'\u003c8' {\n  reset_opt'lto' -- disable lto option when version \u003c 8\n}\n```\n\n## Conditions\n\n- `Or(...)`\n- `And(...)`\n\n```lua\nOr(gcc, clang, msvc) { ... }\nAnd(gcc, lvl'off') { ... }\n```\n\n## if_mt\n\nCompilers, linkers, platforms and condition returns a `if_mt`.\n\n- `-xxx {...}` for `not xxx`\n- `xxx {...} / yyy {...}` for `xxx or else yyy`\n\n```lua\nopt'warnings' { -lvl'on' { ... } } -- neither warnings=on nor warnings=default\nlvl'on' { xxx } / { yyy } -- equivalent to `{ lvl'on' { xxx }, -lvl'on' { yyy } }`\n```\n\nNote: `-opt'name'` isn't allowed\n\n## Others\n\n- `if_else(cond, f)` = `cond { f(true) } / f()`\n- `match(a,b,c,...)` = `a / b / c / ...`\n- `act(data)` for a specific action hardcoded into a generator\n  - cmake: `data` must be a table which can contain the keys:\n    - `cxx`: add the value in `CMAKE_CXX_FLAGS` / `CMAKE_C_FLAGS`\n    - `system_flag`: add the value in `CMAKE_INCLUDE_SYSTEM_FLAG_CXX` / `CMAKE_INCLUDE_SYSTEM_FLAG_C`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanpoelen%2Fcpp-compiler-options","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanpoelen%2Fcpp-compiler-options","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanpoelen%2Fcpp-compiler-options/lists"}