Add CMake and Conan presets, update build config (#26)

* Add CMake and Conan presets, update build config

Introduces CMakePresets.json and ConanPresets.json for standardized build configuration. Updates Makefile to use CMake presets, modifies .gitignore for IDE files, and refines conanfile.py to support CI option and preset integration.

* Update Makefile

* Update _on-pr.yml

* Refactor build presets and folder layout for Windows

Updated Makefile and GitHub workflow to use configurable build and configure presets, improving flexibility for different environments. Adjusted CMakePresets.json to fix preset naming and version, and refactored conanfile.py to set build folders based on compiler type, ensuring correct folder structure for MSVC and other compilers.

* Update build presets and CPack config for Windows

Set PRESET_CONFIGURE to 'conan-default' for Windows builds in Makefile and GitHub workflow. Broaden CPack packaging conditions to include additional build types and comment out WIX generator settings for Windows in CPackConfig.cmake.
This commit is contained in:
Snider 2025-10-09 00:25:29 +01:00 committed by GitHub
parent 106b3431db
commit ef776a93cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 146 additions and 28 deletions

View file

@ -10,6 +10,7 @@ on:
- opened - opened
- synchronize - synchronize
- reopened - reopened
- ready_for_review
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}

2
.gitignore vendored
View file

@ -10,5 +10,7 @@ Thumbs.db
.idea/dictionaries .idea/dictionaries
.idea/shelf .idea/shelf
.idea/copilot* .idea/copilot*
.idea/modules.xml
.idea/*.iml
.vs/* .vs/*
CMakeUserPresets.json CMakeUserPresets.json

12
.idea/misc.xml generated
View file

@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.13 virtualenv at $PROJECT_DIR$.venv" />
</component>
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CidrRootsConfiguration"> <component name="CidrRootsConfiguration">
<excludeRoots> <excludeRoots>
<file path="$PROJECT_DIR$/build" /> <file path="$PROJECT_DIR$/build" />
@ -9,6 +16,7 @@
<component name="MakefileSettings"> <component name="MakefileSettings">
<option name="linkedExternalProjectsSettings"> <option name="linkedExternalProjectsSettings">
<MakefileProjectSettings> <MakefileProjectSettings>
<option name="buildOptions" value="--jobs=30" />
<option name="buildTarget" value="build" /> <option name="buildTarget" value="build" />
<option name="cleanTarget" value="clean-build" /> <option name="cleanTarget" value="clean-build" />
<option name="externalProjectPath" value="$PROJECT_DIR$" /> <option name="externalProjectPath" value="$PROJECT_DIR$" />
@ -23,8 +31,4 @@
</option> </option>
</component> </component>
<component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" /> <component name="MakefileWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project> </project>

View file

@ -246,7 +246,6 @@ message(STATUS "Using Boost ${Boost_VERSION} from Conan")
find_package(miniupnpc REQUIRED) find_package(miniupnpc REQUIRED)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
find_package(ethash REQUIRED)
find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS}) find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS})
include_directories(src "${CMAKE_BINARY_DIR}/version") include_directories(src "${CMAKE_BINARY_DIR}/version")

97
CMakePresets.json Normal file
View file

@ -0,0 +1,97 @@
{
"version": 8,
"cmakeMinimumRequired": {
"major": 3,
"minor": 23,
"patch": 0
},
"include": [
"ConanPresets.json"
],
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build using Ninja generator",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/default",
"cacheVariables": {
"TESTNET": "ON"
}
},
{
"name": "windows-defaultss",
"displayName": "Windows x64 Debug",
"description": "Sets Ninja generator, compilers, x64 architecture, build and install directory, debug build type",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"architecture": {
"value": "x64",
"strategy": "external"
},
"cacheVariables": {
"TESTNET": "ON",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/build/install/${presetName}"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [ "Windows" ]
}
},
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
}
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
],
"testPresets": [
{
"name": "default",
"configurePreset": "default",
"output": {"outputOnFailure": true},
"execution": {"noTestsAction": "error", "stopOnFailure": true}
}
],
"packagePresets": [
{
"name": "default",
"configurePreset": "default",
"generators": [
"TGZ",
"ZIP"
]
}
],
"workflowPresets": [
{
"name": "default",
"steps": [
{
"type": "configure",
"name": "default"
},
{
"type": "build",
"name": "default"
},
{
"type": "test",
"name": "default"
},
{
"type": "package",
"name": "default"
}
]
}
]
}

8
ConanPresets.json Normal file
View file

@ -0,0 +1,8 @@
{
"version": 4,
"vendor": {
"conan": {}
},
"include": [
]
}

View file

@ -16,10 +16,9 @@ STATIC:= 0
BUILD_TYPE ?=Release BUILD_TYPE ?=Release
BUILD_VERSION:=6.0.1 BUILD_VERSION:=6.0.1
BUILD_FOLDER:=build/release BUILD_FOLDER:=build/release
PRESET_BUILD:=conan-release
PRESET_CONFIGURE:=conan-release
# -----------------------------------------------------------------
# Unixlike systems (Linux, macOS, *BSD, etc.)
# -----------------------------------------------------------------
UNAME_S := $(shell uname -s 2>/dev/null || echo Unknown) UNAME_S := $(shell uname -s 2>/dev/null || echo Unknown)
ifeq ($(UNAME_S),Linux) ifeq ($(UNAME_S),Linux)
@ -38,10 +37,10 @@ ifeq ($(filter %BSD,$(UNAME_S)),%BSD)
CPU_CORES := $(shell sysctl -n hw.ncpu 2>/dev/null || echo 1) CPU_CORES := $(shell sysctl -n hw.ncpu 2>/dev/null || echo 1)
endif endif
# -----------------------------------------------------------------
# Windows (detected by the builtin $(OS) variable set by GNU make)
# -----------------------------------------------------------------
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
PRESET_CONFIGURE:=conan-default
# Prefer the environment variable that Windows sets for us. # Prefer the environment variable that Windows sets for us.
# It works in both cmd.exe and PowerShell. # It works in both cmd.exe and PowerShell.
CPU_CORES := $(NUMBER_OF_PROCESSORS) CPU_CORES := $(NUMBER_OF_PROCESSORS)
@ -77,14 +76,7 @@ release: docs build
@rm -rf $(CURDIR)/build/packages/_CPack_Packages @rm -rf $(CURDIR)/build/packages/_CPack_Packages
build: configure build: configure
cmake --build $(BUILD_FOLDER) --config=$(BUILD_TYPE) --parallel=$(CPU_CORES) cmake --build --preset $(PRESET_BUILD) --parallel=$(CPU_CORES)
debug: conan-profile-detect
@echo "Building profile: debug"
CONAN_HOME=$(CONAN_CACHE) $(CONAN_EXECUTABLE) install . --build=missing -s build_type=Debug
cmake -S . -B $(CURDIR)/build/debug -DCMAKE_TOOLCHAIN_FILE=$(CURDIR)/build/debug/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Debug -DTESTNET=$(TESTNET)
cmake --build $(CURDIR)/build/debug --config=Debug --parallel=$(CPU_CORES)
build-deps: conan-profile-detect build-deps: conan-profile-detect
@echo "Build Dependencies: $(BUILD_TYPE) testnet=$(TESTNET)" @echo "Build Dependencies: $(BUILD_TYPE) testnet=$(TESTNET)"
@ -92,7 +84,7 @@ build-deps: conan-profile-detect
configure: build-deps configure: build-deps
@echo "Running Configure: $(BUILD_TYPE) testnet=$(TESTNET)" @echo "Running Configure: $(BUILD_TYPE) testnet=$(TESTNET)"
cmake -S . -B $(BUILD_FOLDER) -DCMAKE_TOOLCHAIN_FILE=$(BUILD_FOLDER)/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DSTATIC=$(STATIC) -DTESTNET=$(TESTNET) -DBUILD_VERSION=$(BUILD_VERSION) cmake --preset $(PRESET_CONFIGURE) -DSTATIC=$(STATIC) -DTESTNET=$(TESTNET) -DBUILD_VERSION=$(BUILD_VERSION)
docs: configure docs: configure
@echo "Building Documentation" @echo "Building Documentation"
@ -165,4 +157,4 @@ clean-build:
tags: tags:
ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ src contrib tests/gtest ctags -R --sort=1 --c++-kinds=+p --fields=+iaS --extra=+q --language-force=C++ src contrib tests/gtest
.PHONY: all release upload-conan-cache docker-chain-node debug docs docs-dev configure static static-release test test-release test-debug clean tags conan-profile-detect get-conan $(PROFILES) .PHONY: all release upload-conan-cache docs docs-dev configure static static-release test test-release test-debug clean tags conan-profile-detect get-conan $(PROFILES)

View file

@ -1,6 +1,6 @@
if(CMAKE_BUILD_TYPE STREQUAL "Release") if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "")
set(CPACK_PACKAGE_NAME "${package_name}") set(CPACK_PACKAGE_NAME "${package_name}")
set(CPACK_PACKAGE_VENDOR "${package_vendor}") set(CPACK_PACKAGE_VENDOR "${package_vendor}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${package_description}") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${package_description}")
@ -26,8 +26,8 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
# message(STATUS "Registered CPACK_GENERATOR: productbuild") # message(STATUS "Registered CPACK_GENERATOR: productbuild")
endif () endif ()
elseif(WIN32) elseif(WIN32)
# set(CPACK_GENERATOR "WIX") # set(CPACK_GENERATOR "WIX")
# message(STATUS "Registered CPACK_GENERATOR: WIX") # message(STATUS "Registered CPACK_GENERATOR: WIX")
# set(CPACK_WIX_PRODUCT_ICON "${CMAKE_SOURCE_DIR}/resources/windows_icon.ico") # set(CPACK_WIX_PRODUCT_ICON "${CMAKE_SOURCE_DIR}/resources/windows_icon.ico")
# set(CPACK_WIX_LICENSE_RTF "${CMAKE_SOURCE_DIR}/LICENSE.rtf") # set(CPACK_WIX_LICENSE_RTF "${CMAKE_SOURCE_DIR}/LICENSE.rtf")
# set(CPACK_WIX_UPGRADE_GUID "D3F5A9C1-4B2E-4F5A-9C71-123456789ABC") # change once per major version # set(CPACK_WIX_UPGRADE_GUID "D3F5A9C1-4B2E-4F5A-9C71-123456789ABC") # change once per major version

View file

@ -11,11 +11,13 @@ class BlockchainConan(ConanFile):
options = { options = {
"static": [True, False], "static": [True, False],
"testnet": [True, False] "testnet": [True, False],
"ci": [True, False]
} }
default_options = { default_options = {
"static": False, "static": False,
"testnet": False, "testnet": False,
"ci": False,
"boost/*:without_test": True "boost/*:without_test": True
} }
@ -29,7 +31,13 @@ class BlockchainConan(ConanFile):
def generate(self): def generate(self):
tc = CMakeToolchain(self) tc = CMakeToolchain(self)
tc.user_presets_path = False
os_val = str(self.settings.os).lower()
# arch_val = str(self.settings.arch).lower()
# compiler_val = str(self.settings.compiler).lower()
# tc.presets_prefix = f"{os_val}"
tc.user_presets_path = "ConanPresets.json"
tc.variables["STATIC"] = self.options.static tc.variables["STATIC"] = self.options.static
tc.variables["TESTNET"] = self.options.testnet tc.variables["TESTNET"] = self.options.testnet
# tc.preprocessor_definitions["TESTNET"] = None # tc.preprocessor_definitions["TESTNET"] = None
@ -40,8 +48,15 @@ class BlockchainConan(ConanFile):
deps.generate() deps.generate()
def layout(self): def layout(self):
self.folders.generators = os.path.join("build", str(self.settings.build_type).lower(), "generators") if self.settings.compiler == "msvc":
self.folders.build = os.path.join("build", str(self.settings.build_type).lower()) # For multi-config, all configurations go into the same "build" folder.
self.folders.build = "build/release"
self.folders.generators = "build/release/generators"
else:
# For single-config, we create a subfolder for each build type.
build_type_str = str(self.settings.build_type).lower()
self.folders.build = os.path.join("build", build_type_str)
self.folders.generators = os.path.join(self.folders.build, "generators")
def build(self): def build(self):
cmake = CMake(self) cmake = CMake(self)