Skip to content
Armin Stebich edited this page Aug 25, 2023 · 28 revisions

Building from Source

Required libraries

  1. cairo
  2. Pango
  3. Qt 5
  4. git
  5. Google test
  6. Eigen 3
  7. Lua >= 5.3 and <= 5.3.5
  8. Curl
  9. Boost
  10. LibDxfRW (Branch LibreCAD_3; building instructions follow)
  11. rapidjson
  12. libglfw3
  13. libglm

LibDxfRW

git clone --branch LibreCAD_3 https://github.com/LibreCAD/libdxfrw
cd libdxfrw
mkdir release
cd release
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
make
sudo make install

LibreCAD

git clone --recursive https://github.com/LibreCAD/LibreCAD_3.git

cd LibreCAD_3

git submodule init

git submodule update --recursive --remote

mkdir build
cd build

# for a release you would use cmake -DCMAKE_BUILD_TYPE=Release ..
cmake .. 

make -j 4
./bin/librecad

OSX MacPorts

If you want to fool around with macports, use this to build:

mkdir build
cd build
/opt/local/bin/cmake -DCMAKE_CXX_COMPILER=/opt/local/bin/g++ -DCMAKE_C_COMPILER=/opt/local/bin/gcc ..
make -j 4
./lcUI/librecad

For a release build:

/opt/local/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=/opt/local/bin/g++ -DCMAKE_C_COMPILER=/opt/local/bin/gcc ..

macOS XCode

If you like XCode as your editor you can ask cmake to generate the build file for you.

mkdir xcode
cd build
cmake -G Xcode ..

Then open the project in XCode and build. Under some conditions, you might want to set an additional search path if libraries are not found (for example, if you compile libdxfrw yourself).

X-Code add headers

When using ports, I had to use:

cd /opt/local/include
sudo ln -sf eigen3/Eigen Eigen
sudo ln -sf eigen3/unsupported unsupported

Any cmake guru care to comment on this oddity? Is there a way to prevent making that symlink?

Debian/Ubuntu/Mint

apt-get install qttools5-dev qttools5-dev-tools libqt5opengl5-dev liblua5.3-dev git g++ libcairo2-dev libpango-1.0-0 libpango1.0-dev libboost-dev libboost-log-dev libboost-program-options-dev libqt5svg5-dev libgtest-dev libeigen3-dev libcurl4-gnutls-dev libgtk-3-dev libglew-dev rapidjson-dev libbz2-dev libglfw3-dev libglm-dev

You need to compile Google Test in /usr/src/gtest and move the libraries in /usr/lib

Windows

Note: This process will use Conan to download the dependencies. Also, it will use Visual Studio to build the project. Qt libraries are needed for its building. Chocolatey commands need the cmd with administrative privileges.

We recommend installing everything in an empty directory, so you can copy-paste the movements between directories and use the same elevated cmd unless stated otherwise in the concrete instruction.

There are steps below where you can install applications in CLI (with a cmd) or you can get it using the official installer of the application on their official website. The last step must be done in GUI (I have not found a way to build the project without it).

The following batch script (must be used in a cmd with administrator privileges, not clicked from File Explorer. Create an empty folder; create there the .bat; and move there with cd before calling it.) should be able to do all steps other than "Visual Studio CMake" (aka building the project with Visual Studio’s GUI).

We recommend looking below to understand it and be able to modify it for what you need (for example, you must create a QT account and add it to the script).

REM This script has to be used in an elevated cmd

REM Install Chocolatey

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

choco feature enable -n=allowGlobalConfirmation &::Get rid of confirmation prompts

REM Install Git

choco install git

REM Install VisualStudio with all the needed components

choco install visualstudio2019community --package-parameters='"--add Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.Windows10SDK.19041"'

REM Install Python for pip and use pip for Conan

choco install python
pip install Conan

choco feature disable -n=allowGlobalConfirmation &::Enabling again confirmation prompts

REM Cloning repository

