CMake: extract bbasm compilation into a function.

This fully preserves existing functionality, although the `embed` mode
is untested and seems broken.
This commit is contained in:
Catherine 2025-01-15 12:57:00 +00:00
parent 43b2f38520
commit a951faa16d
12 changed files with 201 additions and 241 deletions

124
BBAsm.cmake Normal file
View File

@ -0,0 +1,124 @@
include(TestBigEndian)
test_big_endian(IS_BIG_ENDIAN)
if (IS_BIG_ENDIAN)
set(BBASM_ENDIAN_FLAG "--be")
else()
set(BBASM_ENDIAN_FLAG "--le")
endif()
# Example usage:
#
# add_bba_compile_command(
# TARGET chipdb-ice40
# OUTPUT ice40/chipdb-hx8k.bin
# INPUT ice40/chipdb-hx8k.bba
# MODE binary
# )
#
# All paths are relative to ${CMAKE_BINARY_DIR} (sic!).
#
function(add_bba_compile_command)
cmake_parse_arguments(arg "" "DEPENDS;TARGET;OUTPUT;INPUT;MODE" "" ${ARGN})
cmake_path(ABSOLUTE_PATH arg_INPUT BASE_DIRECTORY ${CMAKE_BINARY_DIR})
if (NOT arg_DEPENDS)
set(arg_DEPENDS ${arg_INPUT})
endif()
if (arg_MODE STREQUAL "binary" OR arg_MODE STREQUAL "resource")
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/${arg_OUTPUT}
COMMAND
bbasm ${BBASM_ENDIAN_FLAG}
${arg_INPUT}
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.new
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.new
${CMAKE_BINARY_DIR}/${arg_OUTPUT}
DEPENDS
bbasm
${arg_DEPENDS}
VERBATIM
)
if (arg_MODE STREQUAL "resource")
file(WRITE ${CMAKE_BINARY_DIR}/${arg_OUTPUT}.rc
"${arg_OUTPUT} RCDATA \"${CMAKE_BINARY_DIR}/${arg_OUTPUT}\"")
target_sources(
${arg_TARGET} PRIVATE
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.rc
)
else()
target_sources(
${arg_TARGET} PRIVATE
${CMAKE_BINARY_DIR}/${arg_OUTPUT}
)
endif()
elseif (arg_MODE STREQUAL "embed")
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc
${CMAKE_BINARY_DIR}/${arg_OUTPUT}
COMMAND
bbasm ${BBASM_ENDIAN_FLAG} --e
${arg_INPUT}
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc.new
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.new
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc.new
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.new
${CMAKE_BINARY_DIR}/${arg_OUTPUT}
DEPENDS
bbasm
${arg_DEPENDS}
VERBATIM
)
target_sources(
${arg_TARGET} PRIVATE
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc
)
elseif (arg_MODE STREQUAL "string")
add_custom_command(
OUTPUT
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc
COMMAND
bbasm ${BBASM_ENDIAN_FLAG} --c
${arg_INPUT}
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc.new
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc.new
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc
DEPENDS
bbasm
${arg_DEPENDS}
VERBATIM
)
target_sources(
${arg_TARGET} PRIVATE
${CMAKE_BINARY_DIR}/${arg_OUTPUT}.cc
)
endif()
endfunction()

View File

@ -52,7 +52,9 @@ else()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE) set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
endif() endif()
if (WIN32 OR EXTERNAL_CHIPDB) if (WIN32)
set(BBASM_MODE "resource")
elseif (EXTERNAL_CHIPDB)
set(BBASM_MODE "binary") set(BBASM_MODE "binary")
else() else()
set(BBASM_MODE "string") set(BBASM_MODE "string")
@ -204,7 +206,7 @@ add_subdirectory(3rdparty/json11)
add_subdirectory(3rdparty/oourafft) add_subdirectory(3rdparty/oourafft)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rdparty/sanitizers-cmake/cmake;." ${CMAKE_MODULE_PATH}) set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rdparty/sanitizers-cmake/cmake;${CMAKE_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
find_package(Sanitizers) find_package(Sanitizers)
if (COVERAGE) if (COVERAGE)
@ -224,13 +226,7 @@ else()
add_subdirectory(bba) add_subdirectory(bba)
endif() endif()
include(TestBigEndian) include(BBAsm)
test_big_endian(IS_BIG_ENDIAN)
if (IS_BIG_ENDIAN)
set(BBASM_ENDIAN_FLAG "--be")
else()
set(BBASM_ENDIAN_FLAG "--le")
endif()
if (NOT DEFINED CURRENT_GIT_VERSION) if (NOT DEFINED CURRENT_GIT_VERSION)
# Get the latest abbreviated commit hash of the working branch # Get the latest abbreviated commit hash of the working branch

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.25)
project(chipdb-ecp5 NONE) project(chipdb-ecp5 NONE)
set(ALL_ECP5_DEVICES 25k 45k 85k) set(ALL_ECP5_DEVICES 25k 45k 85k)

