From ac0d0fc241336486e66a353e7f76f18d55e2865e Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 15 Aug 2019 10:36:38 +0800 Subject: [PATCH 1/4] cmake: fix static build on Windows On Windows, we can make a static build by setting the triple to x64-windows-static, but due to some issues with cmake we also need to modify the linker flags and Python definitions. Signed-off-by: Sean Cross --- CMakeLists.txt | 9 ++++++++- README.md | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c58104de..c808572d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,14 @@ option(SERIALIZE_CHIPDB "Never build chipdb in parallel to reduce peak memory us set(link_param "") if (STATIC_BUILD) set(Boost_USE_STATIC_LIBS ON) - if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(CMAKE_CXX_FLAGS_RELEASE "/MT") + set(CMAKE_CXX_FLAGS_DEBUG "/MTd") + if (BUILD_PYTHON) + add_definitions(-DBOOST_PYTHON_STATIC_LIB) + endif() + else() set(link_param "-static") endif() endif() diff --git a/README.md b/README.md index 953d6ef7..10e3bdef 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ of the selected architecture: - For building on Windows with MSVC, usage of vcpkg is advised for dependency installation. - For 32 bit builds: `vcpkg install boost-filesystem boost-program-options boost-thread boost-python qt5-base eigen3` - For 64 bit builds: `vcpkg install boost-filesystem:x64-windows boost-program-options:x64-windows boost-thread:x64-windows boost-python:x64-windows qt5-base:x64-windows eigen3:x64-windows` + - For static builds, add `-static` to each of the package names. For example, change `eigen3:x64-windows` to `eigen3:x64-windows-static` - A copy of Python that matches the version in vcpkg (currently Python 3.6.4). You can download the [Embeddable Zip File](https://www.python.org/downloads/release/python-364/) and extract it. You may need to extract `python36.zip` within the embeddable zip file to a new directory called "Lib". - For building on macOS, brew utility is needed. - Install all needed packages `brew install cmake python boost boost-python3 qt5 eigen` @@ -72,6 +73,8 @@ cmake -DARCH=ice40 -DICEBOX_ROOT=C:/ProgramData/icestorm/share/icebox -DCMAKE_TO cmake --build . --config Release ``` +To build a static release, change the target triplet from `x64-windows` to `x64-windows-static` and add `-DBUILD_STATIC=ON`. + A simple example that runs on the iCEstick dev board can be found in `ice40/examples/blinky/blinky.*`. Usage example: From 0b5c0bd94e19bbd268d9af956c51e804d4661ddf Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 15 Aug 2019 12:59:00 +0800 Subject: [PATCH 2/4] cmake: fix static build on windows On Windows, we can make a static build by setting the triple to x64-windows-static, but due to some issues with cmake we also need to modify the linker flags and Python definitions. Signed-off-by: Sean Cross --- CMakeLists.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c58104de..c808572d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,14 @@ option(SERIALIZE_CHIPDB "Never build chipdb in parallel to reduce peak memory us set(link_param "") if (STATIC_BUILD) set(Boost_USE_STATIC_LIBS ON) - if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + set(CMAKE_CXX_FLAGS_RELEASE "/MT") + set(CMAKE_CXX_FLAGS_DEBUG "/MTd") + if (BUILD_PYTHON) + add_definitions(-DBOOST_PYTHON_STATIC_LIB) + endif() + else() set(link_param "-static") endif() endif() From aa7e20357f4676274067247cfd5322219a790649 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 15 Aug 2019 12:59:27 +0800 Subject: [PATCH 3/4] README: add a note about static windows builds Windows has different triples when building with static. Note this in the README. Signed-off-by: Sean Cross --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 953d6ef7..10e3bdef 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ of the selected architecture: - For building on Windows with MSVC, usage of vcpkg is advised for dependency installation. - For 32 bit builds: `vcpkg install boost-filesystem boost-program-options boost-thread boost-python qt5-base eigen3` - For 64 bit builds: `vcpkg install boost-filesystem:x64-windows boost-program-options:x64-windows boost-thread:x64-windows boost-python:x64-windows qt5-base:x64-windows eigen3:x64-windows` + - For static builds, add `-static` to each of the package names. For example, change `eigen3:x64-windows` to `eigen3:x64-windows-static` - A copy of Python that matches the version in vcpkg (currently Python 3.6.4). You can download the [Embeddable Zip File](https://www.python.org/downloads/release/python-364/) and extract it. You may need to extract `python36.zip` within the embeddable zip file to a new directory called "Lib". - For building on macOS, brew utility is needed. - Install all needed packages `brew install cmake python boost boost-python3 qt5 eigen` @@ -72,6 +73,8 @@ cmake -DARCH=ice40 -DICEBOX_ROOT=C:/ProgramData/icestorm/share/icebox -DCMAKE_TO cmake --build . --config Release ``` +To build a static release, change the target triplet from `x64-windows` to `x64-windows-static` and add `-DBUILD_STATIC=ON`. + A simple example that runs on the iCEstick dev board can be found in `ice40/examples/blinky/blinky.*`. Usage example: From 8b63de9e552ff2b991e047723ea715b4b7d99575 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 15 Aug 2019 16:28:03 +0800 Subject: [PATCH 4/4] cmake: static: add msvc check before adding msvc flags When building with STATIC_BUILD=ON, different flags need to be specified when using MSVC. Check for this flag and only set them if necessary. Signed-off-by: Sean Cross --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c808572d..f662dbe7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ set(link_param "") if (STATIC_BUILD) set(Boost_USE_STATIC_LIBS ON) if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows") + elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows" AND MSVC) set(CMAKE_CXX_FLAGS_RELEASE "/MT") set(CMAKE_CXX_FLAGS_DEBUG "/MTd") if (BUILD_PYTHON)