Skip to content

Commit

Permalink
CMake: eliminate family.cmake/CMakeLists.txt split.
Browse files Browse the repository at this point in the history
While it served a purpose (granting the ability to build `.bba` files
separately from the rest of nextpnr), it made things excessively
convoluted, especially around paths.

This commit removes the ability to pre-generate chip databases. As far
as I know, I was the primary user of that feature. It can be added back
if there is demand for it.

In exchange the per-family `CMakeLists.txt` files are now much easier
to understand.
  • Loading branch information
whitequark committed Jan 15, 2025
1 parent 5382146 commit 3844c2a
Show file tree
Hide file tree
Showing 22 changed files with 474 additions and 649 deletions.
124 changes: 0 additions & 124 deletions BBAsm.cmake

This file was deleted.

10 changes: 8 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.25)
project(nextpnr CXX)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})

include(CheckCXXCompilerFlag)

if (NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
Expand All @@ -22,6 +24,7 @@ option(USE_OPENMP "Use OpenMP to accelerate analytic placer" OFF)
option(COVERAGE "Add code coverage info" OFF)
option(STATIC_BUILD "Create static build" OFF)
option(EXTERNAL_CHIPDB "Create build with pre-built chipdb binaries" OFF)
option(SERIALIZE_CHIPDBS "Serialize device data preprocessing to minimize memory use" ON)
option(WERROR "pass -Werror to compiler (used for CI)" OFF)
option(PROFILER "Link against libprofiler" OFF)
option(USE_IPO "Compile nextpnr with IPO" ON)
Expand Down Expand Up @@ -60,6 +63,8 @@ else()
set(BBASM_MODE "string")
endif()

set(BBASM_SERIALIZE ${SERIALIZE_CHIPDBS})

find_package(Threads)
if (Threads_FOUND)
find_package(TBB QUIET)
Expand Down Expand Up @@ -206,7 +211,7 @@ add_subdirectory(3rdparty/json11)

add_subdirectory(3rdparty/oourafft)

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rdparty/sanitizers-cmake/cmake;${CMAKE_SOURCE_DIR}" ${CMAKE_MODULE_PATH})
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rdparty/sanitizers-cmake/cmake" ${CMAKE_MODULE_PATH})
find_package(Sanitizers)

if (COVERAGE)
Expand Down Expand Up @@ -326,7 +331,8 @@ foreach (family ${ARCH})
endif()

# Include the family-specific CMakeFile
include(${family}/family.cmake)
add_subdirectory(${family})
# include(${family}/family.cmake)
foreach (target ${family_targets})
foreach (lib_dep ${EXTRA_LIB_DEPS})
target_link_libraries(${target} PRIVATE ${lib_dep})
Expand Down
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ sudo make install

The nextpnr GUI is not built by default, to reduce the number of dependencies for a standard headless build. To enable it, add `-DBUILD_GUI=ON` to the CMake command line and ensure that Qt5 and OpenGL are available:

- On Ubuntu 22.04 LTS, install `qtcreator qtbase5-dev qt5-qmake`
- On Ubuntu 22.04 LTS, install `qtcreator qtbase5-dev qt5-qmake`
- On other Ubuntu versions, install `qt5-default`
- For MSVC vcpkg, install `qt5-base` (32-bit) or `qt5-base:x64-windows` (64-bit)
- For Homebrew, install `qt5` and add qt5 in path: `echo 'export PATH="/usr/local/opt/qt/bin:$PATH"' >> ~/.bash_profile`
Expand All @@ -181,19 +181,6 @@ sudo make install

To build every available stable architecture, use `-DARCH=all`. To include experimental arches (currently nexus), use `-DARCH=all+alpha`.

Pre-generating chip databases
-----------------------------

It is possible to pre-generate chip databases (`.bba` files). This can come in handy when building on time-constrained cloud instances, or in situations where Python is unable to use modules. To do this, build the architecture as a standalone project, which will produce the chip database alone. For example, for iCE40:

```
cd ice40
cmake .
make
```

This will create a `chipdb` directory with `.bba` files. Provide the path to this directory when building nextpnr by using `-D<arch>_CHIPDB=/path/to/chipdb`.

Cross-compilation
-----------------

Expand Down
164 changes: 164 additions & 0 deletions cmake/BBAsm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
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 (note the `.new`, used for atomic updates):
#
# add_bba_produce_command(
# COMMAND ${Python_EXECUTABLE}
# ${CMAKE_CURRENT_SOURCE_DIR}/chipdb.py
# -o ${CMAKE_CURRENT_BINARY_DIR}/chipdb-hx8k.bba.new
# OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/chipdb-hx8k.bba
# INPUTS ${CMAKE_CURRENT_SOURCE_DIR}/chipdb.py
# )
#
# Paths must be absolute.
#
function(add_bba_produce_command)
cmake_parse_arguments(arg "" "OUTPUT" "COMMAND;INPUTS" ${ARGN})

cmake_path(GET arg_OUTPUT PARENT_PATH arg_OUTPUT_DIR)
file(MAKE_DIRECTORY ${arg_OUTPUT_DIR})

list(GET arg_COMMAND 0 arg_EXECUTABLE)

add_custom_command(
OUTPUT
${arg_OUTPUT}
COMMAND
${arg_COMMAND}
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${arg_OUTPUT}.new
${arg_OUTPUT}
DEPENDS
${arg_EXECUTABLE}
${arg_INPUTS}
$ENV{SERIALIZE_BBA_PRODUCE_COMMAND}
VERBATIM
)

if (BBASM_SERIALIZE)
set(ENV{SERIALIZE_BBA_PRODUCE_COMMAND} ${arg_OUTPUT})
endif()

endfunction()

# Example usage:
#
# add_bba_compile_command(
# TARGET chipdb-ice40
# OUTPUT ${CMAKE_BINARY_DIR}/chipdb/ice40/chipdb-1k.bin
# INPUT ${CMAKE_CURRENT_BINARY_DIR}/chipdb-1k.bba
# IDENT ice40/chipdb-1k.bba
# MODE binary
# )
#
# Paths must be absolute.
#
function(add_bba_compile_command)
cmake_parse_arguments(arg "" "TARGET;OUTPUT;INPUT;IDENT;MODE" "" ${ARGN})

cmake_path(GET arg_OUTPUT PARENT_PATH arg_OUTPUT_DIR)
file(MAKE_DIRECTORY ${arg_OUTPUT_DIR})

if (arg_MODE STREQUAL "binary" OR arg_MODE STREQUAL "resource")

add_custom_command(
OUTPUT
${arg_OUTPUT}
COMMAND
bbasm ${BBASM_ENDIAN_FLAG}
${arg_INPUT}
${arg_OUTPUT}.new
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${arg_OUTPUT}.new
${arg_OUTPUT}
DEPENDS
bbasm
${arg_INPUT}
VERBATIM
)

if (arg_MODE STREQUAL "resource")

file(WRITE ${arg_OUTPUT}.rc
"${arg_IDENT} RCDATA \"${arg_OUTPUT}\"")

target_sources(
${arg_TARGET} PRIVATE
${arg_OUTPUT}.rc
)

else()

target_sources(
${arg_TARGET} PRIVATE
${arg_OUTPUT}
)

endif()

elseif (arg_MODE STREQUAL "embed")

add_custom_command(
OUTPUT
${arg_OUTPUT}.cc
${arg_OUTPUT}
COMMAND
bbasm ${BBASM_ENDIAN_FLAG} --e
${arg_INPUT}
${arg_OUTPUT}.cc.new
${arg_OUTPUT}.new
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${arg_OUTPUT}.cc.new
${arg_OUTPUT}.cc
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${arg_OUTPUT}.new
${arg_OUTPUT}
DEPENDS
bbasm
${arg_INPUT}
VERBATIM
)

target_sources(
${arg_TARGET} PRIVATE
${arg_OUTPUT}.cc
)

elseif (arg_MODE STREQUAL "string")

add_custom_command(
OUTPUT
${arg_OUTPUT}.cc
COMMAND
bbasm ${BBASM_ENDIAN_FLAG} --c
${arg_INPUT}
${arg_OUTPUT}.cc.new
COMMAND
${CMAKE_COMMAND} -E rename # atomic update
${arg_OUTPUT}.cc.new
${arg_OUTPUT}.cc
DEPENDS
bbasm
${arg_INPUT}
VERBATIM
)

target_sources(
${arg_TARGET} PRIVATE
${arg_OUTPUT}.cc
)

endif()

endfunction()
File renamed without changes.
2 changes: 2 additions & 0 deletions cmake/FindApycula.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
find_program (GOWIN_BBA_EXECUTABLE gowin_bba)
message(STATUS "gowin_bba executable: ${GOWIN_BBA_EXECUTABLE}")
19 changes: 19 additions & 0 deletions cmake/FindIceStorm.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(icestorm_default_install_prefix ${CMAKE_INSTALL_PREFIX})
if (DEFINED ICEBOX_ROOT) # for compatibility with old build scripts
message(WARNING "-DICEBOX_ROOT= is deprecated, use -DICESTORM_INSTALL_PREFIX=${ICEBOX_ROOT} instead")
get_filename_component(dir ${ICEBOX_ROOT} DIRECTORY)
get_filename_component(dir ${dir} DIRECTORY)
set(icestorm_default_install_prefix ${dir})
elseif (DEFINED ENV{ICESTORM_INSTALL_PREFIX})
set(icestorm_default_install_prefix $ENV{ICESTORM_INSTALL_PREFIX})
endif()
set(ICESTORM_INSTALL_PREFIX ${icestorm_default_install_prefix} CACHE STRING
"IceStorm install prefix")
message(STATUS "IceStorm install prefix: ${ICESTORM_INSTALL_PREFIX}")

if (NOT ICEBOX_DATADIR)
set(ICEBOX_DATADIR ${ICESTORM_INSTALL_PREFIX}/share/icebox)
endif()
message(STATUS "icebox data directory: ${ICEBOX_DATADIR}")

return(PROPAGATE ICEBOX_DATADIR)
Loading

0 comments on commit 3844c2a

Please sign in to comment.