The easiest way to get started developing in RevBayes is to use an IDE such as XCode or Eclipse. You can also use your favorite text editor (e.g. vim or emacs). This page will provide some helpful tips on how to set up these development enviroments. See the Download page for instructions on how to obtain the source code.
Setting up Visual Studio Code for RevBayes development
Visual Studio Code (or VSCode) is an open-source text editor by Microsoft. You can download and install it here.
You will first need to install RevBayes from source. Once RevBayes is installed you will need to open VSCode. Once VSCode is open you will need to select the RevBayes folder from wherever you have stored on your computer.
Now you will need to install three extensions to get RevBayes to work nicely. To do this click on the button shown below in VSCode.
Once here you need to search for the “C/C++ extension” , the “Cmake extension” , and the “CMake tools extension” .
Now that these are installed, Cmake tools will prompt in the lower right asking you to locate the file named CMakeLists.txt
. Choose the file located in the revbayes/src/CMakeLists.txt
location. This will prompt a choice of compiler kit this should work with clang
and gcc
. This should begin building RevBayes using CMake and a new folder should appear in revbayes
called build
. This will contain the compiled files and will eventually be added to .gitignore
if it is not currently you will need to add this to the .gitignore
file. Specifically, add build/**
and vscode/**
to .gitignore
. If the build does not start automatically click the build button (the gear icon) on the blue bar on the bottom of the screen.
Once the Cmake build finishes, you can setup debugging by clicking the triangle with the small beatle in the lower left. Now click on the gear shown below. This will open a new file called launch.json
. You need to change the values for the "program:"
object to the path where your rb
executeable is. For example, "${workspaceFolder}/projects/cmake/rb"
. In vscode ${workspaceFolder}
refers to the root folder of the project you opened. To test a specific rev script, change the value of the "args"
object to a location of a Rev script.With that you can use debugging in VSCode by pressing the play button or using the command palette (CTRL/CMD + SHIFT + P) and using the “Cmake: Debug” command.
Setting up Eclipse for RevBayes development
Eclipse is a Java-based, cross-platform IDE with lots of nice features that make it convenient for RevBayes development. First, it’s cross-platform, and unlike Xcode, you can use any compiler you like (not just clang
).
brew install cmake
)clang
(included with XCode), or you can install gcc
(e.g. via homebrew brew install gcc
).To start writing C++ in Eclipse, you must obtain the Eclipse CDT (C/C++ Development Tooling) package. You can download a distribution of Eclipse that comes prepackaged with CDT from the CDT Downloads page.
If you already have Eclipse installed you can go to Help > Install New Software… and enter the p2 repository URL for your version of eclipse found on the CDT downloads page. Then check the Main Features box, click Next twice, accept the User Agreement, and restart Eclipse.
Important! When you first open Eclipse, you will be asked to choose a location for your workspace. Make sure to choose a location that is not inside the source directory of your project!
Assuming you have cloned the RevBayes github repository into the directory <revbayes-repo>
, you can create a new C++ Eclipse project as follows:
revbayes
<revbayes-repo>/src
as the Existing Code LocationCross GCC
in Toolchain for Indexer Settings (you can change this later if you want).You will need to configure your Eclipse project so it correctly compiles the revbayes CMake project.
If you installed the CMake command line tools in the default location :/usr/local/bin
, you must add it to the PATH environment variable of your Eclipse project.
In the Project Explorer view, highlight your revbayes project directory
/usr/local/bin
to the end of the Value
The RevBayes CMake project uses a special build script build.sh
to build the RevBayes executable. You must tell your Eclipse project to use this script as a build command.
sh build.sh
../projects/cmake
to the directory path
-boost false
Configure the Debug configuration by adding -debug true
to the Build (incremental build) options
Now, if you set the active configuration to Debug, RevBayes will be compiled with debugger symbols that can be loaded by lldb
or gdb
. You can also set the active build configuration by going to Project > Build Configurations > Set Active
At this point, C/C++ Indexer will get to work indexing the RevBayes code, during which time Eclipse might appear to be unresponsive.
RevBayes code is indented using spaces. However, by default Eclipse uses tabs. Configure your project to automatically insert 4 spaces when you press the Tab key.
Spaces only
The first time you build RevBayes, you will also need to build the included Boost libraries. You only need to do this once. To build the boost libraries, return to step 5 in the build configuration section and enter -boost true
instead. Then after you’ve built the libraries, you can disable the Boost build flag by resetting -boost false
.
With all the build settings correctly configured, you can build RevBayes by highlighting the project in the Project Explorer view, and then going to Project > Build Project. You can also right click on the project directory and select Build Project.
The Console view should display the progress of the compilation process.
You’re done! Now you can find the rb
executable in the <revbayes-repo>/projects/cmake
directory.
Create a symlink of rb
in your PATH, so it is automatically updated every time you build RevBayes. e.g.
sudo ln -s <revbayes-repo>/projects/cmake/rb /usr/local/bin/rb
If your Project Explorer or Console views disappear and you can’t find them, go to Window > Show View to display various views.
Setting up XCode for RevBayes development
XCode is an IDE for Mac OSX. XCode does not keep track of files, so each time you open your RevBayes project in Xcode you must pull the RevBayes master branch from git & remove reference to all of the source. Eclipse Oxygen does a cleaner job of managing the files; you do not need to pull from git each time you work in it.
rb
and click Next. main.cpp
so that RevBayes is empty. You can do this by selecting the folders and files, right clicking and selecting delete. When asked, choose Move to Trash.revbayes/src/revlanguage
revbayes/src/core
revbayes/src/libs
brew install boost
. This will install the boost libraries in your /usr/local
directory. To enable this version in your Xcode project, scroll to the Search Paths section in the Build Settings and add the following paths:
/usr/local/include
/usr/local/lib
-lboost_program_options
, -lboost_filesystem
, -lboost_system
.
RB_XCODE
Preprocessor Macro to your Xcode projectRB_XCODE
. Do not replace the debug flag that is already present.
At this point, if everything has been setup correctly, you should be able to build the project. You can try by clicking on Product - Build or by using ⌘+B.
brew install cmake
in terminal./<path-to-revbayes>/revbayes/projects/cmake/build.sh
$(ACTION) -boost true -debug true
, or if you haven’t built the boost libraries in RevBayes already. If you have then type $(ACTION) -boost false -debug true
./<path-to-revbayes>/revbayes/projects/cmake/
.revbayes
directory:
revbayes/src/revlanguage
revbayes/src/core
revbayes/src/libs
Setting up vim for RevBayes development
Vim is a text editor that some people love. It’s not an IDE, but it can provide useful IDE-like behaviors. If you are reading this, you are probably a vim-lover and already have a set of customizations that you like. Here are some more to consider.
YouCompleteMe is an extremely useful plugin that provides suggestions as you type for function names, prompts about their arguments, etc. There are several steps to get it working.
This seems to be sufficient on Ubuntu 16.04:
sudo apt-get install build-essential cmake python-dev python3-dev clang
Grab these two plugins:
Put them wherever you put your plugins, e.g., .vim/bundle/
if you’re using Pathogen.
For YCM, you also need to get its submodules:
cd YouCompleteMe/
git submodule update --init --recursive
(If you manage your plugins as git subtrees, note that you probably can’t for YouCompleteMe because it contains submodules itself.)
YCM has a compiled component as well as vim code. This may take a few minutes to run.
cd YouCompleteMe/
./install.py --clang-completer
The above was to install YCM in general. To use it specifically with RevBayes (or any other project), you need to give it information about the codebase. YCM-Generator is one way to do this.
cd revbayes/ # or wherever you keep revbayes
cd projects/cmake/build/
~/.vim/bundle/YCM-Generator/config_gen.py . # adjust the vim path if necessary
That should take a few seconds to run. Then move the result to the top-level directory:
mv .ycm_extra_conf.py ../../../
That should be it.
If YCM is working, when you open a revbayes .cpp
or .h
file, vim will ask Found revbayes/.ycm_extra_conf.py. Load?
If you find that you don’t want YCM operating on all your other filetypes, you can put something like this in your .vimrc
.
let g:ycm_filetype_whitelist = { 'cpp': 1, 'c': 1, 'python': 1 }
If you use vim, we recommend debugging in GDB. You’ll need to compile RevBayes with the -debug true
flag:
./build.sh -debug true
The you can debug RevBayes with GDB:
gdb rb
See here for more on using GDB.