git clone --recursive https://github.com/LibreCAD/LibreCAD_3.git
cd LibreCAD_3

REM Creating and moving to Conan dir. If it fails, modify the profile compiler version and try again

mkdir conan
cd conan
conan install ..
if NOT %errorlevel% == "0" (
conan profile update settings.compiler.version=16  default
conan install ..
)

REM Getting the Qt5 installer

cd ..\..
curl -O https://d13lb3tujbc8s0.cloudfront.net/onlineinstallers/qt-unified-windows-x86-4.3.0-1-online.exe
mkdir Qt

:: These arguments will have to be added and specified below since the license needs a Qt account.
::--email <email> --password <password>
REM Installing qt5

qt-unified-windows-x86-4.3.0-1-online.exe ^
  --accept-licenses ^
  --default-answer ^
  --accept-obligations ^
  --root "%cd%\Qt" ^
  --confirm-command install ^
  qt.qt5.5152.win64_msvc2019_64

:: directories should be dictated to the user or hardcoded as relative paths

REM Adding new env Variables and PATH appends
setx QTDIR "%cd%\Qt\5.15.2\msvc2019_64" & setx QT_QPA_PLATFORM_PLUGIN_PATH "%QTDIR%\plugins\platforms\"

:: Here can't use setx since if PATH is long, it will be truncated, therefore, Powershell
:: %cd%\Qt\5.15.2\msvc2019_64\bin is not in the wiki, I had to add it so it detected Qt5Widgets.dll

Powershell.exe -Command "[Environment]::SetEnvironmentVariable('Path', $env:Path + ';%cd%\Qt\5.15.2\msvc2019_64;%cd%\LibreCAD_3\out\build\x64-Debug\lib;%cd%\Qt\5.15.2\msvc2019_64\bin', 'User')"

:: Modify CMakeSettings Doesn't work
::copy /y CMakeSettings.json LibreCAD_3\CMakeSettings.json
REM Last step is not Automatic, Please Visit https://github.com/LibreCAD/LibreCAD_3/wiki/Building#visual-studio-cmake

If you have any error using this script, please check that the QT5 URL from where we get the installer still works, that Chocolatey installation has not changed, or that you remembered to add your QT mail account and QT password to QT installer arguments.

Chocolatey

Chocolatey is recommended. You can install most dependencies easier in a Command Line Interface, but you can skip this step and install everything from their official pages or other package managers. Just remember to add them to PATH (or to be able to open folders as projects in Visual Studio).

CLI

You will use Chocolatey to install Python, Git, and Visual Studio 2019 with Cmake, WindowsSDK, and MSVC. Feel free to skip it if you already have them.

Open cmd as administrator and write:

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Python and Connan

Cli

You will need Python to install Conan with pip.

If you have Chocolatey, you can use:

choco install python

Gui

Else you can install it in Python Downloads. Remember to add it to PATH in the installer if you do it this way.

Git

Cli

You will need Git to get LibreCAD3's source code. As with Python, you can use Chocolatey:

choco install git

Gui

Or get it from Windows git downloads. Remember to also add it to PATH in the installer.

Visual Studio

Cli

Same as before, if you have Chocolatey you can use:

choco install visualstudio2019community --package-parameters='"--add Microsoft.VisualStudio.Component.VC.CMake.Project Microsoft.VisualStudio.Component.VC.Tools.x86.x64 Microsoft.VisualStudio.Component.Windows10SDK.19041"'

Gui

Else install Visual Studio 2019 Community edition. You can choose Desktop development with C++ Workload, or only install the following individual components:

  • C++
  • CMake for Windows
  • Windows SDK

Cloning Librecad_3 repository

Cli

Note: Librecad_3 MUST be cloned recursively to pick up linked repositories. Here you will clone librecad_3 and move inside.

git clone --recursive https://github.com/LibreCAD/LibreCAD_3.git
cd LibreCAD_3

Conan

Cli

