aboutsummaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2020-05-23 19:50:09 +0000
committerwhitequark <whitequark@whitequark.org>2020-05-23 20:57:26 +0000
commite7bb04769d5d7262d3ecfd0de49953078174a880 (patch)
tree20100cd95832d9da3dcebcdb263ba5b05482ffe2 /CMakeLists.txt
parent2692c6f6cce41d22847058c85715e8822feb9b87 (diff)
downloadnextpnr-e7bb04769d5d7262d3ecfd0de49953078174a880.tar.gz
nextpnr-e7bb04769d5d7262d3ecfd0de49953078174a880.tar.bz2
nextpnr-e7bb04769d5d7262d3ecfd0de49953078174a880.zip
Port nextpnr-{ice40,ecp5} to WASI.
This involves very few changes, all typical to WASM ports: * WASM doesn't currently support threads or atomics so those are disabled. * WASM doesn't currently support exceptions so the exception machinery is stubbed out. * WASM doesn't (and can't) have mmap(), so an emulation library is used. That library currently doesn't support MAP_SHARED flags, so MAP_PRIVATE is used instead. There is also an update to bring ECP5 bbasm CMake rules to parity with iCE40 ones, since although it is possible to embed chipdb into nextpnr on WASM, a 200 MB WASM file has very few practical uses. The README is not updated and there is no included toolchain file because at the moment it's not possible to build nextpnr with upstream boost and wasi-libc. Boost requires a patch (merged, will be available in boost 1.74.0), wasi-libc requires a few unmerged patches.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt28
1 files changed, 26 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c1d9f1a6..4fa8f511 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -14,6 +14,24 @@ option(SERIALIZE_CHIPDB "Never build chipdb in parallel to reduce peak memory us
set(Boost_NO_BOOST_CMAKE ON)
+if(WASI)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lwasi-emulated-mman")
+ set(USE_THREADS OFF)
+ add_definitions(
+ -DBOOST_EXCEPTION_DISABLE
+ -DBOOST_NO_EXCEPTIONS
+ -DBOOST_SP_NO_ATOMIC_ACCESS
+ -DBOOST_AC_DISABLE_THREADS
+ -DBOOST_NO_CXX11_HDR_MUTEX
+ )
+else()
+ set(USE_THREADS ON)
+endif()
+
+if (NOT USE_THREADS)
+ add_definitions(-DNPNR_DISABLE_THREADS)
+endif()
+
set(link_param "")
if (STATIC_BUILD)
set(Boost_USE_STATIC_LIBS ON)
@@ -84,7 +102,6 @@ else()
set(CMAKE_CXX_FLAGS_RELEASE "-Wall -fPIC -O3 -g -pipe")
endif()
endif()
-set(CMAKE_DEFIN)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/3rdparty/sanitizers-cmake/cmake;." ${CMAKE_MODULE_PATH})
@@ -99,7 +116,10 @@ endif()
find_package(Sanitizers)
# List of Boost libraries to include
-set(boost_libs filesystem thread program_options iostreams system)
+set(boost_libs filesystem program_options iostreams system)
+if (USE_THREADS)
+ list(APPEND boost_libs thread)
+endif()
if (BUILD_GUI AND NOT BUILD_PYTHON)
message(FATAL_ERROR "GUI requires Python to build")
@@ -229,6 +249,10 @@ foreach (family ${ARCH})
# Add the CLI binary target
add_executable(${PROGRAM_PREFIX}nextpnr-${family} ${COMMON_FILES} ${${ufamily}_FILES})
+ if (WASI)
+ # set(CMAKE_EXECUTABLE_SUFFIX) breaks CMake tests for some reason
+ set_property(TARGET ${PROGRAM_PREFIX}nextpnr-${family} PROPERTY SUFFIX ".wasm")
+ endif()
install(TARGETS ${PROGRAM_PREFIX}nextpnr-${family} RUNTIME DESTINATION bin)
target_compile_definitions(${PROGRAM_PREFIX}nextpnr-${family} PRIVATE MAIN_EXECUTABLE)