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-2021 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 macro(print_info msg)
128 message("${Blue}${msg}${ResetColor}")
131 # Helper to print the configuration of a 2-valued or 3-valued option 'var'
133 function(print_config str var)
134 if("${var}" STREQUAL "ON")
135 set(OPT_VAL_STR "on")
136 elseif("${var}" STREQUAL "OFF" OR "${var}" STREQUAL "IGNORE")
137 set(OPT_VAL_STR "off")
139 set(OPT_VAL_STR "${var}")
141 message("${Blue}${str}: ${Green}${OPT_VAL_STR}${ResetColor}")
145 # Collect all source files that are required to build libcvc4 in LIBCVC4_SRCS
146 # or LIBCVC4_GEN_SRCS. If GENERATED is the first argument the sources are
147 # added to LIBCVC4_GEN_SRCS. All sources are prepended with the absolute
148 # current path path. CMAKE_CURRENT_BINARY_DIR is prepended
149 # to generated source files.
150 macro(libcvc4_add_sources)
151 set(_sources ${ARGV})
153 # Check if the first argument is GENERATED.
154 list(GET _sources 0 _generated)
155 if(${_generated} STREQUAL "GENERATED")
156 list(REMOVE_AT _sources 0)
157 set(_cur_path ${CMAKE_CURRENT_BINARY_DIR})
158 set(_append_to LIBCVC4_GEN_SRCS)
160 set(_cur_path ${CMAKE_CURRENT_SOURCE_DIR})
161 set(_append_to LIBCVC4_SRCS)
164 # Prepend source files with current path.
165 foreach(_src ${_sources})
166 list(APPEND ${_append_to} "${_cur_path}/${_src}")
170 _rel_path "${PROJECT_SOURCE_DIR}/src" "${CMAKE_CURRENT_SOURCE_DIR}")
172 # Make changes to list ${_append_to} visible to the parent scope if not
174 # Note: ${_append_to} refers to the variable name whereas ${${_append_to}}
175 # refers to the contents of the variable.
177 set(${_append_to} ${${_append_to}} PARENT_SCOPE)
181 # Check if given Python module is installed and raises a FATAL_ERROR error
182 # if the module cannot be found.
183 function(check_python_module module)
186 ${PYTHON_EXECUTABLE} -c "import ${module}"
194 "Could not find module ${module} for Python "
195 "version ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}. "
196 "Make sure to install ${module} for this Python version "
197 "via \n`${PYTHON_EXECUTABLE} -m pip install ${module}'.\n"
198 "Note: You need to have pip installed for this Python version.")