Conan is a package manager providing C++ dependencies compatible with Windows and Visual Studio which simplifies the compilation process.

Use pip (which comes with python) to install Conan:

pip install conan

Gui

Else you can download and install Conan here.

Dependencies

Cli

Download and install the dependencies. Move to the LibreCAD_3 folder, create a Conan folder, and move inside. Conan can fail to get the right compiler, so the following command will change its default compiler and try again if it fails:

mkdir conan
cd conan
conan install ..
if NOT %errorlevel% == "0" (
conan profile update settings.compiler.version=16  default
conan install ..
)

Qt

For Qt, you will need to create an account to use their open-source program. You can do it here.

You will move outside of the LibreCAD folder and get the QT installer.

Cli

Then you can try to get the installer from their release database and install it (you must put your Qt mail and Qt password in the arguments of the installer):

cd ..\..
curl -O https://d13lb3tujbc8s0.cloudfront.net/onlineinstallers/qt-unified-windows-x86-4.3.0-1-online.exe
mkdir Qt
qt-unified-windows-x86-4.3.0-1-online.exe ^
  --accept-licenses ^
  --default-answer ^
  --accept-obligations ^
  --root "%cd%\Qt" ^
  --email [email protected] ^
  --password yourQTpassword ^
  --confirm-command install ^
  qt.qt5.5152.win64_msvc2019_64 

Gui

Else you can download and install Qt5 (open source version) from:

https://www.qt.io/download-qt-installer

Qt is very large, and by default the installer may select a lot of components that we don't need in Select Components. You must select at least one version of Qt for the MSVC compiler and the correct architecture (for example: Qt 5.12.2 which is a Qt5 version).

Adding PATH and other variables to the system

Cli

