Difference between revisions of "How to use CLion with our software"

From OPeNDAP Documentation
m (Open a directory that contains code)
m (Setting up Custom Build Applications)
Line 40: Line 40:
  
 
=== Setting up Custom Build Applications ===
 
=== Setting up Custom Build Applications ===
This is tricky because you have to do two steps here, one is to set up a ''Custom Build Target'' and the second is to set up a ''Custom Build Application.'' The Target is needed for the Application to be valid, and for things like the BES, the Target works to build the code. But, for libdap, the Target will only build the code if bison 3.x is installed in a directory on your '''default PATH.''' If not, then the Target described here won't work (but is still required as a placeholder. The general rule is that the Target only works with all of the tools needed for the build are on the PATH that is used when the OS starts CLion.
+
This is tricky because you have to do two steps here, one is to set up a ''Custom Build Target'' and the second is to set up a ''Custom Build Application.'' The Target is needed for the Application to be valid, and for things like the BES, the Target also works to build the code. But, for libdap, the Target will only build the code if bison 3.x is installed in a directory on your '''default PATH.''' If not, then the Target described here won't work (but is '''still''' required as a placeholder). The general rule is that the Target only works with all of the tools needed for the build are on the PATH that is used when the OS starts CLion.
 +
 
 +
Here's what to do. Open the ''Edit Configurations...'' dialog using the ''Run'' menu (there is also an option to open this from the Run menu's ''Run...'' item).
 +
[[File:Run menu 2019-10-10 at 09.49.36.png|480px|border|Run Menu]]
  
 
== Running the debugger ==
 
== Running the debugger ==

Revision as of 18:42, 15 October 2019

Setting up CLion to work with our software is really the same as using CLion with a 'Makefile' project. By default, CLion uses CMake to to figure out which files are part of a program or library. The problem for our software, and any software that does not use CMake, is that most of the benefit(s) of CLion (or any IDE) depend on knowing all the files that are used to build a program or library.

This page shows how to set up CLion with software that uses make and/or autotools.

1 The whole server or just parts

First, you need to decide if you want to work with all of the C++ code as one 'project' or use a separate project for each of 'hyrax-dependencies,' 'libdap4,' and 'bes.' In practice, you choose one way and then switch without paying too great a penalty.

For the rest of this HowTo, I'll assume you have done the following:

  1. Checkout the hyrax git repo from GitHub (https://github.com/opendap/hyrax) and ...
  2. Have used the script(s) to checkout the three C++ projects 'hyrax-dependencies,' 'libdap4,' 'bes.'
  3. Or, you've done something else to get our server code...

2 Open a directory that contains code

When you start CLion, you will see a dialog box New Project dialog

Click on the New CMake Project from Sources and you will see the following Choose the directories to scan

Use this dialog to choose which directories to scan. CLion will scan the selected directories. looking for code to be compiled and also, in the lower panel, for headers to be included. In the later case, code all the dirs with headers you want to be found. For Hyrax, that means the $prefix/build/deps/include and $prefix/build/include directories. The end result will take a few seconds to load and will show messages at the bottom of the screen regarding various scanning and indexing operations. Once this process completes, you should get a CMakeLists.txt file that is pretty comprehensive (AFAIK, this cannot be used to build code without some additions, but it serves as a database for CLion. It may be that we need to add some extra directories to it for things like the libxml2 and curl headers). Regardless of my parenthetical comments, you should see something like this: CMakeLists file

Drive around in the source panel and open some code. It should look 'good' in the sense that there are not many false positive error flags.

2.1 A second way to make the database

The CMakeLists file is one of two 'databases' you can make for CLion to describe the contents of a C++ project - the other is a compiledb json file. This is built from a python tool called compiledb. But there's a trick. In the simplest use, this tool is used like this compiledb -n make. But this alone probably won't work. Unless the directory is clean (i.e., make clean) make won't build anything and compiledb won't put anything in the database. Second, command line arguments to make seem to confuse compiledb. However, it will work to pipe the output of make into compiledb, like this make check -j18 | compiledb -p.

I'm not sure if this is useful or if editing the CMakeLists.txt file will be sufficient for our needs.

3 Building the code

There are several ways to run builds from within CLion. Here's an overview:

  1. Use the terminal window. It is just like a regular terminal window, so you need to source spath.sh at the root of the hyrax project. This is the simplest way to run builds, but it does not lay the groundwork for debugging.
  2. Using the Makefile plugin is another way, but the result does not provide an easy way to find compilation warnings or errors (that is, click on the error and goto the source file/line without having to search).
  3. Using a Custom Build Application is similar to the Makefile plugin but does set the IDE up debugging and does provide a decent way to link to warnings/errors.

3.1 The terminal window

You know how to run make in a terminal... Here's what the terminal looks like. This shows that, for hyrax, you need to source the spath.sh file.

Terminal window

3.2 Setting up Custom Build Applications

This is tricky because you have to do two steps here, one is to set up a Custom Build Target and the second is to set up a Custom Build Application. The Target is needed for the Application to be valid, and for things like the BES, the Target also works to build the code. But, for libdap, the Target will only build the code if bison 3.x is installed in a directory on your default PATH. If not, then the Target described here won't work (but is still required as a placeholder). The general rule is that the Target only works with all of the tools needed for the build are on the PATH that is used when the OS starts CLion.

Here's what to do. Open the Edit Configurations... dialog using the Run menu (there is also an option to open this from the Run menu's Run... item). Run Menu

4 Running the debugger