Difference between revisions of "Compiling"

From BRL-CAD
(Obtain Dev Tools)
(cmake 3.18 now)
 
(54 intermediate revisions by 10 users not shown)
Line 1: Line 1:
 
= Compiling BRL-CAD =
 
= Compiling BRL-CAD =
  
BRL-CAD source files contain an [http://brlcad.svn.sourceforge.net/viewvc/brlcad/brlcad/trunk/INSTALL INSTALL] file with general instructions.  This page contains simplified tips for building '''''quickly'''''.
+
This page has simplified steps for building '''''quickly'''''.  See [https://github.com/BRL-CAD/brlcad/blob/main/INSTALL INSTALL] for more detailed instruction.
  
== Obtain Dev Tools ==
 
  
If you downloaded the virtual machine disk image, YOU DON'T NEED TO INSTALL ANYTHING ELSE.  Skip this step.
+
== Step 1: Install Dev Tools ==
  
BRL-CAD uses the CMake build system and will compile with most compilers, so first up is to [http://www.cmake.org/cmake/resources/software.html download and install it].  If needed, compiling from their source distribution is actually very easy.
+
To build, you want the latest [https://cmake.org/download/ CMake], a recent compiler, and at least 3GB of disk space.  You will also want [https://git-scm.com/downloads/guis Git] to obtain the latest source code.
  
If you're on some other Debian/Ubuntu system, you can install pretty much everything you might want with aptitude:
+
* Minimum versions:
 +
** CMake must be 3.18 or later
 +
** Git must be 2.17 or later
 +
** Compiler must be C++11-compliant
 +
*** If using Visual Studio, version 2015 (14.0+) or later
 +
*** If using GCC/G++, version 4.8.1 or later
 +
*** If using LLVM/Clang 3.3 or later
 +
*** If using Intel, version 2015 (15.0+) or later
 +
 
 +
 
 +
* '''Windows''': Install [https://gitforwindows.org Git], [https://cmake.org/download/ CMake], and [https://visualstudio.microsoft.com/vs/community/ Visual Studio Community] or Professional.  VS Code should also work, but you will need to install the "[https://visualstudio.microsoft.com/downloads/ Build Tools for Visual Studio]" also.
 +
 
 +
 
 +
* '''Mac''': Install [https://cmake.org/download/ CMake] and XCode or run this in Terminal: <pre>xcode-select --install</pre>
 +
 
 +
 
 +
* '''Linux''' and Windows Subsystem for Linux ('''WSL'''):
 +
 
 +
Installing is easiest with a package management system like apt, brew, yum, and dnf that install for you.  Alas, the tools and names change frequently, so the following are platform-specific recommendations that may need to be adjusted for your system.
 +
 
 +
** WSL: You should be good to go.
 +
 
 +
** Debian/Ubuntu: <pre>apt install build-essential make cmake</pre>
 +
 
 +
If you're on an older distribution, you may need to manually install a more recent version of cmake. 
 +
 
 +
** Fedora: <pre>yum install clang++ make cmake</pre>
 +
 
 +
** CentOS: <pre>yum install python3-pip devtoolset-9</pre><pre>pip3 install cmake</pre><pre>scl enable devtoolset-9 bash</pre>
 +
 
 +
 
 +
* BSD: we assume you know what you're doing and can follow the gist
 +
 
 +
== Step 2: Install Dependencies ==
 +
 
 +
* '''Windows''': You can skip this step.
 +
 
 +
* '''Mac''': Install the latest [https://www.xquartz.org XQuartz]
 +
 
 +
* '''Linux''': BRL-CAD needs the Xorg development packages
 +
 
 +
** Debian/Ubuntu: <pre>apt install libc6-dev libfreetype-dev libfontconfig-dev</pre><pre>apt install xserver-xorg-dev libx11-dev libxi-dev libglu1-mesa-dev</pre>
 +
 
 +
** Fedora: <pre>yum install freetype-devel fontconfig-devel</pre><pre>yum install libX11-devel libXext-devel libXi-devel mesa-libGL-devel</pre>
 +
 
 +
== Step 3: Download BRL-CAD ==
 +
 
 +
We recommend obtaining BRL-CAD by forking or cloning our repository on [https://github.com/BRL-CAD/brlcad GitHub].
 +
 
 +
* '''Windows''': If you're going to build with Visual Studio, run Git GUI specifying this repository to clone: <pre>https://github.com/BRL-CAD/brlcad.git</pre>.  If you're building under WSL, clone from the git-bash command line.
 +
 
 +
* '''Mac''': You can either run the Git GUI, or you can run this in Terminal: <pre>git clone https://github.com/BRL-CAD/brlcad.git</pre>
 +
 
 +
* '''Linux''' and '''WSL''': <pre>git clone https://github.com/BRL-CAD/brlcad.git</pre>
 +
 
 +
The "brlcad" folder created after cloning is a full source checkout of BRL-CAD and contains a README with additional info.  If you run into trouble cloning from git, snapshot source releases [https://sourceforge.net/projects/brlcad/files/BRL-CAD%20Source/ are available].
 +
 
 +
 
 +
== Step 4: Create a Build directory ==
 +
 
 +
You can create a build folder anywhere, but it's typically named "build" and is in or near your "brlcad" source directory.
 +
 
 +
* '''Windows''': create a folder named "build" inside your "brlcad" folder
 +
 
 +
* '''Mac''', '''Linux''': <pre>mkdir -p brlcad/build</pre>
  
<pre>
 
aptitude install build-essential make cmake
 
aptitude install sed byacc flex xsltproc
 
aptitude install libncursesw5-dev libfontconfig-dev
 
aptitude install xserver-xorg-dev
 
aptitude install libx11-dev libxi-dev libxt-dev libxau-dev libxext-dev libxmu-dev libxmu-headers
 
aptitude install libtnt-dev libpng12-dev zlib1g-dev libsm-dev tcl8.5-dev tk8.5-dev itcl3-dev
 
</pre>
 
  
If you're on a Mac or Windows, you just need to install CMake and developer tools.
+
== Step 5: Configure ==
  
== Download BRL-CAD ==
+
It's first recommended during configure and compilation that you temporarily suspend any anti-virus software as they're notorious for issuing false-positives alerts and blocking necessary operations.  Some BRL-CAD tools use temporary network ports that will need to be allowed as well, if prompted.
  
Release sources may be obtained from [https://sourceforge.net/projects/brlcad/files/BRL-CAD%20Source/ Sourceforge] or directory from Subversion:
+
Next, you'll run CMake to configure and generate a build system.
  
If you downloaded the virtual machine disk image, WE ALREADY DID THIS FOR YOUSee the brlcad.svn directory.
+
CMake needs to know the top-level source dir (i.e., "brlcad" dir you cloned) and "build" dir you made are locatedFor your first time, we also recommend setting these CMake variables to avoid trivial issues:
 +
  BRLCAD_ENABLE_STRICT=OFF
 +
  BRLCAD_ENABLE_COMPILER_WARNINGS=OFF
 +
  BRLCAD_BUNDLED_LIBS=ON
  
<pre>
+
* '''Windows''': you can use CMake GUI where you'll specify 1) your source dir (i.e. path to the "brlcad" folder that has README), 2) the build dir, and 3) variables.  CMake does not display variables the first time you run, but you can "+ Add Entry" to add them or run "Configure" to list them. Once dirs and variables are set, run "Configure" again and finally "Generate" to create a Visual Studio build system. [[File:Running_cmake_on_windows.png|200px|thumb|right|Running CMake GUI on Windows]]
svn checkout https://brlcad.svn.sourceforge.net/svnroot/brlcad/brlcad/trunk brlcad
 
cd brlcad
 
</pre>
 
  
== Configure ==
+
* '''Mac''': You can either run CMake GUI like described for Windows, specifying your source dir, build dir, and the above variables, or you can follow the steps below for Linux in Terminal.
  
Next, we set up a build directory and configure our compilation. BRL-CAD adhere's to a high conformance standard and considers most warnings as errors, so we turn off that strict behavior just so the build doesn't halt on trivialities.
+
* '''Linux''': <pre>cd brlcad/build</pre><pre>cmake .. -DBRLCAD_ENABLE_STRICT=NO -DBRLCAD_BUNDLED_LIBS=ON -DCMAKE_BUILD_TYPE=Release</pre>
  
We could add -DCMAKE_BUILD_TYPE=Release to get an optimized build or -DCMAKE_BUILD_TYPE=Debug to get one better suited for development work.
+
See [https://github.com/BRL-CAD/brlcad/blob/main/INSTALL INSTALL] for more CMake options.
  
<pre>
+
If CMake was successful, there will be a summary of the build printed at the end, it will say "Configured", and then "Generated" after a build system is finally done being written out for compiling BRL-CAD.
mkdir .build
 
cd .build
 
cmake .. -DBRLCAD_ENABLE_STRICT=OFF
 
</pre>
 
  
== Compile ==
+
If CMake was unsuccessful, scan the output for any error messages indicating what is failing or missing as it's typically a missing tool, missing library, or erroneous setting.
  
Compilation will usually take anywhere from a couple minutes to an hour depending on your hardware.  If you had a quad-core CPU, you might run '"make -j4" to request compiling in parallel.
+
== Step 6: Compile ==
  
<pre>
+
'''Windows''': navigate to your build directory and open the BRLCAD.sln file with Visual Studio. You can ignore any warning about a duplicate "regress" target.  Compile the default ALL_BUILD solution.
make
 
make test
 
</pre>
 
  
We run make test to see if all went well.  If the build fails, it can be helpful to run make again capturing output to a log file.  E.g., make > build.log 2>&1
+
'''Mac''', '''Linux''': while still in the build directory from Step 4, run <pre>make</pre>.  If you have multiple cores, you can alternatively compile in parallel specifying a desire number of cores, e.g., <pre>make -j10</pre>
  
== Install ==
+
If the build fails, re-run while capturing all output to a log: make 2>&1 | tee build.log
 +
Please [https://github.com/BRL-CAD/brlcad/issues report] any build failures.
  
Depending on the version of sources you start with, BRL-CAD should install into /usr/brlcad/SUBDIR where SUBDIR is rel-VERSION or dev-VERSION.  
+
Note: Compilation can take anywhere from a couple minutes to an hour depending on hardware.  If you had a quad-core CPU, you might run '"make -j4" to speed things up by compiling in parallel.
  
<pre>
 
sudo make install
 
ls -la /usr/brlcad
 
/usr/brlcad/*/bin/mged
 
</pre>
 
  
== Quick test ==
+
== Step 7: Run! ==
  
You don't have to install, though, and can just run binaries that are in the brlcad/.build/bin directory.
+
You don't have to install to run BRL-CAD.  You can run the binaries you just compiled as they are in the brlcad/build/bin directory. On Windows, they can be in Debug/ or Release/ folders.  Of the  hundreds of tools in BRL-CAD, here's just a few to get you started:
  
 
<pre>
 
<pre>
bin/benchmark
+
bin/benchmark run
 
bin/mged
 
bin/mged
 +
bin/archer
 
</pre>
 
</pre>
  
That's it!  If you have a Release compile, you can submit your benchmark results to benchmark at brlcad dot org. Be sure to check out the extensive [[Documentation]] and [[Main_Page]] for tutorials and [[Contributor Quickies]] for ways to get involved!
+
The first command (benchmark) will evaluate system performance and you can send results to benchmark at brlcad dot org.
 +
 
 +
The second command (mged) is BRL-CAD's main graphical user interface application.
 +
 
 +
The third command (archer) is BRL-CAD's newer graphical interface under development.
 +
 
 +
= What next? =
 +
 
 +
Be sure to check out the [[Documentation|docs]] and [[Main_Page]] for tutorials and more.
 +
 
 +
Help make BRL-CAD better!  There are many ways you can contribute to open source and you don't need to be an experienced programmer.  We need artists, writers, designers, software developers, and managers.  Contact us on [[IRC]].
 +
 
 +
Please [https://github.com/BRL-CAD/brlcad/issues report] any build failures.
 +
 
 +
See [[Deuces]] for really easy ways to get started!

Latest revision as of 02:44, 4 October 2022

Compiling BRL-CAD[edit]

This page has simplified steps for building quickly. See INSTALL for more detailed instruction.


Step 1: Install Dev Tools[edit]

To build, you want the latest CMake, a recent compiler, and at least 3GB of disk space. You will also want Git to obtain the latest source code.

  • Minimum versions:
    • CMake must be 3.18 or later
    • Git must be 2.17 or later
    • Compiler must be C++11-compliant
      • If using Visual Studio, version 2015 (14.0+) or later
      • If using GCC/G++, version 4.8.1 or later
      • If using LLVM/Clang 3.3 or later
      • If using Intel, version 2015 (15.0+) or later



  • Mac: Install CMake and XCode or run this in Terminal:
    xcode-select --install


  • Linux and Windows Subsystem for Linux (WSL):

Installing is easiest with a package management system like apt, brew, yum, and dnf that install for you. Alas, the tools and names change frequently, so the following are platform-specific recommendations that may need to be adjusted for your system.

    • WSL: You should be good to go.
    • Debian/Ubuntu:
      apt install build-essential make cmake

If you're on an older distribution, you may need to manually install a more recent version of cmake.

    • Fedora:
      yum install clang++ make cmake
    • CentOS:
      yum install python3-pip devtoolset-9
      pip3 install cmake
      scl enable devtoolset-9 bash


  • BSD: we assume you know what you're doing and can follow the gist

Step 2: Install Dependencies[edit]

  • Windows: You can skip this step.
  • Linux: BRL-CAD needs the Xorg development packages
    • Debian/Ubuntu:
      apt install libc6-dev libfreetype-dev libfontconfig-dev
      apt install xserver-xorg-dev libx11-dev libxi-dev libglu1-mesa-dev
    • Fedora:
      yum install freetype-devel fontconfig-devel
      yum install libX11-devel libXext-devel libXi-devel mesa-libGL-devel

Step 3: Download BRL-CAD[edit]

We recommend obtaining BRL-CAD by forking or cloning our repository on GitHub.

  • Windows: If you're going to build with Visual Studio, run Git GUI specifying this repository to clone:
    https://github.com/BRL-CAD/brlcad.git
    . If you're building under WSL, clone from the git-bash command line.
  • Mac: You can either run the Git GUI, or you can run this in Terminal:
    git clone https://github.com/BRL-CAD/brlcad.git
  • Linux and WSL:
    git clone https://github.com/BRL-CAD/brlcad.git

The "brlcad" folder created after cloning is a full source checkout of BRL-CAD and contains a README with additional info. If you run into trouble cloning from git, snapshot source releases are available.


Step 4: Create a Build directory[edit]

You can create a build folder anywhere, but it's typically named "build" and is in or near your "brlcad" source directory.

  • Windows: create a folder named "build" inside your "brlcad" folder
  • Mac, Linux:
    mkdir -p brlcad/build


Step 5: Configure[edit]

It's first recommended during configure and compilation that you temporarily suspend any anti-virus software as they're notorious for issuing false-positives alerts and blocking necessary operations. Some BRL-CAD tools use temporary network ports that will need to be allowed as well, if prompted.

Next, you'll run CMake to configure and generate a build system.

CMake needs to know the top-level source dir (i.e., "brlcad" dir you cloned) and "build" dir you made are located. For your first time, we also recommend setting these CMake variables to avoid trivial issues:

 BRLCAD_ENABLE_STRICT=OFF
 BRLCAD_ENABLE_COMPILER_WARNINGS=OFF
 BRLCAD_BUNDLED_LIBS=ON
  • Windows: you can use CMake GUI where you'll specify 1) your source dir (i.e. path to the "brlcad" folder that has README), 2) the build dir, and 3) variables. CMake does not display variables the first time you run, but you can "+ Add Entry" to add them or run "Configure" to list them. Once dirs and variables are set, run "Configure" again and finally "Generate" to create a Visual Studio build system.
    Running CMake GUI on Windows
  • Mac: You can either run CMake GUI like described for Windows, specifying your source dir, build dir, and the above variables, or you can follow the steps below for Linux in Terminal.
  • Linux:
    cd brlcad/build
    cmake .. -DBRLCAD_ENABLE_STRICT=NO -DBRLCAD_BUNDLED_LIBS=ON -DCMAKE_BUILD_TYPE=Release

See INSTALL for more CMake options.

If CMake was successful, there will be a summary of the build printed at the end, it will say "Configured", and then "Generated" after a build system is finally done being written out for compiling BRL-CAD.

If CMake was unsuccessful, scan the output for any error messages indicating what is failing or missing as it's typically a missing tool, missing library, or erroneous setting.

Step 6: Compile[edit]

Windows: navigate to your build directory and open the BRLCAD.sln file with Visual Studio. You can ignore any warning about a duplicate "regress" target. Compile the default ALL_BUILD solution.

Mac, Linux: while still in the build directory from Step 4, run

make

. If you have multiple cores, you can alternatively compile in parallel specifying a desire number of cores, e.g.,

make -j10

If the build fails, re-run while capturing all output to a log: make 2>&1 | tee build.log Please report any build failures.

Note: Compilation can take anywhere from a couple minutes to an hour depending on hardware. If you had a quad-core CPU, you might run '"make -j4" to speed things up by compiling in parallel.


Step 7: Run![edit]

You don't have to install to run BRL-CAD. You can run the binaries you just compiled as they are in the brlcad/build/bin directory. On Windows, they can be in Debug/ or Release/ folders. Of the hundreds of tools in BRL-CAD, here's just a few to get you started:

bin/benchmark run
bin/mged
bin/archer

The first command (benchmark) will evaluate system performance and you can send results to benchmark at brlcad dot org.

The second command (mged) is BRL-CAD's main graphical user interface application.

The third command (archer) is BRL-CAD's newer graphical interface under development.

What next?[edit]

Be sure to check out the docs and Main_Page for tutorials and more.

Help make BRL-CAD better! There are many ways you can contribute to open source and you don't need to be an experienced programmer. We need artists, writers, designers, software developers, and managers. Contact us on IRC.

Please report any build failures.

See Deuces for really easy ways to get started!