From 8e7416f3fdb184e7f951be16d376207a475002d9 Mon Sep 17 00:00:00 2001 From: Koen Schmeets Date: Tue, 20 Oct 2020 09:39:26 +0200 Subject: [PATCH] Travis: Build improvements and fixes (#751) - Add OpenMP to macOS build - Use as many cores as possible in CI - Update travis osx image to xcode12.2 - Ignore .vscode folder - In `.travis/sign-macos.sh`, only create keychain when `CI` variable is present - Only run macOS deploy stage when a tag is pushed --- .gitignore | 1 + .travis.yml | 14 +++----------- .travis/build-debian.sh | 2 +- .travis/build-macos.sh | 26 +++++++++++++++++++++----- .travis/build-windows.sh | 6 +++--- .travis/install-macos.sh | 1 + .travis/sign-macos.sh | 24 +++++++++++++----------- CMakeLists.txt | 22 ++++++++++++++++++++-- src/drawentity.cpp | 10 +++++++--- src/mouse.cpp | 28 ++++++++++++++-------------- src/solvespace.h | 2 +- 11 files changed, 85 insertions(+), 51 deletions(-) diff --git a/.gitignore b/.gitignore index 5301e142..4f76b266 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ /debian/libslvs1-dev/ /obj-*/ /*.slvs +.vscode/ diff --git a/.travis.yml b/.travis.yml index b6a5ebf0..d6ac1209 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,22 +9,14 @@ jobs: - stage: test name: macOS os: osx - osx_image: xcode11.2 + osx_image: xcode12.2 install: "./.travis/install-macos.sh" script: "./.travis/build-macos.sh" - deploy: - provider: releases - api_key: - secure: dDlkIawHcODlW9B/20/cQCtzeoocvs0hKuNngRKXKqzXLWTRq33oq/B7+39tAixWbmv6exTpijiKrRNFiSCW5Z4iwHLwaRD4XJznxw63e/Hus/dxg2Tvqx7XFpkCz8mT1Z+gZQE5YxAngeZPpI/sZbZtF1UO3yH5eLeeokZ15p26ZskQUPoYuzrTgTzYL3XfpG3F+20rNBawH1ycsCTVD/08/n31d2m3CrKAsbW7er92ek6w4fzKr7NW8WeXjrPJETVpw5fQg1Od3pRGW8dPQaJcvKQEogMp8Mm0ETYd0qigg89/giBz7QwOgmAWQ4dH+DfZH4Ojl//127QztBolMvyDMQBykWrtJoGcij05sT6K2IJr2FHeUBO12MAEdjiVvhQj3DtTzjPiZAHHDBSLWxLKWWhlhHE4pq7g1MQhqXkaAHI2BLNzwLmaowbMT0bECf9yfz6xx18h6XPQFX44oOktraobVALFlyHqeKa8zdcUt22LF6uAL1m5dxL0tny3eXCIPE4UH/RZgua/cHV9G3cUvKQa/QnFSLRhvWVSbGB+7YsHouBJcsUOOW1gmd5442XuC7mpppccRldh+GSxUk6TBJRAx7TeQ0ybDUaoco9MUqp2twv3KreR2+8Q12PDaAhfQVNEGdF3wTm1sShImjCN4VN3eSLlBEbve1QRQXM= - skip_cleanup: true - file: build/bin/SolveSpace.dmg - on: - repo: solvespace/solvespace - tags: true - stage: deploy + if: tag IS present name: macOS os: osx - osx_image: xcode11.2 + osx_image: xcode12.2 install: "./.travis/install-macos.sh" script: "./.travis/build-macos.sh && ./.travis/sign-macos.sh" deploy: diff --git a/.travis/build-debian.sh b/.travis/build-debian.sh index bb678daf..007bf805 100755 --- a/.travis/build-debian.sh +++ b/.travis/build-debian.sh @@ -7,5 +7,5 @@ cd build cmake .. \ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DENABLE_SANITIZERS=ON -make VERBOSE=1 +make -j$(nproc) VERBOSE=1 make test_solvespace diff --git a/.travis/build-macos.sh b/.travis/build-macos.sh index 3e861deb..31c182b5 100755 --- a/.travis/build-macos.sh +++ b/.travis/build-macos.sh @@ -1,9 +1,25 @@ #!/bin/sh -xe -if echo $TRAVIS_TAG | grep ^v; then BUILD_TYPE=RelWithDebInfo; else BUILD_TYPE=Debug; fi +if echo $TRAVIS_TAG | grep ^v; then + BUILD_TYPE=RelWithDebInfo +else + BUILD_TYPE=Debug +fi -mkdir build +mkdir build || true cd build -cmake -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. -make -j2 -make test_solvespace + +LLVM_PREFIX=$(brew --prefix llvm@9) +export CC="${LLVM_PREFIX}/bin/clang" +export CXX="${CC}++" +export LDFLAGS="-L${LLVM_PREFIX}/lib -Wl,-rpath,${LLVM_PREFIX}/lib" \ +export CFLAGS="-I${LLVM_PREFIX}/include" +export CPPFLAGS="-I${LLVM_PREFIX}/include" + +cmake \ + -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9 \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. \ + -DENABLE_OPENMP=ON + +cmake --build . --config $BUILD_TYPE +make -j$(nproc) test_solvespace diff --git a/.travis/build-windows.sh b/.travis/build-windows.sh index e7502e6b..9cbc3897 100755 --- a/.travis/build-windows.sh +++ b/.travis/build-windows.sh @@ -9,8 +9,8 @@ mkdir build cd build cmake .. -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=$BUILD_TYPE -MSBuild.exe "src/solvespace.vcxproj" -MSBuild.exe "src/solvespace-cli.vcxproj" -MSBuild.exe "test/solvespace-testsuite.vcxproj" +MSBuild.exe "src/solvespace.vcxproj" -maxcpucount +MSBuild.exe "src/solvespace-cli.vcxproj" -maxcpucount +MSBuild.exe "test/solvespace-testsuite.vcxproj" -maxcpucount bin/$BUILD_TYPE/solvespace-testsuite.exe diff --git a/.travis/install-macos.sh b/.travis/install-macos.sh index 0c6a6e7c..d4817455 100755 --- a/.travis/install-macos.sh +++ b/.travis/install-macos.sh @@ -1,3 +1,4 @@ #!/bin/sh -xe +brew install llvm@9 git submodule update --init \ No newline at end of file diff --git a/.travis/sign-macos.sh b/.travis/sign-macos.sh index da90ec21..6c0fd1b5 100755 --- a/.travis/sign-macos.sh +++ b/.travis/sign-macos.sh @@ -6,21 +6,23 @@ app="bin/SolveSpace.app" dmg="bin/SolveSpace.dmg" bundle_id="com.solvespace.solvespace" -# get the signing certificate (this is the Developer ID:Application: Your Name, exported to a p12 file, then converted to base64, e.g.: cat ~/Desktop/certificate.p12 | base64 | pbcopy) -echo $MACOS_CERTIFICATE_P12 | base64 --decode > certificate.p12 +if [ "$CI" = "true" ]; then + # get the signing certificate (this is the Developer ID:Application: Your Name, exported to a p12 file, then converted to base64, e.g.: cat ~/Desktop/certificate.p12 | base64 | pbcopy) + echo $MACOS_CERTIFICATE_P12 | base64 --decode > certificate.p12 -# create a keychain -security create-keychain -p secret build.keychain -security default-keychain -s build.keychain -security unlock-keychain -p secret build.keychain + # create a keychain + security create-keychain -p secret build.keychain + security default-keychain -s build.keychain + security unlock-keychain -p secret build.keychain -# import the key -security import certificate.p12 -k build.keychain -P $MACOS_CERTIFICATE_PASSWORD -T /usr/bin/codesign + # import the key + security import certificate.p12 -k build.keychain -P $MACOS_CERTIFICATE_PASSWORD -T /usr/bin/codesign -security set-key-partition-list -S apple-tool:,apple: -s -k secret build.keychain + security set-key-partition-list -S apple-tool:,apple: -s -k secret build.keychain -# check if all is good -security find-identity -v + # check if all is good + security find-identity -v +fi # sign the .app codesign -s "${MACOS_DEVELOPER_ID}" --timestamp --options runtime -f --deep "${app}" diff --git a/CMakeLists.txt b/CMakeLists.txt index 836c58a0..ed4f673c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,9 +106,27 @@ if(ENABLE_LTO) endif() if(ENABLE_OPENMP) - include(FindOpenMP) - if(OpenMP_FOUND) + if(APPLE) + # OpenMP does not work with the default Apple llvm/clang++ + # Install a more recent version using Homebrew (version 11.0.0 which is the next available tag on homebrew at this time crashed): + # "brew install llvm@9" + # and set the right compiler flags using: + # LLVM_PREFIX=$(brew --prefix llvm@9) + # export CC="${LLVM_PREFIX}/bin/clang" + # export CXX="${CC}++" + # export LDFLAGS="-L${LLVM_PREFIX}/lib -Wl,-rpath,${LLVM_PREFIX}/lib" \ + # export CFLAGS="-I${LLVM_PREFIX}/include" + # export CPPFLAGS="-I${LLVM_PREFIX}/include" + set(OpenMP_CXX_FLAGS "-fopenmp=libomp") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + message(STATUS "found OpenMP, compiling with flags: " ${OpenMP_CXX_FLAGS} ) + else() + find_package( OpenMP REQUIRED ) + include(FindOpenMP) + if(OPENMP_FOUND) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + message(STATUS "found OpenMP, compiling with flags: " ${OpenMP_CXX_FLAGS} ) + endif() endif() endif() diff --git a/src/drawentity.cpp b/src/drawentity.cpp index d6797661..fab40713 100644 --- a/src/drawentity.cpp +++ b/src/drawentity.cpp @@ -315,9 +315,13 @@ void Entity::ComputeInterpolatingSpline(SBezierList *sbl, bool periodic) const { } else { // The wrapping would work, except when n = 1 and everything // wraps to zero... - if(i > 0) bm.A[i][i - 1] = eq.x; - /**/ bm.A[i][i] = eq.y; - if(i < (n-1)) bm.A[i][i + 1] = eq.z; + if(i > 0) { + bm.A[i][i - 1] = eq.x; + } + bm.A[i][i] = eq.y; + if(i < (n-1)) { + bm.A[i][i + 1] = eq.z; + } } } bm.Solve(); diff --git a/src/mouse.cpp b/src/mouse.cpp index 7f90a8a3..699f3e26 100644 --- a/src/mouse.cpp +++ b/src/mouse.cpp @@ -624,24 +624,24 @@ void GraphicsWindow::MouseRightUp(double x, double y) { } if(gs.withEndpoints > 0) { menu->AddItem(_("Select Edge Chain"), - [this]() { MenuEdit(Command::SELECT_CHAIN); }); + []() { MenuEdit(Command::SELECT_CHAIN); }); } if(gs.constraints == 1 && gs.n == 0) { Constraint *c = SK.GetConstraint(gs.constraint[0]); if(c->HasLabel() && c->type != Constraint::Type::COMMENT) { menu->AddItem(_("Toggle Reference Dimension"), - []() { Constraint::MenuConstrain(Command::REFERENCE); }); + []() { Constraint::MenuConstrain(Command::REFERENCE); }); } if(c->type == Constraint::Type::ANGLE || - c->type == Constraint::Type::EQUAL_ANGLE) + c->type == Constraint::Type::EQUAL_ANGLE) { menu->AddItem(_("Other Supplementary Angle"), - []() { Constraint::MenuConstrain(Command::OTHER_ANGLE); }); + []() { Constraint::MenuConstrain(Command::OTHER_ANGLE); }); } } if(gs.constraintLabels > 0 || gs.points > 0) { menu->AddItem(_("Snap to Grid"), - [this]() { MenuEdit(Command::SNAP_TO_GRID); }); + []() { MenuEdit(Command::SNAP_TO_GRID); }); } if(gs.points == 1 && gs.point[0].isFromRequest()) { @@ -714,7 +714,7 @@ void GraphicsWindow::MouseRightUp(double x, double y) { } if(gs.entities == gs.n) { menu->AddItem(_("Toggle Construction"), - [this]() { MenuRequest(Command::CONSTRUCTION); }); + []() { MenuRequest(Command::CONSTRUCTION); }); } if(gs.points == 1) { @@ -748,28 +748,28 @@ void GraphicsWindow::MouseRightUp(double x, double y) { menu->AddSeparator(); if(LockedInWorkplane()) { menu->AddItem(_("Cut"), - [this]() { MenuClipboard(Command::CUT); }); + []() { MenuClipboard(Command::CUT); }); menu->AddItem(_("Copy"), - [this]() { MenuClipboard(Command::COPY); }); + []() { MenuClipboard(Command::COPY); }); } } else { menu->AddItem(_("Select All"), - [this]() { MenuEdit(Command::SELECT_ALL); }); + []() { MenuEdit(Command::SELECT_ALL); }); } if((!SS.clipboard.r.IsEmpty() || !SS.clipboard.c.IsEmpty()) && LockedInWorkplane()) { menu->AddItem(_("Paste"), - [this]() { MenuClipboard(Command::PASTE); }); + []() { MenuClipboard(Command::PASTE); }); menu->AddItem(_("Paste Transformed..."), - [this]() { MenuClipboard(Command::PASTE_TRANSFORM); }); + []() { MenuClipboard(Command::PASTE_TRANSFORM); }); } if(itemsSelected) { menu->AddItem(_("Delete"), - [this]() { MenuClipboard(Command::DELETE); }); + []() { MenuClipboard(Command::DELETE); }); menu->AddSeparator(); menu->AddItem(_("Unselect All"), - [this]() { MenuEdit(Command::UNSELECT_ALL); }); + []() { MenuEdit(Command::UNSELECT_ALL); }); } // If only one item is selected, then it must be the one that we just // selected from the hovered item; in which case unselect all and hovered @@ -785,7 +785,7 @@ void GraphicsWindow::MouseRightUp(double x, double y) { if(itemsSelected) { menu->AddSeparator(); menu->AddItem(_("Zoom to Fit"), - [this]() { MenuView(Command::ZOOM_TO_FIT); }); + []() { MenuView(Command::ZOOM_TO_FIT); }); } menu->PopUp(); diff --git a/src/solvespace.h b/src/solvespace.h index 1157723a..d0fde5f5 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -513,7 +513,7 @@ public: GraphicsWindow GW; // The state for undo/redo - typedef struct { + typedef struct UndoState { IdList group; List
groupOrder; IdList request;