From cd4f8a0c9d7a6ed1f805fa07725eeed734c0fe39 Mon Sep 17 00:00:00 2001 From: Catherine Date: Thu, 16 Jan 2025 21:09:33 +0000 Subject: [PATCH] Allow splitting nextpnr-himbaechel per microarchitecture. This is added primarily for YoWASP. --- CMakeLists.txt | 17 +++++++++--- himbaechel/CMakeLists.txt | 56 +++++++++++++++++++++++++++++---------- 2 files changed, 56 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8d2a5ec4dd..f7dd645895 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,7 +249,18 @@ add_subdirectory(rust) add_subdirectory(tests/gui) function(add_nextpnr_architecture target) - cmake_parse_arguments(arg "" "MAIN_SOURCE" "CORE_SOURCES;TEST_SOURCES" ${ARGN}) + cmake_parse_arguments(arg "" "MAIN_SOURCE" "CORE_SOURCES;TEST_SOURCES;CURRENT_SOURCE_DIR;CURRENT_BINARY_DIR" ${ARGN}) + + if (NOT arg_CURRENT_SOURCE_DIR) + set(arg_CURRENT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + if (NOT arg_CURRENT_BINARY_DIR) + set(arg_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) + endif() + + set(arg_MAIN_SOURCE "${arg_CURRENT_SOURCE_DIR}/${arg_MAIN_SOURCE}") + list(TRANSFORM arg_CORE_SOURCES PREPEND ${arg_CURRENT_SOURCE_DIR}/) + list(TRANSFORM arg_TEST_SOURCES PREPEND ${arg_CURRENT_SOURCE_DIR}/) # Defs library: used by everything # @@ -259,7 +270,7 @@ function(add_nextpnr_architecture target) target_include_directories(nextpnr-${target}-defs INTERFACE ${CMAKE_SOURCE_DIR}/common/kernel - ${CMAKE_CURRENT_SOURCE_DIR} + ${arg_CURRENT_SOURCE_DIR} ) string(TOUPPER ${family} family_upper) @@ -301,7 +312,7 @@ function(add_nextpnr_architecture target) endif() if (BUILD_GUI) - add_subdirectory(${CMAKE_SOURCE_DIR}/gui ${CMAKE_CURRENT_BINARY_DIR}/gui) + add_subdirectory(${CMAKE_SOURCE_DIR}/gui ${arg_CURRENT_BINARY_DIR}/gui) # Upsettingly, there is a cyclic dependency between `common/kernel` and `gui`, so these # two libraries have to be added separately to all executable targets. diff --git a/himbaechel/CMakeLists.txt b/himbaechel/CMakeLists.txt index 2f9aad251f..947b51b6fc 100644 --- a/himbaechel/CMakeLists.txt +++ b/himbaechel/CMakeLists.txt @@ -1,4 +1,6 @@ -set(SOURCES +option(HIMBAECHEL_SPLIT "Whether to build one executable per Himbächel microarchitecture" OFF) + +set(HIMBAECHEL_SOURCES arch.cc archdefs.h arch.h @@ -13,24 +15,50 @@ set(SOURCES himbaechel_helpers.h ) -add_nextpnr_architecture(${family} - CORE_SOURCES ${SOURCES} - MAIN_SOURCE main.cc -) +if (HIMBAECHEL_SPLIT) -function(add_nextpnr_himbaechel_microarchitecture microtarget) - cmake_parse_arguments(arg "" "" "CORE_SOURCES;TEST_SOURCES" ${ARGN}) + function(add_nextpnr_himbaechel_microarchitecture microtarget) + cmake_parse_arguments(arg "" "" "CORE_SOURCES;TEST_SOURCES" ${ARGN}) - target_sources(nextpnr-himbaechel-core INTERFACE ${arg_CORE_SOURCES}) + list(TRANSFORM arg_CORE_SOURCES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/) + list(TRANSFORM arg_TEST_SOURCES PREPEND ${CMAKE_CURRENT_SOURCE_DIR}/) - add_library(nextpnr-himbaechel-${microtarget}-chipdb INTERFACE) + add_nextpnr_architecture(himbaechel-${microtarget} + CORE_SOURCES ${HIMBAECHEL_SOURCES} + MAIN_SOURCE main.cc + CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/himbaechel + CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR} + ) - target_link_libraries(nextpnr-himbaechel-core INTERFACE nextpnr-himbaechel-${microtarget}-chipdb) + target_sources(nextpnr-himbaechel-${microtarget}-core INTERFACE ${arg_CORE_SOURCES}) - if (BUILD_TESTS) - target_sources(nextpnr-himbaechel-test PRIVATE ${arg_TEST_SOURCES}) - endif() -endfunction() + if (BUILD_TESTS) + target_sources(nextpnr-himbaechel-${microtarget}-test PRIVATE ${arg_TEST_SOURCES}) + endif() + endfunction() + +else() + + add_nextpnr_architecture(himbaechel + CORE_SOURCES ${HIMBAECHEL_SOURCES} + MAIN_SOURCE main.cc + ) + + function(add_nextpnr_himbaechel_microarchitecture microtarget) + cmake_parse_arguments(arg "" "" "CORE_SOURCES;TEST_SOURCES" ${ARGN}) + + target_sources(nextpnr-himbaechel-core INTERFACE ${arg_CORE_SOURCES}) + + add_library(nextpnr-himbaechel-${microtarget}-chipdb INTERFACE) + + target_link_libraries(nextpnr-himbaechel-core INTERFACE nextpnr-himbaechel-${microtarget}-chipdb) + + if (BUILD_TESTS) + target_sources(nextpnr-himbaechel-test PRIVATE ${arg_TEST_SOURCES}) + endif() + endfunction() + +endif() set(HIMBAECHEL_UARCHES example gowin xilinx ng-ultra)