View File

@ -1,53 +1,21 @@
add_subdirectory(${family}) add_subdirectory(${family})
message(STATUS "Using ECP5 chipdb: ${ECP5_CHIPDB}") message(STATUS "Using ECP5 chipdb: ${ECP5_CHIPDB}")
set(chipdb_sources) add_library(chipdb-${family} OBJECT)
set(chipdb_binaries) target_compile_options(chipdb-${family} PRIVATE -w -g0 -O0)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb)
foreach (device ${ECP5_DEVICES})
set(chipdb_bba ${ECP5_CHIPDB}/chipdb-${device}.bba)
set(chipdb_bin ${family}/chipdb/chipdb-${device}.bin)
set(chipdb_cc ${family}/chipdb/chipdb-${device}.cc)
if (BBASM_MODE STREQUAL "binary")
add_custom_command(
OUTPUT ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${chipdb_bba} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "embed")
add_custom_command(
OUTPUT ${chipdb_cc} ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --e ${chipdb_bba} ${chipdb_cc} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "string")
add_custom_command(
OUTPUT ${chipdb_cc}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --c ${chipdb_bba} ${chipdb_cc}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
endif()
endforeach()
if (WIN32)
set(chipdb_rc ${CMAKE_CURRENT_BINARY_DIR}/${family}/resource/chipdb.rc)
list(APPEND chipdb_sources ${chipdb_rc})
file(WRITE ${chipdb_rc})
foreach (device ${ECP5_DEVICES})
file(APPEND ${chipdb_rc}
"${family}/chipdb-${device}.bin RCDATA \"${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb/chipdb-${device}.bin\"")
endforeach()
endif()
add_custom_target(chipdb-${family}-bins DEPENDS ${chipdb_sources} ${chipdb_binaries})
add_library(chipdb-${family} OBJECT ${ECP5_CHIPDB} ${chipdb_sources})
add_dependencies(chipdb-${family} chipdb-${family}-bins)
target_compile_options(chipdb-${family} PRIVATE -g0 -O0 -w)
target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family})
target_include_directories(chipdb-${family} PRIVATE ${family}) target_include_directories(chipdb-${family} PRIVATE ${family})
foreach (family_target ${family_targets}) foreach (family_target ${family_targets})
target_sources(${family_target} PRIVATE $<TARGET_OBJECTS:chipdb-${family}>) target_link_libraries(${family_target} PRIVATE chipdb-${family})
endforeach()
foreach (device ${ECP5_DEVICES})
add_bba_compile_command(
DEPENDS chipdb-${family}-bbas
TARGET chipdb-${family}
OUTPUT ${family}/chipdb-${device}.bin
INPUT ${ECP5_CHIPDB}/chipdb-${device}.bba
MODE ${BBASM_MODE}
)
endforeach() endforeach()

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.25)
project(chipdb-gowin NONE) project(chipdb-gowin NONE)
set(ALL_GOWIN_DEVICES GW1N-1 GW1NZ-1 GW1N-4 GW1N-9 GW1N-9C GW1NS-2 GW1NS-4 GW2A-18) set(ALL_GOWIN_DEVICES GW1N-1 GW1NZ-1 GW1N-4 GW1N-9 GW1N-9C GW1NS-2 GW1NS-4 GW2A-18)

View File

