3 ## Top contributors (to current version):
4 ## Mathias Preiner, Aina Niemetz, Andres Noetzli
5 ## This file is part of the CVC4 project.
6 ## Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
7 ## in the top-level source directory and their institutional affiliations.
8 ## All rights reserved. See the file COPYING in the top-level source
9 ## directory for licensing information.
11 include(CheckCCompilerFlag)
12 include(CheckCXXCompilerFlag)
16 set(Yellow "${Esc}[33m")
17 set(ResetColor "${Esc}[m")
20 # Add a C flag to the global list of C flags.
21 macro(add_c_flag flag)
23 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}")
25 set(CMAKE_C_FLAGS "${flag}")
27 message(STATUS "Configuring with C flag '${flag}'")
30 # Add a CXX flag to the global list of CXX flags.
31 macro(add_cxx_flag flag)
33 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}")
35 set(CMAKE_CXX_FLAGS "${flag}")
37 message(STATUS "Configuring with CXX flag '${flag}'")
40 # Add a C and CXX flag to the global list of C/CXX flags.
41 macro(add_c_cxx_flag flag)
46 # Check if C flag is supported and add to global list of C flags.
47 macro(add_check_c_flag flag)
48 string(REGEX REPLACE "[-=]" "_" flagname ${flag})
49 check_c_compiler_flag("${flag}" HAVE_FLAG${flagname})
50 if(HAVE_FLAG${flagname})
55 # Check if CXX flag is supported and add to global list of CXX flags.
56 macro(add_check_cxx_flag flag)
57 string(REGEX REPLACE "[-=]" "_" flagname ${flag})
58 check_cxx_compiler_flag("${flag}" HAVE_FLAG${flagname})
59 if(HAVE_FLAG${flagname})
64 # Check if C/CXX flag is supported and add to global list of C/CXX flags.
65 macro(add_check_c_cxx_flag flag)
66 add_check_c_flag(${flag})
67 add_check_cxx_flag(${flag})
70 # Add required CXX flag. Configuration fails if the CXX flag is not supported
72 macro(add_required_cxx_flag flag)
73 string(REGEX REPLACE "[-=]" "_" flagnamename ${flag})
74 check_cxx_compiler_flag("${flag}" HAVE_FLAG${flagname})
75 if (NOT HAVE_FLAG${flagname})
76 message(FATAL_ERROR "Required compiler flag ${flag} not supported")
81 # Add required C flag. Configuration fails if the C flag is not supported by
83 macro(add_required_c_flag flag)
84 string(REGEX REPLACE "[-=]" "_" flagname ${flag})
85 check_c_compiler_flag("${flag}" HAVE_FLAG${flagname})
86 if (NOT HAVE_FLAG${flagname})
87 message(FATAL_ERROR "Required compiler flag ${flag} not supported")
92 # Add requied C/CXX flag. Configuration fails if the C/CXX flag is not
93 # supported by the compiler.
94 macro(add_required_c_cxx_flag flag)
95 add_required_c_flag(${flag})
96 add_required_cxx_flag(${flag})
99 # CVC4 Boolean options are three-valued to detect if an option was set by the
100 # user. The available values are: IGNORE (default), ON, OFF
101 # Default options do not override options that were set by the user, i.e.,
102 # cvc4_set_option only sets an option if it's value is still IGNORE.
103 # This e.g., allows the user to disable proofs for debug builds (where proofs
104 # are enabled by default).
105 macro(cvc4_option var description)
106 set(${var} IGNORE CACHE STRING "${description}")
107 # Provide drop down menu options in cmake-gui
108 set_property(CACHE ${var} PROPERTY STRINGS IGNORE ON OFF)
111 # Only set option if the user did not set an option.
112 macro(cvc4_set_option var value)
113 if(${var} STREQUAL "IGNORE")
118 # Prepend 'prepand_value' to each element of the list 'in_list'. The result
119 # is stored in 'out_list'.
120 function(list_prepend in_list prepand_value out_list)
121 foreach(_elem ${${in_list}})
122 list(APPEND ${out_list} "${prepand_value}${_elem}")
124 set(${out_list} ${${out_list}} PARENT_SCOPE)
127 # Helper to print the configuration of a 2-valued or 3-valued option 'var'
129 macro(print_config str var)
130 if(${var} STREQUAL "ON")
131 set(OPT_VAL_STR "on")
133 set(OPT_VAL_STR "off")
135 message("${str} ${OPT_VAL_STR}")
139 # Collect all source files that are required to build libcvc4 in LIBCVC4_SRCS
140 # or LIBCVC4_GEN_SRCS. If GENERATED is the first argument the sources are
141 # added to LIBCVC4_GEN_SRCS. All sources are prepended with the absolute
142 # current path path. CMAKE_CURRENT_BINARY_DIR is prepended
143 # to generated source files.
144 macro(libcvc4_add_sources)
145 set(_sources ${ARGV})
147 # Check if the first argument is GENERATED.
148 list(GET _sources 0 _generated)
149 if(${_generated} STREQUAL "GENERATED")
150 list(REMOVE_AT _sources 0)
151 set(_cur_path ${CMAKE_CURRENT_BINARY_DIR})
152 set(_append_to LIBCVC4_GEN_SRCS)
154 set(_cur_path ${CMAKE_CURRENT_SOURCE_DIR})
155 set(_append_to LIBCVC4_SRCS)
158 # Prepend source files with current path.
159 foreach(_src ${_sources})
160 list(APPEND ${_append_to} "${_cur_path}/${_src}")
164 _rel_path "${PROJECT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}")
166 # Make changes to list ${_append_to} visible to the parent scope if not
168 # Note: ${_append_to} refers to the variable name whereas ${${_append_to}}
169 # refers to the contents of the variable.
171 set(${_append_to} ${${_append_to}} PARENT_SCOPE)