summaryrefslogtreecommitdiffstats
path: root/project/cmake/scripts/common/AddOptions.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'project/cmake/scripts/common/AddOptions.cmake')
-rw-r--r--project/cmake/scripts/common/AddOptions.cmake78
1 files changed, 78 insertions, 0 deletions
diff --git a/project/cmake/scripts/common/AddOptions.cmake b/project/cmake/scripts/common/AddOptions.cmake
new file mode 100644
index 0000000..96837c1
--- /dev/null
+++ b/project/cmake/scripts/common/AddOptions.cmake
@@ -0,0 +1,78 @@
1# - Add options without repeating them on the command line
2#
3# Synopsis:
4#
5# add_options (lang build opts)
6#
7# where:
8#
9# lang Name of the language whose compiler should receive the
10# options, e.g. CXX. If a comma-separated list is received
11# then the option is added for all those languages. Use the
12# special value ALL_LANGUAGES for these languages: CXX, C
13# and Fortran
14#
15# build Kind of build to which this options should apply,
16# such as DEBUG and RELEASE. This can also be a comma-
17# separated list. Use the special value ALL_BUILDS to apply
18# to all builds.
19#
20# opts List of options to add. Each should be quoted.
21#
22# Example:
23#
24# add_options (CXX RELEASE "-O3" "-DNDEBUG" "-Wall")
25
26function(add_options langs builds)
27 # special handling of empty language specification
28 if("${langs}" STREQUAL "ALL_LANGUAGES")
29 set(langs CXX C Fortran)
30 endif()
31 foreach(lang IN LISTS langs)
32 # prepend underscore if necessary
33 foreach(build IN LISTS builds)
34 if(NOT ("${build}" STREQUAL "ALL_BUILDS"))
35 set(_bld "_${build}")
36 string(TOUPPER "${_bld}" _bld)
37 else()
38 set(_bld "")
39 endif()
40 foreach(_opt IN LISTS ARGN)
41 set(_var "CMAKE_${lang}_FLAGS${_bld}")
42 #message(STATUS "Adding \"${_opt}\" to \${${_var}}")
43 # remove it first
44 string(REPLACE "${_opt}" "" _without "${${_var}}")
45 string(STRIP "${_without}" _without)
46 # we need to strip this one as well, so they are comparable
47 string(STRIP "${${_var}}" _stripped)
48 # if it wasn't there, then add it at the end
49 if("${_without}" STREQUAL "${_stripped}")
50 # don't add any extra spaces if no options yet are set
51 if(NOT ${_stripped} STREQUAL "")
52 set(${_var} "${_stripped} ${_opt}")
53 else()
54 set(${_var} "${_opt}")
55 endif()
56 set(${_var} "${${_var}}" PARENT_SCOPE)
57 endif()
58 endforeach()
59 endforeach()
60 endforeach()
61endfunction()
62
63# set varname to flag unless user has specified something that matches regex
64function(set_default_option varname flag regex)
65 if(NOT "$ENV{CXXFLAGS}" MATCHES "${regex}"
66 AND NOT "${CMAKE_CXX_FLAGS}" MATCHES "${regex}"
67 AND NOT "${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE}}" MATCHES "${regex}")
68 set(${varname} ${flag} PARENT_SCOPE)
69 else()
70 set(${varname} PARENT_SCOPE)
71 endif()
72endfunction()
73
74# note: this must be called before project()
75macro(no_default_options)
76 # prevent the platform probe to set options
77 set(CMAKE_NOT_USING_CONFIG_FLAGS TRUE)
78endmacro()