@ -1,53 +1,21 @@
add_subdirectory(${family}) add_subdirectory(${family})
message(STATUS "Using Gowin chipdb: ${GOWIN_CHIPDB}") message(STATUS "Using Gowin chipdb: ${GOWIN_CHIPDB}")
set(chipdb_sources) add_library(chipdb-${family} OBJECT)
set(chipdb_binaries) target_compile_options(chipdb-${family} PRIVATE -w -g0 -O0)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb)
foreach (device ${GOWIN_DEVICES})
set(chipdb_bba ${GOWIN_CHIPDB}/chipdb-${device}.bba)
set(chipdb_bin ${family}/chipdb/chipdb-${device}.bin)
set(chipdb_cc ${family}/chipdb/chipdb-${device}.cc)
if (BBASM_MODE STREQUAL "binary")
add_custom_command(
OUTPUT ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${chipdb_bba} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "embed")
add_custom_command(
OUTPUT ${chipdb_cc} ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --e ${chipdb_bba} ${chipdb_cc} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "string")
add_custom_command(
OUTPUT ${chipdb_cc}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --c ${chipdb_bba} ${chipdb_cc}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
endif()
endforeach()
if (WIN32)
set(chipdb_rc ${CMAKE_CURRENT_BINARY_DIR}/${family}/resource/chipdb.rc)
list(APPEND chipdb_sources ${chipdb_rc})
file(WRITE ${chipdb_rc})
foreach (device ${GOWIN_DEVICES})
file(APPEND ${chipdb_rc}
"${family}/chipdb-${device}.bin RCDATA \"${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb/chipdb-${device}.bin\"")
endforeach()
endif()
add_custom_target(chipdb-${family}-bins DEPENDS ${chipdb_sources} ${chipdb_binaries})
add_library(chipdb-${family} OBJECT ${GOWIN_CHIPDB} ${chipdb_sources})
add_dependencies(chipdb-${family} chipdb-${family}-bins)
target_compile_options(chipdb-${family} PRIVATE -g0 -O0 -w)
target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family})
target_include_directories(chipdb-${family} PRIVATE ${family}) target_include_directories(chipdb-${family} PRIVATE ${family})
foreach (family_target ${family_targets}) foreach (family_target ${family_targets})
target_sources(${family_target} PRIVATE $<TARGET_OBJECTS:chipdb-${family}>) target_link_libraries(${family_target} PRIVATE chipdb-${family})
endforeach()
foreach (device ${GOWIN_DEVICES})
add_bba_compile_command(
DEPENDS chipdb-${family}-bbas
TARGET chipdb-${family}
OUTPUT ${family}/chipdb-${device}.bin
INPUT ${GOWIN_CHIPDB}/chipdb-${device}.bba
MODE ${BBASM_MODE}
)
endforeach() endforeach()

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.25)
project(chipdb-ice40 NONE) project(chipdb-ice40 NONE)
set(ALL_ICE40_DEVICES 384 1k 5k u4k 8k) set(ALL_ICE40_DEVICES 384 1k 5k u4k 8k)

View File

