build: modify conanfile cmake layout (#2)

Co-authored-by: light7734 <mail@light7734.com>
Reviewed-on: #2
This commit is contained in:
light7734 2024-08-08 08:37:22 +00:00
parent 8dd81708e4
commit 1b1356c93d
2 changed files with 29 additions and 9 deletions

View File

@ -32,11 +32,10 @@ steps:
- cp ./tools/conan/profiles/linux_clang_amd64 $(conan profile path default)
- conan remote add light https://artifactory.light7734.com/artifactory/api/conan/conan
- conan install . --output-folder=build -r light --build=missing
- conan install . -r light --build=missing
- conan build .
- cmake -Bbuild -DCMAKE_TOOLCHAIN_FILE=./build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
- cmake --build ./build/
- ./build/modules/light/light
- build/Release/modules/light
---
kind: pipeline
@ -73,11 +72,10 @@ steps:
- cp ./tools/conan/profiles/linux_gcc_amd64 $(conan profile path default)
- conan remote add light https://artifactory.light7734.com/artifactory/api/conan/conan
- conan install . --output-folder=build -r light --build=missing
- conan install . -r light --build=missing
- conan build .
- cmake -Bbuild -DCMAKE_TOOLCHAIN_FILE=./build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release
- cmake --build ./build/
- ./build/modules/light/light
- build/Release/modules/light
---
kind: pipeline

View File

@ -1,5 +1,7 @@
from conan import ConanFile
from conan.tools.cmake import CMakeToolchain
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
import shutil
import os
class LightRecipe(ConanFile):
name = "light"
@ -26,6 +28,9 @@ class LightRecipe(ConanFile):
"enable_sanitizers": False,
}
def layout(self):
cmake_layout(self)
def generate(self):
tc = CMakeToolchain(self)
@ -34,3 +39,20 @@ class LightRecipe(ConanFile):
tc.cache_variables["ENABLE_STATIC_ANALYSIS"] = self.options.enable_static_analysis
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
self.copy_compile_commands()
def copy_compile_commands(self):
build_folder = self.build_folder
source_file = os.path.join(build_folder, "compile_commands.json")
destination_file = os.path.join(self.source_folder, "compile_commands.json")
if os.path.isfile(source_file):
shutil.copy(source_file, destination_file)
self.output.info(f"Copied compile_commands.json to {destination_file}")
else:
self.output.warn("compile_commands.json not found!")