Skip to content

Commit

Permalink
verilator: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Oct 25, 2023
1 parent 448163e commit ff6abf1
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 174 deletions.
6 changes: 0 additions & 6 deletions recipes/verilator/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ sources:
patches:
"4.038":
- patch_file: "patches/0001-split-opt-and-debug-build-install.patch"
base_path: "source_subfolder"
- patch_file: "patches/0004-msvc-patches.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-add-msvc_link-sh.patch"
base_path: "source_subfolder"
"4.034":
- patch_file: "patches/0001-split-opt-and-debug-build-install.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-msvc-patches.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-add-msvc_link-sh.patch"
base_path: "source_subfolder"
282 changes: 136 additions & 146 deletions recipes/verilator/all/conanfile.py

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions recipes/verilator/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(PackageTest CXX)

include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup(TARGETS)

find_package(verilator REQUIRED)
find_package(verilator REQUIRED CONFIG)

add_executable(blinky
blinky.cpp
Expand All @@ -14,9 +11,10 @@ verilate(blinky SOURCES blinky.v TRACE)
option(BUILD_SYSTEMC "Build SystemC example" ON)

if(BUILD_SYSTEMC)
find_package(SystemCLanguage REQUIRED CONFIG)
add_executable(blinky_sc
blinky_sc.cpp
)
verilate(blinky_sc SOURCES blinky.v SYSTEMC)
target_link_libraries(blinky_sc PRIVATE CONAN_PKG::systemc)
target_link_libraries(blinky_sc PRIVATE SystemC::systemc)
endif()
2 changes: 1 addition & 1 deletion recipes/verilator/all/test_package/blinky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <stdio.h>
#include <stdlib.h>

void tick(int tickcount, Vblinky *tb, VerilatedVcdC* tfp) {
void tick(int tickcount, Vblinky *tb, VerilatedVcdC* tfp) {
tb->eval();
if (tfp)
tfp->dump(tickcount * 10 - 2);
Expand Down
48 changes: 33 additions & 15 deletions recipes/verilator/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
from conans import ConanFile, CMake, tools
import os

from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain

class TestVerilatorConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package"

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def build_requirements(self):
self.tool_requires(self.tested_reference_str)
if self._with_systemc_example:
self.tool_requires("systemc/2.3.4")

def layout(self):
cmake_layout(self)

@property
def _with_systemc_example(self):
# systemc is not available on Macos
return self.settings.os != "Macos"
return not is_apple_os(self)

def requirements(self):
if self._with_systemc_example:
self.requires("systemc/2.3.3")
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SYSTEMC"] = self._with_systemc_example
tc.generate()

def build(self):
if not tools.cross_building(self.settings, skip_x64_x86=True):
if can_run(self):
cmake = CMake(self)
cmake.definitions["BUILD_SYSTEMC"] = self._with_systemc_example
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings, skip_x64_x86=True):
with tools.run_environment(self):
self.run("perl {} --version".format(os.path.join(self.deps_cpp_info["verilator"].rootpath, "bin", "verilator")), run_environment=True)
self.run(os.path.join("bin", "blinky"), run_environment=True)
if can_run(self):
verilator_path = os.path.join(self.dependencies["verilator"].package_folder, "bin", "verilator")
self.run(f"perl {verilator_path} --version")
bin_path = os.path.join(self.cpp.build.bindir, "blinky")
self.run(bin_path, env="conanrun")
if self._with_systemc_example:
self.run(os.path.join("bin", "blinky_sc"), run_environment=True)
bin_path = os.path.join(self.cpp.build.bindir, "blinky_sc")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/verilator/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
31 changes: 31 additions & 0 deletions recipes/verilator/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from conans import ConanFile, CMake, tools
import os


class TestVerilatorConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

@property
def _with_systemc_example(self):
# systemc is not available on Macos
return not is_apple_os(self)

def requirements(self):
if self._with_systemc_example:
self.requires("systemc/2.3.3")

def build(self):
if not tools.cross_building(self.settings, skip_x64_x86=True):
cmake = CMake(self)
cmake.definitions["BUILD_SYSTEMC"] = self._with_systemc_example
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings, skip_x64_x86=True):
with tools.run_environment(self):
self.run("perl {} --version".format(os.path.join(self.deps_cpp_info["verilator"].rootpath, "bin", "verilator")), run_environment=True)
self.run(os.path.join("bin", "blinky"), run_environment=True)
if self._with_systemc_example:
self.run(os.path.join("bin", "blinky_sc"), run_environment=True)

0 comments on commit ff6abf1

Please sign in to comment.