mirror of
https://github.com/IRBorisov/ConceptCore.git
synced 2025-06-26 01:00:36 +03:00
Setup pyconcept build with CMake
This commit is contained in:
parent
6ad679c1fd
commit
843718b4a3
|
@ -19,7 +19,7 @@ output
|
||||||
packages
|
packages
|
||||||
**/build
|
**/build
|
||||||
**/venv
|
**/venv
|
||||||
**/pyconcept/import
|
**/pyconcept/ccl
|
||||||
**/egg-info
|
**/egg-info
|
||||||
|
|
||||||
|
|
||||||
|
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -11,7 +11,7 @@ build
|
||||||
output
|
output
|
||||||
venv/
|
venv/
|
||||||
CMakeUserPresets.json
|
CMakeUserPresets.json
|
||||||
pyconcept/import/
|
pyconcept/ccl/
|
||||||
*egg-info
|
*egg-info
|
||||||
|
|
||||||
ccl/rslang/src/RSParserImpl.output
|
ccl/rslang/src/RSParserImpl.output
|
||||||
|
|
25
.vscode/settings.json
vendored
25
.vscode/settings.json
vendored
|
@ -1,4 +1,20 @@
|
||||||
{
|
{
|
||||||
|
"search.exclude": {
|
||||||
|
".mypy_cache/": true,
|
||||||
|
".pytest_cache/": true
|
||||||
|
},
|
||||||
|
"python.testing.unittestArgs": ["-v", "-s", "./tests", "-p", "t_*.py"],
|
||||||
|
"python.testing.pytestEnabled": false,
|
||||||
|
"python.testing.unittestEnabled": true,
|
||||||
|
"python.analysis.typeCheckingMode": "off",
|
||||||
|
"python.analysis.ignore": ["**/tests/**", "**/venv/**"],
|
||||||
|
"cmake.configureOnEdit": false,
|
||||||
|
"cmake.configureOnOpen": false,
|
||||||
|
"cmake.sourceDirectory": "${workspaceFolder}/ccl",
|
||||||
|
"cmake.configureArgs": ["--preset=conan-default"],
|
||||||
|
"cmake.buildArgs": ["--preset=conan-release"],
|
||||||
|
"cmake.ctestArgs": ["--test-dir build", "--output-on-failure"],
|
||||||
|
"cmake.installPrefix": "output",
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"coredll",
|
"coredll",
|
||||||
"DCMAKE",
|
"DCMAKE",
|
||||||
|
@ -14,12 +30,5 @@
|
||||||
"pyconcept",
|
"pyconcept",
|
||||||
"rslang",
|
"rslang",
|
||||||
"symmdiff"
|
"symmdiff"
|
||||||
],
|
]
|
||||||
"cmake.configureOnEdit": false,
|
|
||||||
"cmake.configureOnOpen": false,
|
|
||||||
"cmake.sourceDirectory": "${workspaceFolder}/ccl",
|
|
||||||
"cmake.configureArgs": ["--preset=conan-default"],
|
|
||||||
"cmake.buildArgs": ["--preset=conan-release"],
|
|
||||||
"cmake.ctestArgs": ["--test-dir build", "--output-on-failure"],
|
|
||||||
"cmake.installPrefix": "output"
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,13 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
## Project options
|
## Project options
|
||||||
##
|
##
|
||||||
option(CC_UseSanitizers "Use sanitizers" FALSE)
|
option(CC_UseSanitizers "Use sanitizers" FALSE)
|
||||||
|
option(CC_BuildTests "Include tests executable" FALSE)
|
||||||
|
|
||||||
# Compiler options
|
# Compiler options
|
||||||
include(cmake/CXXTargets.cmake)
|
include(cmake/CXXTargets.cmake)
|
||||||
|
|
||||||
# Libraries folder
|
## Import internal targets
|
||||||
link_directories(import/lib)
|
add_subdirectory(ccl)
|
||||||
|
|
||||||
# Add pybind11
|
# Add pybind11
|
||||||
set(PYBIND11_FINDPYTHON ON)
|
set(PYBIND11_FINDPYTHON ON)
|
||||||
|
@ -49,9 +50,6 @@ target_include_directories(pyconcept
|
||||||
target_link_libraries(pyconcept
|
target_link_libraries(pyconcept
|
||||||
PUBLIC
|
PUBLIC
|
||||||
ConceptCoreLibrary
|
ConceptCoreLibrary
|
||||||
RSlang
|
|
||||||
cclLang
|
|
||||||
cclGraph
|
|
||||||
PRIVATE
|
PRIVATE
|
||||||
pybind11_all_do_not_use
|
pybind11_all_do_not_use
|
||||||
ccl_CXXwarnings
|
ccl_CXXwarnings
|
||||||
|
|
|
@ -4,6 +4,5 @@ graft include
|
||||||
graft tests
|
graft tests
|
||||||
graft cmake
|
graft cmake
|
||||||
|
|
||||||
|
|
||||||
include CMakeLists.txt
|
include CMakeLists.txt
|
||||||
recursive-include import *
|
recursive-include ccl *
|
|
@ -1,15 +1,20 @@
|
||||||
Set-Location $PSScriptRoot\..
|
Set-Location $PSScriptRoot\..
|
||||||
|
|
||||||
$packageName = 'pyconcept'
|
$packageName = 'pyconcept'
|
||||||
$output = "${PSScriptRoot}\..\..\..\output\py\x64\${packageName}"
|
$output = "${PSScriptRoot}\..\..\output\py\${packageName}"
|
||||||
$python = '.\venv\Scripts\python.exe'
|
$python = '.\venv\Scripts\python.exe'
|
||||||
$conan = 'conan'
|
$conan = '.\venv\Scripts\conan.exe'
|
||||||
|
|
||||||
|
$ccl_source = "${PSScriptRoot}\..\..\ccl"
|
||||||
|
$ccl_destination = "${PSScriptRoot}\..\ccl"
|
||||||
|
$ccl_exclude = @('*.vcxproj*','*packages.config','CMakeUserPresets.json')
|
||||||
|
|
||||||
function Build {
|
function Build {
|
||||||
PrepareEnv
|
# PrepareEnv
|
||||||
PrepareImports
|
PrepareImports
|
||||||
PrepareOutput
|
PrepareOutput
|
||||||
$wheel = BuildWheel
|
BuildProject
|
||||||
|
$wheel = Get-Childitem -Path "${output}\*.whl" -Name
|
||||||
if (-not (${wheel}) -or $LASTEXITCODE -ne 0) {
|
if (-not (${wheel}) -or $LASTEXITCODE -ne 0) {
|
||||||
Write-Error "No wheel generated for ${packageName}"
|
Write-Error "No wheel generated for ${packageName}"
|
||||||
Exit 1
|
Exit 1
|
||||||
|
@ -19,7 +24,7 @@ function Build {
|
||||||
}
|
}
|
||||||
|
|
||||||
function PrepareEnv {
|
function PrepareEnv {
|
||||||
Write-Host "Setting up environment for ${python}" -ForegroundColor DarkGreen
|
Write-Host "Set up environment for ${python}" -ForegroundColor DarkGreen
|
||||||
if (-not (Test-Path -Path ${python} -PathType Leaf)) {
|
if (-not (Test-Path -Path ${python} -PathType Leaf)) {
|
||||||
& 'python' -m venv .\venv
|
& 'python' -m venv .\venv
|
||||||
& $python -m pip install --upgrade pip
|
& $python -m pip install --upgrade pip
|
||||||
|
@ -29,25 +34,30 @@ function PrepareEnv {
|
||||||
|
|
||||||
function PrepareImports {
|
function PrepareImports {
|
||||||
Write-Host 'Copy imports' -ForegroundColor DarkGreen
|
Write-Host 'Copy imports' -ForegroundColor DarkGreen
|
||||||
if (Test-Path -Path 'import') {
|
if (Test-Path -Path ${ccl_destination}) {
|
||||||
Remove-Item 'import' -Recurse -Force
|
Remove-Item ${ccl_destination} -Recurse -Force
|
||||||
}
|
}
|
||||||
Copy-Item -Path "..\..\output\include" -Destination "import\include" -Recurse
|
New-Item -Path ${ccl_destination} -ItemType Directory | Out-Null
|
||||||
Copy-Item -Path "..\..\output\lib\x64" -Destination "import\lib" -Recurse
|
$source = Resolve-Path(${ccl_source})
|
||||||
|
$destination = Resolve-Path(${ccl_destination})
|
||||||
|
Get-ChildItem ${source} -Recurse -Exclude ${ccl_exclude} `
|
||||||
|
| Where-Object -Property 'FullName' -CNotLike '*build*' `
|
||||||
|
| Copy-Item -Destination {Join-Path ${destination}.Path $_.FullName.Substring(${source}.Path.length)}
|
||||||
}
|
}
|
||||||
|
|
||||||
function PrepareOutput {
|
function PrepareOutput {
|
||||||
|
Write-Host "Clear output at ${output}" -ForegroundColor DarkGreen
|
||||||
if (Test-Path -Path ${output}) {
|
if (Test-Path -Path ${output}) {
|
||||||
Remove-Item ${output} -Recurse -Force
|
Remove-Item ${output} -Recurse -Force
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function BuildWheel {
|
function BuildProject {
|
||||||
Write-Host 'Building project...' -ForegroundColor DarkGreen
|
Write-Host 'Configuring Conan...' -ForegroundColor DarkGreen
|
||||||
& ${conan} profile detect --force
|
& ${conan} profile detect --force
|
||||||
& ${conan} install .
|
& ${conan} install .
|
||||||
& $python -m build --no-isolation --wheel --outdir="${output}"
|
Write-Host 'Building project...' -ForegroundColor DarkGreen
|
||||||
return Get-Childitem -Path "${output}\*.whl" -Name
|
& $python -m build --wheel --no-isolation --outdir="${output}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function TestWheel([string] $wheelPath) {
|
function TestWheel([string] $wheelPath) {
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
# Build single project
|
|
||||||
# TODO: setup project folder as parameter
|
|
||||||
Set-Location $PSScriptRoot
|
|
||||||
|
|
||||||
& conan profile detect --force
|
|
||||||
& conan install .
|
|
||||||
|
|
||||||
& cmake --preset conan-default
|
|
||||||
& cmake --build --preset conan-release
|
|
||||||
& ctest --test-dir build --output-on-failure
|
|
||||||
& cmake --install build --prefix ../output
|
|
|
@ -32,11 +32,11 @@ class CMakeBuild(build_ext):
|
||||||
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
|
ext_fullpath = Path.cwd() / self.get_ext_fullpath(ext.name)
|
||||||
output_folder = ext_fullpath.parent.resolve()
|
output_folder = ext_fullpath.parent.resolve()
|
||||||
|
|
||||||
debug = int(os.environ.get('DEBUG', 0)) if self.debug is None else self.debug
|
debug_flag = int(os.environ.get('DEBUG', 0)) if self.debug is None else self.debug
|
||||||
build_type = 'Debug' if debug else 'Release'
|
build_type = 'Debug' if debug_flag else 'Release'
|
||||||
cmake_generator = os.environ.get('CMAKE_GENERATOR', '')
|
cmake_generator = os.environ.get('CMAKE_GENERATOR', '')
|
||||||
cmake_args = [
|
cmake_args = [
|
||||||
'--preset conan-release',
|
'--preset conan-default',
|
||||||
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={output_folder}{os.sep}",
|
f"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY={output_folder}{os.sep}",
|
||||||
f"-DCMAKE_BUILD_TYPE={build_type}"
|
f"-DCMAKE_BUILD_TYPE={build_type}"
|
||||||
]
|
]
|
||||||
|
@ -44,7 +44,7 @@ class CMakeBuild(build_ext):
|
||||||
if 'CMAKE_ARGS' in os.environ:
|
if 'CMAKE_ARGS' in os.environ:
|
||||||
cmake_args += [item for item in os.environ['CMAKE_ARGS'].split(' ') if item]
|
cmake_args += [item for item in os.environ['CMAKE_ARGS'].split(' ') if item]
|
||||||
|
|
||||||
build_args = ['--preset conan-release']
|
build_args = ['--preset conan-debug' if debug_flag else '--preset conan-release']
|
||||||
if self.compiler.compiler_type != 'msvc':
|
if self.compiler.compiler_type != 'msvc':
|
||||||
if not cmake_generator or cmake_generator == 'Ninja':
|
if not cmake_generator or cmake_generator == 'Ninja':
|
||||||
try:
|
try:
|
||||||
|
@ -80,15 +80,13 @@ class CMakeBuild(build_ext):
|
||||||
if hasattr(self, 'parallel') and self.parallel:
|
if hasattr(self, 'parallel') and self.parallel:
|
||||||
build_args += [f"-j{self.parallel}"]
|
build_args += [f"-j{self.parallel}"]
|
||||||
|
|
||||||
build_temp = Path(self.build_temp) / ext.name
|
|
||||||
if not build_temp.exists():
|
|
||||||
build_temp.mkdir(parents=True)
|
|
||||||
|
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
['cmake', ext.sourcedir, *cmake_args], cwd=build_temp, check=True
|
['cmake', ext.sourcedir, *cmake_args],
|
||||||
|
check=True
|
||||||
)
|
)
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
['cmake', '--build', '.', *build_args], cwd=build_temp, check=True
|
['cmake', '--build', '.', *build_args],
|
||||||
|
check=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user