@ -1,53 +1,21 @@
add_subdirectory(${family}) add_subdirectory(${family})
message(STATUS "Using iCE40 chipdb: ${ICE40_CHIPDB}") message(STATUS "Using iCE40 chipdb: ${ICE40_CHIPDB}")
set(chipdb_sources) add_library(chipdb-${family} OBJECT)
set(chipdb_binaries) target_compile_options(chipdb-${family} PRIVATE -w -g0 -O0)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb)
foreach (device ${ICE40_DEVICES})
set(chipdb_bba ${ICE40_CHIPDB}/chipdb-${device}.bba)
set(chipdb_bin ${family}/chipdb/chipdb-${device}.bin)
set(chipdb_cc ${family}/chipdb/chipdb-${device}.cc)
if (BBASM_MODE STREQUAL "binary")
add_custom_command(
OUTPUT ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${chipdb_bba} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "embed")
add_custom_command(
OUTPUT ${chipdb_cc} ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --e ${chipdb_bba} ${chipdb_cc} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "string")
add_custom_command(
OUTPUT ${chipdb_cc}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --c ${chipdb_bba} ${chipdb_cc}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
endif()
endforeach()
if (WIN32)
set(chipdb_rc ${CMAKE_CURRENT_BINARY_DIR}/${family}/resource/chipdb.rc)
list(APPEND chipdb_sources ${chipdb_rc})
file(WRITE ${chipdb_rc})
foreach (device ${ICE40_DEVICES})
file(APPEND ${chipdb_rc}
"${family}/chipdb-${device}.bin RCDATA \"${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb/chipdb-${device}.bin\"")
endforeach()
endif()
add_custom_target(chipdb-${family}-bins DEPENDS ${chipdb_sources} ${chipdb_binaries})
add_library(chipdb-${family} OBJECT ${ICE40_CHIPDB} ${chipdb_sources})
add_dependencies(chipdb-${family} chipdb-${family}-bins)
target_compile_options(chipdb-${family} PRIVATE -g0 -O0 -w)
target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family})
target_include_directories(chipdb-${family} PRIVATE ${family}) target_include_directories(chipdb-${family} PRIVATE ${family})
foreach (family_target ${family_targets}) foreach (family_target ${family_targets})
target_sources(${family_target} PRIVATE $<TARGET_OBJECTS:chipdb-${family}>) target_link_libraries(${family_target} PRIVATE chipdb-${family})
endforeach()
foreach (device ${ICE40_DEVICES})
add_bba_compile_command(
DEPENDS chipdb-${family}-bbas
TARGET chipdb-${family}
OUTPUT ${family}/chipdb-${device}.bin
INPUT ${ICE40_CHIPDB}/chipdb-${device}.bba
MODE ${BBASM_MODE}
)
endforeach() endforeach()

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.25)
project(chipdb-machxo2 NONE) project(chipdb-machxo2 NONE)
set(ALL_MACHXO2_DEVICES 256X 640X 1200X 2280X 256 640 1200 2000 4000 7000 1300 2100 4300 6900 9400 4300D 9400D) set(ALL_MACHXO2_DEVICES 256X 640X 1200X 2280X 256 640 1200 2000 4000 7000 1300 2100 4300 6900 9400 4300D 9400D)
@ -109,6 +109,6 @@ else()
# serialize chipdb build across multiple architectures # serialize chipdb build across multiple architectures
set(PREVIOUS_CHIPDB_TARGET chipdb-machxo2-bbas PARENT_SCOPE) set(PREVIOUS_CHIPDB_TARGET chipdb-machxo2-bbas PARENT_SCOPE)
else() else()
message(STATUS "Build nextpnr with -DMACHXO2_CHIPDB=${CMAKE_CURRENT_BINARY_DIR}") message(STATUS "Build nextpnr with -DMACHXO2_CHIPDB=${CMAKE_CURRENT_BINARY_DIR}/chipdb")
endif() endif()
endif() endif()

View File

@ -1,56 +1,24 @@
add_subdirectory(${family}) add_subdirectory(${family})
message(STATUS "Using MachXO2/XO3 chipdb: ${MACHXO2_CHIPDB}") message(STATUS "Using MachXO2/XO3 chipdb: ${MACHXO2_CHIPDB}")
set(chipdb_sources) add_library(chipdb-${family} OBJECT)
set(chipdb_binaries) target_compile_options(chipdb-${family} PRIVATE -w -g0 -O0)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb)
foreach (device ${MACHXO2_DEVICES})
set(chipdb_bba ${MACHXO2_CHIPDB}/chipdb-${device}.bba)
set(chipdb_bin ${family}/chipdb/chipdb-${device}.bin)
set(chipdb_cc ${family}/chipdb/chipdb-${device}.cc)
if (BBASM_MODE STREQUAL "binary")
add_custom_command(
OUTPUT ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${chipdb_bba} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "embed")
add_custom_command(
OUTPUT ${chipdb_cc} ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --e ${chipdb_bba} ${chipdb_cc} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "string")
add_custom_command(
OUTPUT ${chipdb_cc}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --c ${chipdb_bba} ${chipdb_cc}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
endif()
endforeach()
if (WIN32)
set(chipdb_rc ${CMAKE_CURRENT_BINARY_DIR}/${family}/resource/chipdb.rc)
list(APPEND chipdb_sources ${chipdb_rc})
file(WRITE ${chipdb_rc})
foreach (device ${MACHXO2_DEVICES})
file(APPEND ${chipdb_rc}
"${family}/chipdb-${device}.bin RCDATA \"${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb/chipdb-${device}.bin\"")
endforeach()
endif()
add_custom_target(chipdb-${family}-bins DEPENDS ${chipdb_sources} ${chipdb_binaries})
add_library(chipdb-${family} OBJECT ${MACHXO2_CHIPDB} ${chipdb_sources})
add_dependencies(chipdb-${family} chipdb-${family}-bins)
target_compile_options(chipdb-${family} PRIVATE -g0 -O0 -w)
target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family})
target_include_directories(chipdb-${family} PRIVATE ${family}) target_include_directories(chipdb-${family} PRIVATE ${family})
configure_file(${family}/machxo2_available.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/machxo2_available.h) configure_file(${family}/machxo2_available.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/machxo2_available.h)
target_sources(chipdb-${family} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated/machxo2_available.h)
foreach (family_target ${family_targets}) foreach (family_target ${family_targets})
target_sources(${family_target} PRIVATE $<TARGET_OBJECTS:chipdb-${family}>) target_link_libraries(${family_target} PRIVATE chipdb-${family})
target_sources(${family_target} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/generated/machxo2_available.h) endforeach()
foreach (device ${MACHXO2_DEVICES})
add_bba_compile_command(
DEPENDS chipdb-${family}-bbas
TARGET chipdb-${family}
OUTPUT ${family}/chipdb-${device}.bin
INPUT ${MACHXO2_CHIPDB}/chipdb-${device}.bba
MODE ${BBASM_MODE}
)
endforeach() endforeach()

