nextpnr/CMakeLists.txt

385 lines
13 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.25)
project(nextpnr CXX)
include(CheckCXXCompilerFlag)
if (NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS)
set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings")
endif()
# We want to explictly include all include directories when generating the
# compilation database as not all clang/gcc share the same implicit includes
# leading to essentially non-working compile_commands.json
if (CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES
${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()
option(BUILD_GUI "Build GUI" OFF)
option(BUILD_PYTHON "Build Python Integration" ON)
option(BUILD_TESTS "Build tests" OFF)
option(USE_OPENMP "Use OpenMP to accelerate analytic placer" OFF)
2018-08-24 00:38:13 +08:00
option(COVERAGE "Add code coverage info" OFF)
2018-08-16 16:32:34 +08:00
option(STATIC_BUILD "Create static build" OFF)
2019-02-09 20:34:57 +08:00
option(EXTERNAL_CHIPDB "Create build with pre-built chipdb binaries" OFF)
option(WERROR "pass -Werror to compiler (used for CI)" OFF)
option(PROFILER "Link against libprofiler" OFF)
option(USE_IPO "Compile nextpnr with IPO" ON)
2023-12-09 01:36:48 +08:00
option(USE_RUST "Enable Rust bindings" OFF)
set(PROGRAM_PREFIX "" CACHE STRING "Name prefix for executables")
if (BUILD_GUI AND NOT BUILD_PYTHON)
message(FATAL_ERROR "GUI requires Python to build")
endif()
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
2023-12-09 01:36:48 +08:00
endif()
if (USE_IPO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported)
if (ipo_supported)
message(STATUS "Building with IPO")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "IPO is not supported with this compiler")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
endif()
else()
message(STATUS "Building without IPO")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
endif()
if (WIN32)
set(BBASM_MODE "resource")
elseif (EXTERNAL_CHIPDB)
set(BBASM_MODE "binary")
else()
set(BBASM_MODE "string")
endif()
2018-08-16 16:32:34 +08:00
find_package(Threads)
if (Threads_FOUND)
find_package(TBB QUIET)
if (TBB_FOUND)
add_definitions(-DNEXTPNR_USE_TBB)
endif()
else()
add_definitions(-DNPNR_DISABLE_THREADS)
endif()
if (WASI)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lwasi-emulated-mman")
add_definitions(
-DBOOST_EXCEPTION_DISABLE
-DBOOST_NO_EXCEPTIONS
)
if (NOT Threads_FOUND)
add_definitions(-DBOOST_NO_CXX11_HDR_MUTEX)
endif()
endif()
2018-08-16 16:32:34 +08:00
set(link_param "")
if (STATIC_BUILD)
set(Boost_USE_STATIC_LIBS ON)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
2020-05-14 14:35:55 +08:00
if (MSVC)
set(CMAKE_CXX_FLAGS_RELEASE "/MT")
set(CMAKE_CXX_FLAGS_DEBUG "/MTd")
endif()
else()
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so")
set(link_param "-static")
2020-07-24 22:40:45 +08:00
if (BUILD_PYTHON)
find_package(ZLIB)
find_package(EXPAT)
find_package(Threads)
2020-07-24 00:40:54 +08:00
endif()
endif()
2018-08-16 16:32:34 +08:00
endif()
2019-02-09 20:34:57 +08:00
if (EXTERNAL_CHIPDB)
set(EXTERNAL_CHIPDB_ROOT "${CMAKE_INSTALL_PREFIX}/share/nextpnr" CACHE STRING
"External chipdb path")
message(STATUS "Using external chipdb path: ${EXTERNAL_CHIPDB_ROOT}")
2019-02-09 20:34:57 +08:00
add_definitions("-DEXTERNAL_CHIPDB_ROOT=\"${EXTERNAL_CHIPDB_ROOT}\"")
endif()
# List of families to build
set(FAMILIES generic ice40 ecp5 nexus gowin machxo2 mistral himbaechel)
set(STABLE_FAMILIES generic ice40 ecp5)
set(EXPERIMENTAL_FAMILIES nexus gowin machxo2 mistral himbaechel)
set(ARCH "" CACHE STRING "Architecture family for nextpnr build")
set_property(CACHE ARCH PROPERTY STRINGS ${FAMILIES})
if (NOT ARCH)
message(STATUS "Architecture needs to be set, set desired one with -DARCH=xxx")
message(STATUS "Supported architectures are :")
message(STATUS " all")
message(STATUS " all+alpha")
foreach (item ${FAMILIES})
message(STATUS " ${item}")
endforeach()
message(FATAL_ERROR "Architecture setting is mandatory")
endif()
if (ARCH STREQUAL "all+alpha")
set(ARCH ${STABLE_FAMILIES} ${EXPERIMENTAL_FAMILIES})
elseif (ARCH STREQUAL "all")
set(ARCH ${STABLE_FAMILIES})
endif()
foreach (item ${ARCH})
if (NOT item IN_LIST FAMILIES)
message(FATAL_ERROR "Architecture '${item}' not in list of supported architectures")
endif()
endforeach()
2024-01-03 21:19:42 +08:00
set(CMAKE_CXX_STANDARD 17)
2018-07-03 14:52:19 +08:00
if (MSVC)
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /D_DEBUG /W4 /wd4100 /wd4244 /wd4125 /wd4800 /wd4456 /wd4458 /wd4305 /wd4459 /wd4121 /wd4996")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /W4 /wd4100 /wd4244 /wd4125 /wd4800 /wd4456 /wd4458 /wd4305 /wd4459 /wd4121 /wd4996 /wd4127")
2018-07-03 14:52:19 +08:00
else()
# N.B. the -Wno-array-bounds is to work around a false positive in GCC 9
set(WARN_FLAGS "-Wall -Wextra")
foreach (TRY_WARN_FLAG no-unused-parameter no-missing-field-initializers no-array-bounds no-format-truncation)
check_cxx_compiler_flag("-W${TRY_WARN_FLAG}" HAS_W${TRY_WARN_FLAG})
if (HAS_W${TRY_WARN_FLAG})
set(WARN_FLAGS "${WARN_FLAGS} -W${TRY_WARN_FLAG}")
endif()
endforeach()
if (WERROR)
set(WARN_FLAGS "${WARN_FLAGS} -Werror")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "${WARN_FLAGS} -fPIC -ggdb -pipe")
if (USE_OPENMP)
set(CMAKE_CXX_FLAGS_RELEASE "${WARN_FLAGS} -fPIC -O3 -g -pipe -fopenmp")
else()
set(CMAKE_CXX_FLAGS_RELEASE "${WARN_FLAGS} -fPIC -O3 -g -pipe")
endif()
2018-07-03 14:52:19 +08:00
endif()
2018-06-25 01:32:39 +08:00
set(boost_libs filesystem program_options iostreams system)
if (Threads_FOUND)
list(APPEND boost_libs thread)
endif()
find_package(Boost REQUIRED COMPONENTS ${boost_libs})
2018-07-14 20:06:05 +08:00
if (BUILD_PYTHON)
# TODO: sensible minimum Python version
find_package(Python3 3.5 REQUIRED COMPONENTS Interpreter Development.Embed)
find_package(pybind11 CONFIG)
if (NOT pybind11_FOUND)
message(STATUS "Using built-in pybind11")
add_subdirectory(3rdparty/pybind11 EXCLUDE_FROM_ALL)
endif()
else()
find_package(Python3 3.5 REQUIRED COMPONENTS Interpreter)
add_definitions("-DNO_PYTHON")
endif()
if (USE_RUST)
add_subdirectory(3rdparty/corrosion)
corrosion_import_crate(MANIFEST_PATH rust/Cargo.toml PROFILE "release" IMPORTED_CRATES RUST_CRATES)
endif()
if (BUILD_GUI)
# Find the Qt5 libraries
find_package(Qt5 COMPONENTS Core Widgets OpenGL REQUIRED)
# For higher quality backtraces
set(CMAKE_ENABLE_EXPORTS ON)
2018-06-12 03:04:30 +08:00
add_subdirectory(3rdparty/QtPropertyBrowser ${CMAKE_CURRENT_BINARY_DIR}/generated/3rdparty/QtPropertyBrowser EXCLUDE_FROM_ALL)
else()
add_definitions(-DNO_GUI)
endif()
find_package(Eigen3 REQUIRED NO_MODULE)
2018-06-06 03:03:06 +08:00
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})
find_package(Sanitizers)
2023-12-09 01:36:48 +08:00
if (COVERAGE)
include(CodeCoverage)
endif()
if (BUILD_TESTS)
add_subdirectory(3rdparty/googletest/googletest ${CMAKE_CURRENT_BINARY_DIR}/generated/3rdparty/googletest EXCLUDE_FROM_ALL)
enable_testing()
endif()
if (CMAKE_CROSSCOMPILING)
set(BBA_IMPORT "IMPORTFILE-NOTFOUND" CACHE FILEPATH
"Path to the `bba-export.cmake` export file from a native build")
include(${BBA_IMPORT})
else()
add_subdirectory(bba)
endif()
include(BBAsm)
if (NOT DEFINED CURRENT_GIT_VERSION)
# Get the latest abbreviated commit hash of the working branch
# if not already defined outside (e.g. by package manager when building
# outside of git repository)
execute_process(
COMMAND git describe --tags --always
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE CURRENT_GIT_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/common/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h)
include_directories(
common/kernel
${Boost_INCLUDE_DIRS}
${Python3_INCLUDE_DIRS}
)
add_subdirectory(common/kernel)
add_subdirectory(common/place)
add_subdirectory(common/route)
add_subdirectory(frontend)
add_subdirectory(json)
add_subdirectory(rust)
set(COMMON_LIBRARIES
nextpnr_kernel
nextpnr_place
nextpnr_route
nextpnr_frontend
nextpnr_json
Eigen3::Eigen
oourafft
)
set(EXTRA_LIB_DEPS)
if (PROFILER)
list(APPEND EXTRA_LIB_DEPS profiler)
endif()
if (TBB_FOUND)
2022-04-05 23:12:44 +08:00
list(APPEND EXTRA_LIB_DEPS TBB::tbb)
endif()
foreach (family ${ARCH})
message(STATUS "Configuring architecture: ${family}")
string(TOUPPER ${family} ufamily)
aux_source_directory(${family}/ ${ufamily}_FILES)
if (BUILD_GUI)
add_subdirectory(gui ${CMAKE_CURRENT_BINARY_DIR}/generated/gui/${family} EXCLUDE_FROM_ALL)
endif()
# Add the CLI binary target
add_executable(${PROGRAM_PREFIX}nextpnr-${family} ${${ufamily}_FILES})
target_link_libraries(${PROGRAM_PREFIX}nextpnr-${family} PRIVATE ${COMMON_LIBRARIES})
if (WASI)
# set(CMAKE_EXECUTABLE_SUFFIX) breaks CMake tests for some reason
set_property(TARGET ${PROGRAM_PREFIX}nextpnr-${family} PROPERTY SUFFIX ".wasm")
endif()
2020-04-10 16:50:30 +08:00
install(TARGETS ${PROGRAM_PREFIX}nextpnr-${family} RUNTIME DESTINATION bin)
target_compile_definitions(${PROGRAM_PREFIX}nextpnr-${family} PRIVATE MAIN_EXECUTABLE)
# Add any new per-architecture targets here
if (BUILD_TESTS)
2018-08-24 00:38:13 +08:00
if (COVERAGE)
APPEND_COVERAGE_COMPILER_FLAGS()
2018-08-24 00:45:54 +08:00
set(COVERAGE_LCOV_EXCLUDES '/usr/include/*' '3rdparty/*' 'generated/*' 'bba/*' 'tests/*')
2018-08-24 00:38:13 +08:00
SETUP_TARGET_FOR_COVERAGE_LCOV(
NAME ${family}-coverage
2020-04-10 16:50:30 +08:00
EXECUTABLE ${PROGRAM_PREFIX}nextpnr-${family}-test
DEPENDENCIES ${PROGRAM_PREFIX}nextpnr-${family}-test
2018-08-24 00:38:13 +08:00
)
endif()
aux_source_directory(tests/${family}/ ${ufamily}_TEST_FILES)
2018-07-26 04:57:20 +08:00
if (BUILD_GUI)
aux_source_directory(tests/gui/ GUI_TEST_FILES)
endif()
2020-04-10 16:50:30 +08:00
add_executable(${PROGRAM_PREFIX}nextpnr-${family}-test ${${ufamily}_TEST_FILES}
${${ufamily}_FILES} ${GUI_TEST_FILES})
target_link_libraries(${PROGRAM_PREFIX}nextpnr-${family}-test PRIVATE ${COMMON_LIBRARIES} gtest_main)
2020-04-10 16:50:30 +08:00
add_sanitizers(${PROGRAM_PREFIX}nextpnr-${family}-test)
add_test(${family}-test ${CMAKE_CURRENT_BINARY_DIR}/nextpnr-${family}-test)
endif()
# Set ${family_targets} to the list of targets being build for this family
2020-04-10 16:50:30 +08:00
set(family_targets ${PROGRAM_PREFIX}nextpnr-${family})
if (BUILD_TESTS)
2020-04-10 16:50:30 +08:00
set(family_targets ${family_targets} ${PROGRAM_PREFIX}nextpnr-${family}-test)
Adding NanoXplore NG-Ultra support (#1397) * ng-ultra: new architecture * Implementation as in D2 deliverable * Support for nxdesignsuite-24.0.0.0-20240429T102300 * Save memory by directly outputing json * Add support for bidirectional IOs * cleanup * Create BFRs properly * Add IOM insertion * Cleanup * Block certain pips depending of DDFR mode * Add LUT bypass to improve routability * Add bypass for CSC mode of GCK * Fix IOM case * Initial memory support * Better RF/XRF handling * fix * RF placement and legalization * Disconnect non available ports for NX_RAM * cleanup * Add RFB/RAM context support for latest release * Remove ports that must not be used * Proper port used only on RFB * Add structure for clock sinks * Use cell type where applicable * Add clock sinks for other cell types * Validation check fixes * Commented too restrictive placement * Added more crossbar wire type * Hande IO termination input * Fail early due to NX tools limitation for now * Validations and fixes for RAM I/Os * Fix for latest version of tools * Use ctx->idf where applicable * warn if RAM ports are not actually used * Fix IOM packing * Fix CY packing * Change how constants are handled on CY * Post placement optimization for CY * Address comments for PR * pack and export GCK, WFG and PLL * Cover more global routing cases * Constraing to location if provided * Place at LOC * Pack and export DSP * wip * wip * notes * wip * wip * Validate DSPs * DSP cascading * Check mandatory parameters for DSP * existing gck * wip * export all the rest for bitstream * CDC packing * add more sinks * place FIFO * map rest of FIFO ports * enable pll by default * cleanup * Initial XLUT support * Fix statistics * Properly duplicate GCKs * RRSTO and WRSTO are not used on XFIFO * Fix for latest version of JSON format * Implement GCK limitations * cleanup * cleanup * Add more signals and use lowskew name * cleanup code a bit * Fix wfb * detect cascaded GCKs * Handle DFR * Route dfr clock properly * Cleanup * Cleanup bitstream code * Review issues addressed * Move helper routines * Expose private members for unit tests * cleanup * remove scale factor * make all location helper arrays static * Addressed review comments * Support post-routing CSC and SCC * Support NX_BFF * Place CSS and SCC only on allowed locations * Support latest Impulse * ng_ultra: Expand bounding box further for left-edge IO Signed-off-by: gatecat <gatecat@ds0.me> * Export all IO parameters in bitstream * Handle new CSV order or parameters and additional validation * Add some more undocumented values for CSV * Support for old and new CSV formats * Initial DDFR support * Display warning message once per file * Address review issues * Fix crash on memory access * Make boundbox fit NG-Ultra internal design * Update attributes after dff rewrite * Implement basic NG-Ultra LUT-DFF unit tests * Always use first seen xbar input Signed-off-by: gatecat <gatecat@ds0.me> * Simplified crossbar pip detection * Change order to prevent issues with some unconnected constants * Pack LUT and multiple DFF in stripe * Place DFF chains * Improve large DFF chains * Rename to pack_dff_chains * Better use XLUTs when possible * pack output DFF together with XLUT * option to disable XLUT optimiziations * Make more optimizations optional * fix to use pre-increment * GCK for lowskew signals * Bugfix for nets that are not part of lowskew network * Fix bitstream export for PLL cell * Remove separate route lowskew * Allow WFG mode 2 * Merge inverter into GCK * Add CSC per TILE when needed * Improve reusage of existing cell for CSC * Take preferred CSC * Cleanup * When in place CSC size not important * Cleanup * Reset and Load restriction * make csc optimisation optional * Proper count for IO resources * Detect when there is no next cell for DSP chain * Do not incorporate loops in XLUT * Check if output exists * Update copyright for delivery * Make building NG-Ultra chip database optional, follow filename convention * Ported drawing code to new API * Update expandBoundingBox for NG-Ultra * Copyright and license update * Add README information * cleanup and constids * Using ctx->idf where applicable * remove if_using_basecluster * refactor extra data usage * refactor to use create_cell_ptr only * optimized getCSC * optimize critical path a bit * clangformat * disable clangformat where applicable --------- Signed-off-by: gatecat <gatecat@ds0.me> Co-authored-by: Lofty <dan.ravensloft@gmail.com> Co-authored-by: gatecat <gatecat@ds0.me>
2024-12-04 16:00:05 +08:00
set(family_test_targets ${PROGRAM_PREFIX}nextpnr-${family}-test)
endif()
# Include the family-specific CMakeFile
include(${family}/family.cmake)
foreach (target ${family_targets})
foreach (lib_dep ${EXTRA_LIB_DEPS})
target_link_libraries(${target} PRIVATE ${lib_dep})
endforeach()
# Include family-specific source files to all family targets and set defines appropriately
2023-12-09 01:36:48 +08:00
target_include_directories(${target} PRIVATE ${family}/ ${CMAKE_CURRENT_BINARY_DIR}/generated/ rust/)
target_compile_definitions(${target} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family} ARCH_${ufamily} ARCHNAME=${family})
target_link_libraries(${target} LINK_PUBLIC ${Boost_LIBRARIES} ${link_param})
2018-07-16 14:07:57 +08:00
if (NOT MSVC)
target_link_libraries(${target} LINK_PUBLIC pthread)
endif()
2018-06-25 01:32:39 +08:00
add_sanitizers(${target})
if (BUILD_GUI)
target_compile_definitions(${target} PRIVATE QT_NO_KEYWORDS)
target_include_directories(${target} PRIVATE gui/${family}/ gui/)
target_link_libraries(${target} LINK_PUBLIC gui_${family})
endif()
2018-07-02 16:59:25 +08:00
if (BUILD_PYTHON)
target_link_libraries(${target} LINK_PUBLIC ${Python3_LIBRARIES})
if (STATIC_BUILD)
target_link_libraries(${target} LINK_PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} ${ZLIB_LIBRARIES} ${EXPAT_LIBRARIES})
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Windows")
else()
target_link_libraries(${target} LINK_PUBLIC -lutil)
endif()
endif()
2018-07-02 16:59:25 +08:00
endif()
2023-12-09 01:36:48 +08:00
if (USE_RUST)
target_sources(${target} PRIVATE ${RUST_FILES})
target_compile_definitions(${target} PRIVATE USE_RUST)
foreach (crate ${RUST_CRATES})
2023-12-09 01:36:48 +08:00
target_link_libraries(${target} PRIVATE ${crate})
endforeach()
2023-12-09 01:36:48 +08:00
endif()
endforeach()
endforeach()
file(GLOB_RECURSE CLANGFORMAT_FILES *.cc *.h)
2020-06-27 19:20:16 +08:00
string(REGEX REPLACE "[^;]*/ice40/chipdb/chipdb-[^;]*.cc" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
string(REGEX REPLACE "[^;]*/ecp5/chipdb/chipdb-[^;]*.cc" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
string(REGEX REPLACE "[^;]*nexus/chipdb/chipdb-[^;]*.cc" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
string(REGEX REPLACE "[^;]*/machxo2/chipdb/chipdb-[^;]*.cc" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
string(REGEX REPLACE "[^;]*/3rdparty[^;]*" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
string(REGEX REPLACE "[^;]*/generated[^;]*" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
string(REGEX REPLACE "[^;]*/libmistral/[^;]*" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}")
add_custom_target(
clangformat
COMMAND clang-format
-style=file
-i
${CLANGFORMAT_FILES}
)