Skip to content

Commit

Permalink
add problem description
Browse files Browse the repository at this point in the history
  • Loading branch information
ibis-hdl committed Nov 22, 2024
1 parent 3acae24 commit 36be107
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .vscode/.dictionaries/project_words.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
ccache
cmaketoolchain
conanfile
devcontainers
gnuc
libc
libcpp
msvc
ptrace
pwsh
sccache
105 changes: 105 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,107 @@
# conan-issue
Repository to handle with cmake and conan

Prerequisite:
- Ubuntu 24.04
```
$ cat ~/.conan2/profiles/clang
[settings]
arch=x86_64
build_type=Release
compiler=clang
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=18
os=Linux
[buildenv]
CC=clang
CXX=clang++
[conf]
tools.build:compiler_executables={ "c": "/usr/bin/clang", "cpp": "/usr/bin/clang++" }
```

Changes in `conanfile.py`
```python
def layout(self):
# see: conan.io #17324
self.folders.build_folder_vars = ["settings.compiler", "settings.build_type"]

```
Changes in `CMakePresets.json` (concrete `cmake/common.json`)
```
"configurePresets": [
...
{
"name": "ninja-default-settings",
"description": "Common settings related to build tool Ninja.",
"hidden": true,
"binaryDir": "${sourceDir}/build/${buildPresets}",
...
},
```

try to build:
```
$ ./conan_install.py --profile clang
conan install . --settings build_type=Release --conf tools.cmake.cmaketoolchain:generator='Ninja Multi-Config' --build=missing --output-folder=. --profile:all=clang
...
conan install . --settings build_type=Release --conf tools.cmake.cmaketoolchain:generator='Ninja Multi-Config' --build=missing --output-folder=. --profile:all=clang
...
...
$ cmake --list-presets
CMake Error: Could not read presets from /workspaces/conan-issue:
Invalid preset: "clang"
```
which results to:
```
$ cat build/clang-debug/generators/CMakePresets.json
...
"configurePresets": [
{
"name": "conan-clang-debug",
...
}
],
"buildPresets": [
{
"name": "conan-clang-debug",
"configurePreset": "conan-clang-debug",
"configuration": "Debug"
}
],
...
```
but in `CMakePresets.json` there are (e.g. for gcc, msvc)
```
"configurePresets": [
{
"name": "gcc",
...
"inherits": [
...
"conan-default",
...
]
},
...
{
"name": "msvc",
"inherits": [
...
"conan-default",
...
]
},
```
where the inherited `"conan-default"` (or even other settings) aren't here - how to cope with it?
The error message below is misleading and results only from missing inheritance name
```
$ cmake --list-presets
CMake Error: Could not read presets from /workspaces/conan-issue:
Invalid preset: "clang"
```
and how to write it now for `"conan-clang-debug"` and `"conan-clang-release"`?

The same problem rises with Ninja's single target I mentioned at [#17324](https://github.com/conan-io/conan/issues/17324).
2 changes: 1 addition & 1 deletion cmake/presets/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"name": "ninja-default-settings",
"description": "Common settings related to build tool Ninja.",
"hidden": true,
"binaryDir": "${sourceDir}/build/",
"binaryDir": "${sourceDir}/build/${buildPresets}",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true
},
Expand Down
8 changes: 5 additions & 3 deletions conan_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import platform
import argparse
import pathlib
from pathlib import Path
from multipledispatch import dispatch

class ConanInstaller:
Expand Down Expand Up @@ -40,6 +40,7 @@ def __init__(self):
self.conan_profile = arg.profile
else:
self.conan_profile = 'default'

print(f"using conan profile '{self.conan_profile}'")

"""
Expand All @@ -52,10 +53,10 @@ def __init__(self):
@see `conanfile.py` at generate().
"""
def removeConanPresetsJson(self, file_name: str):
file_path = pathlib.Path(file_name)
file_path = Path(file_name)
if file_path.exists():
print(f"remove former generated Conan CMake preset '{file_name}'")
pathlib.Path(file_name).unlink(missing_ok=True)
Path(file_name).unlink(missing_ok=True)

@dispatch(str, str)
def install(self, build_type: str, conan_profile: str) -> None:
Expand All @@ -69,6 +70,7 @@ def install(self, build_type: str, conan_profile: str) -> None:
f"--settings build_type={build_type}",
f"--conf tools.cmake.cmaketoolchain:generator={self.generator}",
f"--build=missing",
f"--output-folder=.",
f"--profile:all={conan_profile}"
]
cmd_line = f"conan install . " + f' '.join(cmd_args)
Expand Down
4 changes: 2 additions & 2 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def requirements(self):
self.requires("catch2/3.7.1")

def layout(self):
# see: conan.io #17324
#self.folders.build_folder_vars = ["settings.compiler", "settings.build_type"]
# see: conan.io #17324; must match "${buildPresets}" (cmake/presets/common.json)
self.folders.build_folder_vars = ["settings.compiler", "settings.build_type"]
cmake_layout(self)

def generate(self):
Expand Down

0 comments on commit 36be107

Please sign in to comment.