If you have not moved and are still in the root directory (just outside Librecad3 folder or Qt), you can use this command to add those User variables. For PATH appends we will call PowerShell (using setx will truncate the PATH if it's long):

setx QTDIR "%cd%\Qt\5.15.2\msvc2019_64" & setx QT_QPA_PLATFORM_PLUGIN_PATH "%QTDIR%\plugins\platforms\"
Powershell.exe -Command "[Environment]::SetEnvironmentVariable('Path', $env:Path + ';%cd%\Qt\5.15.2\msvc2019_64;%cd%\LibreCAD_3\out\build\x64-Debug\lib;', 'User')"

Adding %cd%\Qt\5.15.2\msvc2019_64\bin was necessary for me using the CLI installation, though not using GUI. I guess Qt GUI adds it to the path automatically.

Gui

Go to Control Panel ▶ System and Security ▶ System ▶ Advanced system settings ▶ Advanced ▶ Environment Variables, or search in the bottom left windows icon for Edit the system environment variables.

In this window that just opened, you want to Set QT Environment. Press the New... button in the upper half and add QTDIR as Variable name and C:\Qt\5.15.2\msvc2019_64 as Variable value. (The variable value may differ, depending on where and what version of Qt you have installed.)

Also set QT_QPA_PLATFORM_PLUGIN_PATH as Variable name and %QTDIR%\plugins\platforms\ as Variable value.

Now you will need to add PATH environment variable folders for Qt bin, libdxfrw, and LibreCAD_3 lib.

This time you’ll have to search for Path on the left side of the top part of the window. Once you've found it double-click on it. In this new window, you will have to click on a space and add C:\Qt\5.15.2\msvc2019_64 and click in the next space and add C:\source\repos\LibreCAD_3\out\build\x64-Debug\lib

Visual Studio CMake

For this last step, you need to use the GUI.

GUI

Open the project in Visual Studio and configure CMake settings under Project ▶ CMake settings

Configuration name: x64-Debug

Configuration type: RelWithDebInfo (Debug won't work as Conan libraries are compiled in release mode.)

CMake command arguments, adapting to your configuration:

-DCMAKE_PREFIX_PATH=C:\Qt\5.15.2\msvc2019_64\lib\cmake

When CMake detects Conan it should set GLEW_ROOT.

Run in Visual Studio by clicking the green play button. You have to choose librecad.exe(bin\librecad.exe)

OpenGL

Some old graphics cards need OpenGL configuration:

Find opengl32sw.dll, copy to C:\source\repos\LibreCAD_3\out\build\x64-Debug\bin and set Environment:

set QT_OPENGL=desktop

If you still have errors, try downloading an OpenGL library distributor . You can use their script "perappdeploy", which will deploy all the needed openGL libraries to LibreCAD's bin folder.

Uninstall

The following is required, but be careful not to remove if required for other software on your computer:

  1. Librecad_3 repository (C:\source\repos\LibreCAD_3)
  2. conan (C:\Users\User\.conan)
  3. python may have been installed to install conan
  4. qt
  5. Visual Studio
  6. environment variables

Manual installation

Dependencies

Boost

Download prebuilt Windows binaries for Boost from:

https://sourceforge.net/projects/boost/files/boost-binaries/

Eigen 3

Download Eigen 3 zip archive from:

https://gitlab.com/libeigen/eigen

Unzip it on your disk (C:\local\eigen-3.3.7).

Qt

Download and install Qt (open source version) from:

https://www.qt.io/download

You must select at least one version of Qt for the MSVC compiler and the correct architecture.

Add to the PATH environment variable the Qt bin folder (C:\Qt\5.14.1\msvc2017_64\bin).

Lua

Download Windows binaries (dll15) here:

https://sourceforge.net/projects/luabinaries/files/5.3.5/Windows%20Libraries/Dynamic/

Unzip it on your disk (C:\local\lua-5.3.5)

GLEW

Download Windows binaries from:

glew.sourceforge.net

Unzip this archive on your disk (C:\local\glew-2.1.0)

The GLEW_ROOT environment variable (in Windows) should be set to where the archive was extracted, in this case C:\local\glew-2.1.0

Libdxfrw

Clone libdxfrw repository:

git clone --branch LibreCAD_3 https://github.com/LibreCAD/libdxfrw

Open it as a folder in Visual Studio:

  • Build all
  • Install DXFRW

Note the folder where it was installed (ex: C:\Users\...\libdxfrw\out\install\x64-Debug)

rapidjson

rapidjson is a header-only library. Download the latest release from:

https://github.com/Tencent/rapidjson/releases/tag/v1.1.0

Then unzip it to your disk.

LibreCAD

Open project as folder in Visual Studio.

In Project ▶ CMake Settings, set the following CMake options, after adapting the paths to your environment:

-DBoost_ADDITIONAL_VERSIONS=1.71.0 
-DBoost_COMPILER=-vc142 
-DBOOST_LIBRARYDIR=C:\local\boost_1_71_0\lib64-msvc-14.2 
-DEIGEN3_ROOT=C:\local\eigen-3.3.7 
-DLIBDXFRW_PATH=C:\Users\ferag\Workspace\libdxfrw\out\install\x64-Debug 
-DWITH_LIBOPENCAD=OFF
-DGLEW_INCLUDE_DIR=C:\local\glew-2.1.0\include 
-DFREETYPE_LIBRARY=C:\local\freetype-2.10.1\win64\freetype.lib 
-DCMAKE_PREFIX_PATH=C:\Qt\5.13.1\msvc2017_64\lib\cmake 
-DCMAKE_LIBRARY_PATH=C:\Qt\5.13.1\msvc2017_64\lib 
-DWITH_LUACMDINTERFACE=FALSE 
-DWITH_RENDERING_UNITTESTS=OFF 
-DWITH_CAIRO=OFF 
-DOPENGL_INCLUDE_DIR=C:\local\glm-0.9.9.6 
-DWITH_UNITTESTS=OFF

-DBoost options were added because the latest version of Boost wasn't supported by CMake. They may not be necessary anymore.

Add the folders containing the .dll files to your PATH environment variable.