View File

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5) cmake_minimum_required(VERSION 3.25)
project(chipdb-nexus NONE) project(chipdb-nexus NONE)
set(ALL_NEXUS_FAMILIES LIFCL) set(ALL_NEXUS_FAMILIES LIFCL)

View File

@ -1,53 +1,21 @@
add_subdirectory(${family}) add_subdirectory(${family})
message(STATUS "Using Nexus chipdb: ${NEXUS_CHIPDB}") message(STATUS "Using Nexus chipdb: ${NEXUS_CHIPDB}")
set(chipdb_sources) add_library(chipdb-${family} OBJECT)
set(chipdb_binaries) target_compile_options(chipdb-${family} PRIVATE -w -g0 -O0)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb)
foreach (subfamily ${NEXUS_FAMILIES})
set(chipdb_bba ${NEXUS_CHIPDB}/chipdb-${subfamily}.bba)
set(chipdb_bin ${family}/chipdb/chipdb-${subfamily}.bin)
set(chipdb_cc ${family}/chipdb/chipdb-${subfamily}.cc)
if (BBASM_MODE STREQUAL "binary")
add_custom_command(
OUTPUT ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} ${chipdb_bba} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "embed")
add_custom_command(
OUTPUT ${chipdb_cc} ${chipdb_bin}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --e ${chipdb_bba} ${chipdb_cc} ${chipdb_bin}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
list(APPEND chipdb_binaries ${chipdb_bin})
elseif (BBASM_MODE STREQUAL "string")
add_custom_command(
OUTPUT ${chipdb_cc}
COMMAND bbasm ${BBASM_ENDIAN_FLAG} --c ${chipdb_bba} ${chipdb_cc}
DEPENDS bbasm chipdb-${family}-bbas ${chipdb_bba})
list(APPEND chipdb_sources ${chipdb_cc})
endif()
endforeach()
if (WIN32)
set(chipdb_rc ${CMAKE_CURRENT_BINARY_DIR}/${family}/resource/chipdb.rc)
list(APPEND chipdb_sources ${chipdb_rc})
file(WRITE ${chipdb_rc})
foreach (subfamily ${NEXUS_FAMILIES})
file(APPEND ${chipdb_rc}
"${family}/chipdb-${subfamily}.bin RCDATA \"${CMAKE_CURRENT_BINARY_DIR}/${family}/chipdb/chipdb-${subfamily}.bin\"")
endforeach()
endif()
add_custom_target(chipdb-${family}-bins DEPENDS ${chipdb_sources} ${chipdb_binaries})
add_library(chipdb-${family} OBJECT ${NEXUS_CHIPDB} ${chipdb_sources})
add_dependencies(chipdb-${family} chipdb-${family}-bins)
target_compile_options(chipdb-${family} PRIVATE -g0 -O0 -w)
target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family})
target_include_directories(chipdb-${family} PRIVATE ${family}) target_include_directories(chipdb-${family} PRIVATE ${family})
foreach (family_target ${family_targets}) foreach (family_target ${family_targets})
target_sources(${family_target} PRIVATE $<TARGET_OBJECTS:chipdb-${family}>) target_link_libraries(${family_target} PRIVATE chipdb-${family})
endforeach()
foreach (subfamily ${NEXUS_FAMILIES})
add_bba_compile_command(
DEPENDS chipdb-${family}-bbas
TARGET chipdb-${family}
OUTPUT ${family}/chipdb-${subfamily}.bin
INPUT ${NEXUS_CHIPDB}/chipdb-${subfamily}.bba
MODE ${BBASM_MODE}
)
endforeach() endforeach()