-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CMake: extract bbasm compilation into a function.
This fully preserves existing functionality, although the `embed` mode is untested and seems broken.
- Loading branch information
1 parent
bfecb52
commit 5382146
Showing
12 changed files
with
201 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,21 @@ | ||
add_subdirectory(${family}) | ||
message(STATUS "Using ECP5 chipdb: ${ECP5_CHIPDB}") | ||
|
||
set(chipdb_sources) | ||
set(chipdb_binaries) | ||
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) | ||
add_library(chipdb-${family} OBJECT) | ||
target_compile_options(chipdb-${family} PRIVATE -w -g0 -O0) | ||
target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) | ||
target_include_directories(chipdb-${family} PRIVATE ${family}) | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,21 @@ | ||
add_subdirectory(${family}) | ||
message(STATUS "Using Gowin chipdb: ${GOWIN_CHIPDB}") | ||
|
||
set(chipdb_sources) | ||
set(chipdb_binaries) | ||
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) | ||
add_library(chipdb-${family} OBJECT) | ||
target_compile_options(chipdb-${family} PRIVATE -w -g0 -O0) | ||
target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) | ||
target_include_directories(chipdb-${family} PRIVATE ${family}) | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,21 @@ | ||
add_subdirectory(${family}) | ||
message(STATUS "Using iCE40 chipdb: ${ICE40_CHIPDB}") | ||
|
||
set(chipdb_sources) | ||
set(chipdb_binaries) | ||
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) | ||
add_library(chipdb-${family} OBJECT) | ||
target_compile_options(chipdb-${family} PRIVATE -w -g0 -O0) | ||
target_compile_definitions(chipdb-${family} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family}) | ||
target_include_directories(chipdb-${family} PRIVATE ${family}) | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.