diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a8a8890..474d582 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,3 +1,9 @@ +trigger: + branches: + exclude: + # master branch publishes releases - avoid merges triggering a new release + - master + schedules: - cron: "0 4 * * *" displayName: Nightly build at 0400 UTC @@ -26,6 +32,7 @@ stages: jobs: - job: build_toolchain displayName: Build toolchain + timeoutInMinutes: 0 strategy: matrix: linux_x86_64: @@ -34,9 +41,6 @@ stages: osx: ARCH: darwin vm_image: macOS-10.15 - # win64: - # ARCH: windows_amd64 - # vm_image: vs2017-win2016 pool: vmImage: '$(vm_image)' steps: @@ -53,6 +57,54 @@ stages: name: build_toolchain - publish: _packages/build_$(ARCH)/fpga-toolchain-$(ARCH)-$(RELEASE_TAG).tar.gz artifact: fpga-toolchain-$(ARCH)-$(RELEASE_TAG) + - job: build_toolchain_windows_amd64 + displayName: Build toolchain windows_amd64 + timeoutInMinutes: 0 + pool: + vmImage: vs2017-win2016 + variables: + ARCH: windows_amd64 + MINGW_ARCH: x86_64 + steps: + - powershell: | + Set-MpPreference -DisableArchiveScanning $true + Set-MpPreference -DisableRealtimeMonitoring $true + Set-MpPreference -DisableBehaviorMonitoring $true + - download: current + artifact: ecp5-bba + - bash: | + RELEASE_TAG=nightly-$(date +'%Y%m%d') + # create pipeline variable + echo "##vso[task.setvariable variable=RELEASE_TAG]$RELEASE_TAG" + - script: copy $(Pipeline.Workspace)\ecp5-bba\ecp5-bba-linux_x86_64-nightly.tar.gz $(Build.Repository.LocalPath)\chipdb.tar.gz + displayName: Copy BBA artifact + - script: | + set MSYS_ROOT=%CD:~0,2%\msys64 + echo ##vso[task.setvariable variable=MSYS_ROOT]%MSYS_ROOT% + git clone https://github.com/msys2/msys2-ci-base.git %MSYS_ROOT% + %MSYS_ROOT%\usr\bin\rm -rf %MSYS_ROOT%\.git + displayName: Install MSYS2 + - script: | + set PATH=%MSYS_ROOT%\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem + %MSYS_ROOT%\usr\bin\pacman --noconfirm -Syyuu + displayName: Update MSYS2 + - script: | + set PATH=%MSYS_ROOT%\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem + %MSYS_ROOT%\usr\bin\pacman --noconfirm --needed -S git base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake + %MSYS_ROOT%\usr\bin\pacman --noconfirm -Scc + displayName: Install Toolchain + - script: | + set PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem + %MSYS_ROOT%\usr\bin\sed -i "s|#CacheDir.*|CacheDir=/c/Users/%USERNAME%/AppData/Local/Temp|g" /etc/pacman.conf + set MSYS=winsymlinks:nativestrict + %MSYS_ROOT%\msys2_shell.cmd -defterm -no-start -mingw64 -full-path -here -c "./build.sh windows_amd64" + displayName: CI-Build + env: + MSYSTEM: MINGW64 + CHERE_INVOKING: yes + MINGW_INSTALLS: mingw64 + - publish: _packages/build_$(ARCH)/fpga-toolchain-$(ARCH)-$(RELEASE_TAG).zip + artifact: fpga-toolchain-$(ARCH)-$(RELEASE_TAG) - stage: publish_release displayName: publish release diff --git a/build.sh b/build.sh index 206578d..3f1f759 100755 --- a/build.sh +++ b/build.sh @@ -21,8 +21,8 @@ export NAME=fpga-toolchain # -- Debug flags INSTALL_DEPS=1 COMPILE_DFU_UTIL=1 -COMPILE_ICESTORM=1 COMPILE_YOSYS=1 +COMPILE_ICESTORM=1 COMPILE_NEXTPNR_ICE40=1 COMPILE_NEXTPNR_ECP5=1 COMPILE_ECPPROG=1 @@ -60,12 +60,15 @@ mkdir -p $PACKAGE_DIR/$NAME/share # -- Test script function function test_bin { - . $WORK_DIR/test/test_bin.sh $1 - if [ $? != "0" ]; then - exit 1 + if [[ ${ARCH:0:7} != "windows" ]]; then + . $WORK_DIR/test/test_bin.sh $1 + if [ $? != "0" ]; then + exit 1 + fi fi } + # -- Print function function print { echo "" diff --git a/scripts/build_setup.sh b/scripts/build_setup.sh index da49238..18861fc 100755 --- a/scripts/build_setup.sh +++ b/scripts/build_setup.sh @@ -3,6 +3,8 @@ set -e +export MAKE="make" + if [ $ARCH == "linux_x86_64" ]; then export CC="gcc" export CXX="g++" @@ -46,6 +48,14 @@ if [ $ARCH == "windows_amd64" ]; then export CXX="x86_64-w64-mingw32-g++" export HOST_FLAGS="--host=x86_64-w64-mingw32" export ABC_ARCHFLAGS="-DSIZEOF_VOID_P=8 -DSIZEOF_LONG=4 -DSIZEOF_INT=4 -DWIN32_NO_DLL -DHAVE_STRUCT_TIMESPEC -D_POSIX_SOURCE -fpermissive -w" + export MAKE="mingw32-make" + + export EMBEDDED_PY_VER=$(python.exe -c 'import sys; print(str(sys.version_info[0])+"."+str(sys.version_info[1]))') + mkdir -p $PACKAGE_DIR/$NAME/lib/python$EMBEDDED_PY_VER + cp -L -R /mingw64/lib/python$EMBEDDED_PY_VER $PACKAGE_DIR/$NAME/lib + # this isn't necessary and takes up ~half the size + rm -rf $PACKAGE_DIR/$NAME/lib/python$EMBEDDED_PY_VER/test + cp /mingw64/bin/{libgcc_s_seh-1.dll,libstdc++-6.dll,libwinpthread-1.dll,libpython$EMBEDDED_PY_VER.dll} $PACKAGE_DIR/$NAME/bin fi if [ $ARCH == "darwin" ]; then @@ -70,3 +80,5 @@ fi if [ $J -gt 1 ]; then J=$(($J-1)) fi + +echo Running with J=$J diff --git a/scripts/compile-nextpnr-ecp5.sh b/scripts/compile-nextpnr-ecp5.sh index e327805..63cfdfb 100755 --- a/scripts/compile-nextpnr-ecp5.sh +++ b/scripts/compile-nextpnr-ecp5.sh @@ -54,7 +54,7 @@ fi rm -f $nextpnr_dir/CMakeCache.txt $prjtrellis_dir/CMakeCache.txt cd $BUILD_DIR -mkdir chipdb +mkdir -p chipdb cd chipdb tar -xvf $WORK_DIR/chipdb.tar.gz @@ -91,20 +91,39 @@ then cd .. elif [ ${ARCH:0:7} = "windows" ] then - echo "Build not functioning on Windows" - exit 1 -else cd $BUILD_DIR/$prjtrellis_dir/libtrellis + cmake \ + -G "MinGW Makefiles" \ + -DBUILD_SHARED=OFF \ + -DSTATIC_BUILD=ON \ + -DBUILD_PYTHON=OFF \ + -DCMAKE_INSTALL_PREFIX=$PACKAGE_DIR/$NAME \ + -DCURRENT_GIT_VERSION=$prjtrellis_commit \ + -DBoost_USE_STATIC_LIBS=ON \ + . + mingw32-make -j$J CXX="$CXX" LIBS="-lm" + mingw32-make install - # # The first run of the build produces the Python shared library - # # (Disabled since we now use PREGENERATED_BBA_PATH) - # cmake \ - # -DBUILD_SHARED=ON \ - # -DSTATIC_BUILD=OFF \ - # -DBUILD_PYTHON=ON \ - # . - # make -j$J CXX="$CXX" - # rm -rf CMakeCache.txt + cd $BUILD_DIR/$nextpnr_dir + cp $WORK_DIR/scripts/nextpnr-CMakeLists.txt CMakeLists.txt + + cmake \ + -G "MinGW Makefiles" \ + -DARCH=ecp5 \ + -DTRELLIS_ROOT=$BUILD_DIR/$prjtrellis_dir \ + -DPYTRELLIS_LIBDIR=$BUILD_DIR/$prjtrellis_dir/libtrellis \ + -DPREGENERATED_BBA_PATH=$BUILD_DIR/chipdb/ecp5-bba/bba \ + -DBoost_USE_STATIC_LIBS=ON \ + -DBUILD_GUI=OFF \ + -DBUILD_PYTHON=ON \ + -DBUILD_HEAP=ON \ + -DSTATIC_BUILD=ON \ + . + + mingw32-make -j$J CXX="$CXX" LIBS="-static -lstdc++ -lm" VERBOSE=1 + cd .. +else + cd $BUILD_DIR/$prjtrellis_dir/libtrellis # The second run builds the static libraries we'll use in the final release cmake \ @@ -131,7 +150,7 @@ else -DSTATIC_BUILD=ON \ -DBoost_USE_STATIC_LIBS=ON \ . - make -j$J CXX="$CXX" + make -j$J CXX="$CXX" LIBS="-static -lstdc++ -lm" # Install a copy of Python, since Python libraries are not compatible # across minor versions. @@ -149,13 +168,15 @@ fi || exit 1 # -- Copy the executables to the bin dir mkdir -p $PACKAGE_DIR/$NAME/bin -$WORK_DIR/scripts/test_bin.sh $BUILD_DIR/$nextpnr_dir/nextpnr-ecp5$EXE +# $WORK_DIR/scripts/test_bin.sh $BUILD_DIR/$nextpnr_dir/nextpnr-ecp5$EXE cp $BUILD_DIR/$nextpnr_dir/nextpnr-ecp5$EXE $PACKAGE_DIR/$NAME/bin/nextpnr-ecp5$EXE for i in ecpmulti ecppack ecppll ecpunpack ecpbram do - $WORK_DIR/scripts/test_bin.sh $BUILD_DIR/$prjtrellis_dir/libtrellis/$i$EXE + # $WORK_DIR/scripts/test_bin.sh $BUILD_DIR/$prjtrellis_dir/libtrellis/$i$EXE cp $BUILD_DIR/$prjtrellis_dir/libtrellis/$i$EXE $PACKAGE_DIR/$NAME/bin/$i$EXE done # Do a test run of the new binary $PACKAGE_DIR/$NAME/bin/nextpnr-ecp5$EXE --help +echo 'print("hello from python!")' > hello.py +$PACKAGE_DIR/$NAME/bin/nextpnr-ecp5$EXE --run hello.py diff --git a/scripts/compile_dfu_util.sh b/scripts/compile_dfu_util.sh index 9680f79..50175e7 100755 --- a/scripts/compile_dfu_util.sh +++ b/scripts/compile_dfu_util.sh @@ -27,10 +27,14 @@ if [ $ARCH == "darwin" ]; then --includedir=/opt/local/include \ USB_CFLAGS="-I$LIBUSB_ROOT/include/libusb-1.0" \ USB_LIBS="$LIBUSB_ROOT/lib/libusb-1.0.a -Wl,-framework,IOKit -Wl,-framework,CoreFoundation" - make + $MAKE +elif [ ${ARCH:0:7} = "windows" ] +then + ./configure USB_LIBS="-static -lpthread -lusb-1.0" + $MAKE else ./configure USB_CFLAGS="-I$WORK_DIR/build-data/include/libusb-1.0" USB_LIBS="-static $WORK_DIR/build-data/lib/$ARCH/libusb-1.0.a -lpthread" - make + $MAKE fi TOOLS="dfu-util dfu-prefix dfu-suffix" diff --git a/scripts/compile_ecpprog.sh b/scripts/compile_ecpprog.sh index c79152b..1fec204 100755 --- a/scripts/compile_ecpprog.sh +++ b/scripts/compile_ecpprog.sh @@ -24,14 +24,19 @@ if [ $ARCH == "darwin" ]; then sed -i "" "s/-ggdb //;" Makefile # pkg-config is used to set LDLIBS in this Makefile and doesn't quite do what we want sed -i "" "s/\$^ \$(LDLIBS)/\$^ \$(LDSTATICLIBS)/g" Makefile - make -j$J CC="$CC" \ + $MAKE -j$J CC="$CC" \ PKG_CONFIG=":" \ LDSTATICLIBS="$LIBFTDI_ROOT/lib/libftdi1.a $LIBUSB_ROOT/lib/libusb-1.0.a -Wl,-framework,IOKit -Wl,-framework,CoreFoundation" \ CFLAGS="-MD -O0 -Wall -std=c99 -I$LIBFTDI_ROOT/include/libftdi1 $CFLAGS" +elif [ ${ARCH:0:7} = "windows" ] +then + sed -i "s/-ggdb //;" Makefile + $MAKE -j$J CC="$CC" \ + LDFLAGS="-static -pthread" else sed -i "s/-ggdb //;" Makefile sed -i "s/\$^ \$(LDLIBS)/\$^ \$(LDLIBS) \$(LDUSBSTATIC)/g" Makefile - make -j$J CC="$CC" \ + $MAKE -j$J CC="$CC" \ LDFLAGS="-static -pthread -L$WORK_DIR/build-data/lib/$ARCH " \ LDUSBSTATIC="-lusb-1.0"\ CFLAGS="-MD -O0 -Wall -std=c99 -I$WORK_DIR/build-data/include/libftdi1 -I$WORK_DIR/build-data/include/libusb-1.0" diff --git a/scripts/compile_icestorm.sh b/scripts/compile_icestorm.sh index 80920a6..91f8b9d 100755 --- a/scripts/compile_icestorm.sh +++ b/scripts/compile_icestorm.sh @@ -33,6 +33,10 @@ if [ $ARCH == "darwin" ]; then make -j$J CXX="$CXX" \ CXXFLAGS="-std=c++11 $CXXFLAGS" \ SUBDIRS="icebox icepack icemulti icepll icetime icebram" +elif [ ${ARCH:0:7} = "windows" ] +then + sed -i "s/-ggdb //;" Makefile + $MAKE -j$J CC="$CC" STATIC=1 else sed -i "s/-ggdb //;" config.mk sed -i "s/\$^ \$(LDLIBS)/\$^ \$(LDLIBS) \$(LDUSBSTATIC)/g" iceprog/Makefile @@ -47,19 +51,14 @@ fi TOOLS="iceprog icepack icemulti icepll icetime icebram" -EXE_O= -if [ -f icepack/icepack.exe ]; then - EXE_O=.exe -fi - # -- Test the generated executables for dir in $TOOLS; do - test_bin $dir/$dir$EXE_O + test_bin $dir/$dir$EXE done # -- Copy the executables to the bin dir for dir in $TOOLS; do - cp $dir/$dir$EXE_O $PACKAGE_DIR/$NAME/bin/$dir$EXE + cp $dir/$dir$EXE $PACKAGE_DIR/$NAME/bin/$dir$EXE done # -- Copy the chipdb*.txt data files diff --git a/scripts/compile_iverilog.sh b/scripts/compile_iverilog.sh index 9dc5ec4..206fdc3 100755 --- a/scripts/compile_iverilog.sh +++ b/scripts/compile_iverilog.sh @@ -28,15 +28,21 @@ if [ $ARCH == "darwin" ]; then ./configure --prefix=$PACKAGE_DIR/$NAME \ --exec-prefix=$PACKAGE_DIR/$NAME \ - make + $MAKE export PATH=$OLDPATH +elif [ ${ARCH:0:7} = "windows" ] +then + ./configure --prefix=$PACKAGE_DIR/$NAME \ + --exec-prefix=$PACKAGE_DIR/$NAME \ + LDFLAGS="-static -lstdc++ -lm" \ + + $MAKE else ./configure --prefix=$PACKAGE_DIR/$NAME \ --exec-prefix=$PACKAGE_DIR/$NAME \ - make + $MAKE fi -make install - +$MAKE install diff --git a/scripts/compile_nextpnr-ice40.sh b/scripts/compile_nextpnr-ice40.sh index cba8478..bff3fb3 100755 --- a/scripts/compile_nextpnr-ice40.sh +++ b/scripts/compile_nextpnr-ice40.sh @@ -43,16 +43,20 @@ if [ $ARCH == "darwin" ]; then . make -j$J CXX="$CXX" LIBS="-lm -fno-lto -ldl -lutil" elif [ ${ARCH:0:7} == "windows" ]; then + cp $WORK_DIR/scripts/nextpnr-CMakeLists.txt CMakeLists.txt + cmake \ - -DARCH=ice40 \ - -DBUILD_HEAP=ON \ - -DCMAKE_SYSTEM_NAME=Windows \ - -DBUILD_GUI=OFF \ - -DSTATIC_BUILD=ON \ - -DICEBOX_ROOT=$PACKAGE_DIR/$NAME/share/icebox \ - -DBoost_USE_STATIC_LIBS=ON \ - . - make -j$J CXX="$CXX" LIBS="-static -static-libstdc++ -static-libgcc -lm" + -G "MinGW Makefiles" \ + -DARCH=ice40 \ + -DBUILD_HEAP=ON \ + -DBUILD_GUI=OFF \ + -DBUILD_PYTHON=ON \ + -DSTATIC_BUILD=ON \ + -DICEBOX_ROOT=$PACKAGE_DIR/$NAME/share/icebox \ + -DBoost_USE_STATIC_LIBS=ON \ + . + + $MAKE -j$J CXX="$CXX" VERBOSE=1 else cmake \ -DARCH=ice40 \ diff --git a/scripts/compile_yosys.sh b/scripts/compile_yosys.sh index 429890a..131f460 100755 --- a/scripts/compile_yosys.sh +++ b/scripts/compile_yosys.sh @@ -37,7 +37,7 @@ cd $BUILD_DIR/$YOSYS # -- Compile it if [ $ARCH == "darwin" ]; then - make config-clang + $MAKE config-clang sed -i "" "s/-Wall -Wextra -ggdb/-w/;" Makefile CXXFLAGS="-std=c++11 $CXXFLAGS" make \ -j$J YOSYS_VER="$VER (open-tool-forge build)" \ @@ -46,8 +46,8 @@ if [ $ARCH == "darwin" ]; then ARCHFLAGS=\"$ABC_ARCHFLAGS\" ABC_USE_NO_READLINE=1" elif [ ${ARCH:0:7} == "windows" ]; then - make config-msys2-64 - make -j$J YOSYS_VER="$VER (open-tool-forge build)" PRETTY=0 \ + $MAKE config-msys2-64 + $MAKE -j$J YOSYS_VER="$VER (open-tool-forge build)" PRETTY=0 \ LDLIBS="-static -lstdc++ -lm" \ ABCMKARGS="CC=\"$CC\" CXX=\"$CXX\" LIBS=\"-static -lm\" OPTFLAGS=\"-O\" \ ARCHFLAGS=\"$ABC_ARCHFLAGS\" \ @@ -57,12 +57,12 @@ elif [ ${ARCH:0:7} == "windows" ]; then ENABLE_TCL=0 ENABLE_PLUGINS=0 ENABLE_READLINE=0 ENABLE_COVER=0 ENABLE_ZLIB=0 ENABLE_ABC=1 else - make config-gcc + $MAKE config-gcc sed -i "s/-Wall -Wextra -ggdb/-w/;" Makefile sed -i "s/LD = gcc$/LD = $CC/;" Makefile sed -i "s/CXX = gcc$/CXX = $CC/;" Makefile sed -i "s/LDFLAGS += -rdynamic/LDFLAGS +=/;" Makefile - make -j$J YOSYS_VER="$VER (open-tool-forge build)" \ + $MAKE -j$J YOSYS_VER="$VER (open-tool-forge build)" \ LDLIBS="-static -lstdc++ -lm" \ ENABLE_TCL=0 ENABLE_PLUGINS=0 ENABLE_READLINE=0 ENABLE_COVER=0 ENABLE_ZLIB=0 ENABLE_ABC=1 \ ABCMKARGS="CC=\"$CC\" CXX=\"$CXX\" LIBS=\"-static -lm -ldl -pthread\" \ @@ -71,25 +71,19 @@ else ABC_USE_NO_READLINE=1" fi -EXE_O= -if [ -f yosys.exe ]; then - EXE_O=.exe - PY=.exe -fi - # -- Test the generated executables -test_bin yosys$EXE_O -test_bin yosys-abc$EXE_O +test_bin yosys$EXE +test_bin yosys-abc$EXE test_bin yosys-config -test_bin yosys-filterlib$EXE_O -test_bin yosys-smtbmc$EXE_O +test_bin yosys-filterlib$EXE +test_bin yosys-smtbmc$EXE # -- Copy the executable files -cp yosys$EXE_O $PACKAGE_DIR/$NAME/bin/yosys$EXE -cp yosys-abc$EXE_O $PACKAGE_DIR/$NAME/bin/yosys-abc$EXE +cp yosys$EXE $PACKAGE_DIR/$NAME/bin/yosys$EXE +cp yosys-abc$EXE $PACKAGE_DIR/$NAME/bin/yosys-abc$EXE cp yosys-config $PACKAGE_DIR/$NAME/bin/yosys-config -cp yosys-filterlib$EXE_O $PACKAGE_DIR/$NAME/bin/yosys-filterlib$EXE -cp yosys-smtbmc$EXE_O $PACKAGE_DIR/$NAME/bin/yosys-smtbmc$PY +cp yosys-filterlib$EXE $PACKAGE_DIR/$NAME/bin/yosys-filterlib$EXE +cp yosys-smtbmc$EXE $PACKAGE_DIR/$NAME/bin/yosys-smtbmc$EXE # -- Copy the share folder to the package folder mkdir -p $PACKAGE_DIR/$NAME/share/yosys diff --git a/scripts/install_dependencies.sh b/scripts/install_dependencies.sh index c5eb3d8..f57f7da 100755 --- a/scripts/install_dependencies.sh +++ b/scripts/install_dependencies.sh @@ -80,23 +80,8 @@ if [ $ARCH == "windows_x86" ]; then fi if [ $ARCH == "windows_amd64" ]; then - sudo DEBIAN_FRONTEND=noninteractiveapt-get install -y $base_packages \ - mingw-w64 mingw-w64-tools mingw-w64-x86-64-dev \ - zip - -# this was used to cross-compile nextpnr-ecp5 for Windows but we can't build native python libs -# for Windows with MinGW (CPython on Windows is built with MSVC) and the built python libs are run as part -# of the build process -# sudo apt-get install -y build-essential bison flex libreadline-dev \ -# gawk tcl-dev libffi-dev git mercurial graphviz \ -# xdot pkg-config python3.5-dev qt5-default libqt5opengl5-dev $BOOST \ -# gcc-5-mingw-w64 gc++-5-mingw-w64 wine libeigen3-dev qtbase5-dev libpython3.5-dev zip -# #mingw-w64 mingw-w64-tools -# sudo apt-get autoremove -y -# ln -s /usr/include/x86_64-linux-gnu/zconf.h /usr/include -# sudo update-alternatives \ -# --install /usr/bin/x86_64-w64-mingw32-gcc x86_64-w64-mingw32-gcc /usr/bin/x86_64-w64-mingw32-gcc-5 60 \ -# --slave /usr/bin/x86_64-w64-mingw32-g++ x86_64-w64-mingw32-g++ /usr/bin/x86_64-w64-mingw32-g++-5 + pacman --noconfirm --needed -S git base-devel mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake \ + mingw-w64-x86_64-boost mingw-w64-x86_64-eigen3 rsync unzip zip mingw-w64-x86_64-libftdi bison flex x86_64-w64-mingw32-gcc --version x86_64-w64-mingw32-g++ --version diff --git a/scripts/nextpnr-CMakeLists.txt b/scripts/nextpnr-CMakeLists.txt new file mode 100644 index 0000000..9bd8519 --- /dev/null +++ b/scripts/nextpnr-CMakeLists.txt @@ -0,0 +1,311 @@ +# TODO: sensible minimum CMake version +cmake_minimum_required(VERSION 3.3) +project(nextpnr) + +option(BUILD_GUI "Build GUI" ON) +option(BUILD_PYTHON "Build Python Integration" ON) +option(BUILD_TESTS "Build tests" OFF) +option(BUILD_HEAP "Build HeAP analytic placer" ON) +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_CHIPDB "Never build chipdb in parallel to reduce peak memory use" ON) + +set(Boost_NO_BOOST_CMAKE ON) + +set(link_param "") +if (STATIC_BUILD) + set(Boost_USE_STATIC_LIBS ON) + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + if (MSVC) + set(CMAKE_CXX_FLAGS_RELEASE "/MT") + set(CMAKE_CXX_FLAGS_DEBUG "/MTd") + endif() + if (BUILD_PYTHON) + add_definitions(-DBOOST_PYTHON_STATIC_LIB) + endif() + else() + set(CMAKE_FIND_LIBRARY_SUFFIXES ".a" ".so") + set(link_param "-static") + if (BUILD_PYTHON) + find_package(ZLIB) + find_package(EXPAT) + find_package(Threads) + endif() + endif() +endif() + +if (EXTERNAL_CHIPDB) + if (NOT DEFINED EXTERNAL_CHIPDB_ROOT) + message(STATUS "EXTERNAL_CHIPDB_ROOT not defined using -DEXTERNAL_CHIPDB_ROOT=/path/to/nextpnr. Default to /usr/share/nextpnr") + set(EXTERNAL_CHIPDB_ROOT "/usr/share/nextpnr") + endif() + add_definitions("-DEXTERNAL_CHIPDB_ROOT=\"${EXTERNAL_CHIPDB_ROOT}\"") +endif() + +set(PROGRAM_PREFIX "" CACHE STRING "Name prefix for executables") + +# List of families to build +set(FAMILIES generic ice40 ecp5) + +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") + foreach(item ${FAMILIES}) + message(STATUS " ${item}") + endforeach() + message(FATAL_ERROR "Architecture setting is mandatory") +endif () + +if (ARCH STREQUAL "all") + SET(ARCH ${FAMILIES}) +endif() + +foreach(item ${ARCH}) + if (NOT item IN_LIST FAMILIES) + message(FATAL_ERROR "Architecture '${item}' not in list of supported architectures") + endif() +endforeach() + +set(CMAKE_CXX_STANDARD 11) +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") +else() + set(CMAKE_CXX_FLAGS_DEBUG "-Wall -fPIC -ggdb -pipe") + if (USE_OPENMP) + set(CMAKE_CXX_FLAGS_RELEASE "-Wall -fPIC -O3 -g -pipe -fopenmp") + 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}) + +if (COVERAGE) + include(CodeCoverage) +endif() + +if(NOT DEFINED CMAKE_SUPPRESS_DEVELOPER_WARNINGS) + set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS 1 CACHE INTERNAL "No dev warnings") +endif() + +find_package(Sanitizers) + +# List of Boost libraries to include +set(boost_libs filesystem thread program_options iostreams system) + +if (BUILD_GUI AND NOT BUILD_PYTHON) + message(FATAL_ERROR "GUI requires Python to build") +endif() + +find_package(PythonInterp 3.5 REQUIRED) +if (BUILD_PYTHON) + # TODO: sensible minimum Python version + find_package(PythonLibs 3.5 REQUIRED) +else() + add_definitions("-DNO_PYTHON") +endif() + +find_package(Boost REQUIRED COMPONENTS ${boost_libs}) + +if (BUILD_GUI) + # Find the Qt5 libraries + find_package(Qt5 COMPONENTS Core Widgets OpenGL REQUIRED) + find_package(OpenGL REQUIRED) +else() + add_definitions("-DNO_GUI") +endif() + +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() + +if (BUILD_TESTS) + add_subdirectory(3rdparty/googletest/googletest ${CMAKE_CURRENT_BINARY_DIR}/generated/3rdparty/googletest EXCLUDE_FROM_ALL) + enable_testing() +endif() + +if (BUILD_GUI) + add_subdirectory(3rdparty/QtPropertyBrowser ${CMAKE_CURRENT_BINARY_DIR}/generated/3rdparty/QtPropertyBrowser EXCLUDE_FROM_ALL) +endif() + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/common/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/generated/version.h +) + +if (BUILD_PYTHON) + # Find Boost::Python of a suitable version in a cross-platform way + # Some distributions (Arch) call it libboost_python3, others such as Ubuntu + # call it libboost_python35. In the latter case we must consider all minor versions + # Original source: https://github.com/BVLC/caffe/blob/master/cmake/Dependencies.cmake#L148 + set(version ${PYTHONLIBS_VERSION_STRING}) + + STRING(REGEX REPLACE "[^0-9]" "" boost_py_version "${version}") + find_package(Boost QUIET COMPONENTS "python-py${boost_py_version}" ${boost_libs}) + set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND}) + + while (NOT "${version}" STREQUAL "" AND NOT Boost_PYTHON_FOUND) + STRING(REGEX REPLACE "([0-9.]+).[0-9]+" "\\1" version "${version}") + + STRING(REGEX REPLACE "[^0-9]" "" boost_py_version "${version}") + find_package(Boost QUIET COMPONENTS "python-py${boost_py_version}" ${boost_libs}) + set(Boost_PYTHON_FOUND ${Boost_PYTHON-PY${boost_py_version}_FOUND}) + + STRING(REGEX MATCHALL "([0-9.]+).[0-9]+" has_more_version "${version}") + if ("${has_more_version}" STREQUAL "") + break() + endif () + endwhile () + + if (NOT Boost_PYTHON_FOUND) + foreach (PyVer 3 36 37 38 39) + find_package(Boost QUIET COMPONENTS python${PyVer} ${boost_libs}) + if ("${Boost_LIBRARIES}" MATCHES ".*(python|PYTHON).*" ) + set(Boost_PYTHON_FOUND TRUE) + break() + endif () + endforeach () + endif () + + if (NOT Boost_PYTHON_FOUND) + STRING(REGEX REPLACE "([0-9]+\\.[0-9]+).*" "\\1" gentoo_version "${PYTHONLIBS_VERSION_STRING}") + find_package(Boost QUIET COMPONENTS python-${gentoo_version} ${boost_libs}) + if ("${Boost_LIBRARIES}" MATCHES ".*(python|PYTHON).*" ) + set(Boost_PYTHON_FOUND TRUE) + endif () + endif () + + if (NOT Boost_PYTHON_FOUND ) + message( FATAL_ERROR "No version of Boost::Python 3.x could be found.") + endif () +endif() + +include_directories(common/ json/ frontend/ 3rdparty/json11/ ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}) + +if(BUILD_HEAP) + find_package (Eigen3 REQUIRED NO_MODULE) + include_directories(${EIGEN3_INCLUDE_DIRS}) + add_definitions(${EIGEN3_DEFINITIONS}) + add_definitions(-DWITH_HEAP) +endif() + +aux_source_directory(common/ COMMON_SRC_FILES) +aux_source_directory(json/ JSON_PARSER_FILES) +aux_source_directory(3rdparty/json11 EXT_JSON11_FILES) +aux_source_directory(frontend/ FRONTEND_FILES) + +set(COMMON_FILES ${COMMON_SRC_FILES} ${EXT_JSON11_FILES} ${JSON_PARSER_FILES} ${FRONTEND_FILES}) +set(CMAKE_BUILD_TYPE Release) + +if(MINGW) + add_definitions("-Wa,-mbig-obj") +endif(MINGW) + +include(bba/bba.cmake) + +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} ${COMMON_FILES} ${${ufamily}_FILES}) + 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) + if (COVERAGE) + APPEND_COVERAGE_COMPILER_FLAGS() + set(COVERAGE_LCOV_EXCLUDES '/usr/include/*' '3rdparty/*' 'generated/*' 'bba/*' 'tests/*') + SETUP_TARGET_FOR_COVERAGE_LCOV( + NAME ${family}-coverage + EXECUTABLE ${PROGRAM_PREFIX}nextpnr-${family}-test + DEPENDENCIES ${PROGRAM_PREFIX}nextpnr-${family}-test + ) + endif() + + aux_source_directory(tests/${family}/ ${ufamily}_TEST_FILES) + if (BUILD_GUI) + aux_source_directory(tests/gui/ GUI_TEST_FILES) + endif() + + add_executable(${PROGRAM_PREFIX}nextpnr-${family}-test ${${ufamily}_TEST_FILES} + ${COMMON_FILES} ${${ufamily}_FILES} ${GUI_TEST_FILES}) + target_link_libraries(${PROGRAM_PREFIX}nextpnr-${family}-test PRIVATE gtest_main) + 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 + set(family_targets ${PROGRAM_PREFIX}nextpnr-${family}) + + if (BUILD_TESTS) + set(family_targets ${family_targets} ${PROGRAM_PREFIX}nextpnr-${family}-test) + endif() + + # Include the family-specific CMakeFile + include(${family}/family.cmake) + foreach (target ${family_targets}) + # Include family-specific source files to all family targets and set defines appropriately + target_include_directories(${target} PRIVATE ${family}/ ${CMAKE_CURRENT_BINARY_DIR}/generated/) + target_compile_definitions(${target} PRIVATE NEXTPNR_NAMESPACE=nextpnr_${family} ARCH_${ufamily} ARCHNAME=${family}) + target_link_libraries(${target} LINK_PUBLIC ${Boost_LIBRARIES} ${link_param}) + if (NOT MSVC) + target_link_libraries(${target} LINK_PUBLIC pthread) + endif() + add_sanitizers(${target}) + if (BUILD_GUI) + target_include_directories(${target} PRIVATE gui/${family}/ gui/) + target_compile_definitions(${target} PRIVATE QT_NO_KEYWORDS) + target_link_libraries(${target} LINK_PUBLIC gui_${family} ${GUI_LIBRARY_FILES_${ufamily}}) + endif() + if (BUILD_PYTHON) + target_link_libraries(${target} LINK_PUBLIC ${PYTHON_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() + endif() + endforeach (target) +endforeach (family) + +file(GLOB_RECURSE CLANGFORMAT_FILES *.cc *.h) +string(REGEX REPLACE "[^;]*/ice40/chipdbs/chipdb-[^;]*.cc" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}") +string(REGEX REPLACE "[^;]*/ecp5/chipdbs/chipdb-[^;]*.cc" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}") +string(REGEX REPLACE "[^;]*/3rdparty[^;]*" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}") +string(REGEX REPLACE "[^;]*/generated[^;]*" "" CLANGFORMAT_FILES "${CLANGFORMAT_FILES}") + +add_custom_target( + clangformat + COMMAND clang-format + -style=file + -i + ${CLANGFORMAT_FILES} +) diff --git a/scripts/test_bin.sh b/scripts/test_bin.sh index 0947f57..c90bc04 100755 --- a/scripts/test_bin.sh +++ b/scripts/test_bin.sh @@ -1,7 +1,6 @@ #!/bin/bash -# Test script -set -e +# Test script FILE=$1 @@ -28,7 +27,7 @@ function test_exec { } function test_static { - output=$(ldd $1 | grep "not a dynamic executable") + output=$(ldd $1 2>&1 | grep "not a dynamic executable") test_base "- 3. File is static" test -n "$output" }