MCPcopy Index your code
hub / github.com/couchbase/couchbase-python-client / create_cmake_config

Method create_cmake_config

pycbc_build_setup.py:136–231  ·  view source on GitHub ↗
(cls,  # noqa: C901
                            output_dir: str,
                            source_dir: str,
                            set_cpm_cache: Optional[bool] = None
                            )

Source from the content-addressed store, hash-verified

134
135 @classmethod
136 def create_cmake_config(cls, # noqa: C901
137 output_dir: str,
138 source_dir: str,
139 set_cpm_cache: Optional[bool] = None
140 ) -> CMakeConfig:
141 env = os.environ.copy()
142 num_threads = env.pop('PYCBC_CMAKE_PARALLEL_THREADS', '4')
143 build_type = env.pop('PYCBC_BUILD_TYPE')
144 cmake_generator = env.pop('PYCBC_CMAKE_SET_GENERATOR', None)
145 cmake_arch = env.pop('PYCBC_CMAKE_SET_ARCH', None)
146 cmake_config_args = [CMAKE_EXE,
147 source_dir,
148 f'-DCMAKE_BUILD_TYPE={build_type}',
149 f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={output_dir}',
150 f'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{build_type.upper()}={output_dir}']
151
152 cmake_config_args.extend(
153 [x for x in
154 os.environ.get('CMAKE_COMMON_VARIABLES', '').split(' ')
155 if x])
156
157 python3_find_strategy = env.get('PYCBC_PYTHON3_FIND_STRATEGY', 'LOCATION')
158 cmake_config_args += [f'-DPython3_FIND_STRATEGY={python3_find_strategy}']
159
160 python3_rootdir = env.get('PYCBC_PYTHON3_ROOT_DIR', None)
161 if python3_rootdir:
162 cmake_config_args += [f'-DPython3_ROOT_DIR={python3_rootdir}']
163
164 python3_executable = env.get('PYCBC_PYTHON3_EXECUTABLE', None)
165 if python3_executable is None and sys.executable:
166 # if sys.executable determines the path we want to use that to determine the
167 # Python version in our get_python_version CMake function.
168 python3_executable = sys.executable
169 env['PYCBC_PYTHON3_EXECUTABLE'] = python3_executable
170 if python3_executable:
171 cmake_config_args += [f'-DPython3_EXECUTABLE={python3_executable}']
172
173 python3_include = env.get('PYCBC_PYTHON3_INCLUDE_DIR', None)
174 if python3_include:
175 cmake_config_args += [f'-DPython3_INCLUDE_DIR={python3_include}']
176
177 if set_cpm_cache is None:
178 set_cpm_cache = env.pop('PYCBC_SET_CPM_CACHE', 'false').lower() in ENV_TRUE
179 use_cpm_cache = env.pop('PYCBC_USE_CPM_CACHE', 'true').lower() in ENV_TRUE
180
181 if set_cpm_cache is True:
182 # if we are setting the cache, we don't want to attempt a build (it will fail).
183 use_cpm_cache = False
184 if os.path.exists(CXXCBC_CACHE_DIR):
185 shutil.rmtree(CXXCBC_CACHE_DIR)
186 cmake_config_args += [f'-DCOUCHBASE_CXX_CPM_CACHE_DIR={CXXCBC_CACHE_DIR}',
187 '-DCPM_DOWNLOAD_ALL=ON',
188 '-DCPM_USE_NAMED_CACHE_DIRECTORIES=ON',
189 '-DCPM_USE_LOCAL_PACKAGES=OFF']
190
191 if use_cpm_cache is True:
192 if not os.path.exists(CXXCBC_CACHE_DIR):
193 raise OptionError(f'Cannot use cached dependencies, path={CXXCBC_CACHE_DIR} does not exist.')

Callers 2

runMethod · 0.80
build_extensionMethod · 0.80

Calls 5

CMakeConfigClass · 0.85
popMethod · 0.45
getMethod · 0.45
existsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected