Login  Register

Re: CMake build system for QuantLib

Posted by Joao Paulo Magalhaes-2 on Jul 25, 2012; 10:10pm
URL: http://quantlib.414.s1.nabble.com/CMake-build-system-for-QuantLib-tp8933p8934.html


On 07/25/2012 04:00 PM, Luigi Ballabio wrote:
> On Wed, Jul 25, 2012 at 4:55 PM, Joao Paulo Magalhaes
> [hidden email] wrote:
>> I have created a CMake build system for QuantLib, retaining the
>> behaviour of the current autotools build system: the same
>> configuration options are provided, and the resulting install is the
>> same (apart from one or two wrinkles which are not yet sorted out). My
>> intent is to provide the QuantLib user with both build systems.
>>
>> Would you be interested in trying it out? Is it OK if I send the
>> archive as an attachment?
>
> Sure.  The archive contains the cmake files, not the whole distribution, right?
>

Right. The archive contains only the following files:


QuantLib-1.2-cmake/CMakeLists.txt             # the main cmake file: provides the options and builds the library
QuantLib-1.2-cmake/files.cmake                # the list of source files in ql/
QuantLib-1.2-cmake/config.cmake               # process the user options and creates ql/config.hpp
QuantLib-1.2-cmake/ql/config.hpp.cmake        # the input to obtain ql/config.hpp
QuantLib-1.2-cmake/Examples/CMakeLists.txt    # deals with examples
QuantLib-1.2-cmake/test-suite/CMakeLists.txt  # deals with the test suite
QuantLib-1.2-cmake/test-suite/files.cmake     # the list of source files in the test suite
QuantLib-1.2-cmake/test-suite/main.cpp        # see below


To get things ready to roll, you need first to put the files in the archive into a clean QuantLib source tree:

# untar the archive in a place of your choice
cd /path/to ; tar xvfz QuantLib-1.2-cmake.tar.gz    

# copy its contents into your fresh & clean QuantLib folder:
cd /to/your/QuantLib-1.2 ; cp -r /path/to/QuantLib-1.2-cmake/* .


Instructions for a console build & install.

I presume most of you are already familiar with usage of cmake, but I'll outline the procedure just in case.

# configure & build (out of source)
cd /to/your/QuantLib-1.2/build
cmake -DCMAKE_INSTALL_PREFIX=/your/install/folder ..         # note the path to the location of the main CMakeLists.txt
make

# install
make install

I've setup the options so that defaults are the same as in autotools. So the above procedure won't compile examples or benchmarks. To get that, you can either use the command line or a GUI. Using the command line, the cmake command becomes

cmake -DCMAKE_INSTALL_PREFIX=/your/install/folder -DQuantLib_WITH_EXAMPLES -DQuantLib_WITH_BENCHMARK ..

with all the rest being equal. Each -D above is the definition of the value of a cmake option. If, for example, you want to disable deprecated code, set the value of the option QuantLib_ENABLE_DEPRECATED_CODE to OFF using .

cmake -DCMAKE_INSTALL_PREFIX=/your/install/folder -DQuantLib_WITH_EXAMPLES -DQuantLib_WITH_BENCHMARK -DQuantLib_ENABLE_DEPRECATED_CODE=OFF ..

Since it can be bothersome to remember all the names for these options, the cmake GUI can be handy. For the GUI, there are two choices: a curses-based console GUI (ccmake in ubuntu) and a Qt-based GUI (cmake-gui). I'll start with the curses GUI. The cmake command now can simply be instead:

ccmake ..

Now you'll be able to see and edit the available options, following the instructions at the bottom of the screen. Basically, the procedure consists of iterating between setting an option (or options) and pressing 'c' to configure - until nothing changes (please note that some options activate other options). Then hit 'g' to generate the Makefiles, and exit. The procedure is exactly the same for the Qt GUI, only now you must use the mouse to carry it out.


CAVEAT: There are currently two places which raise issues of compatibility of cmake with autotools (which I hope you'll help me fix):

- the obtaining of ql/config.hpp . Currently I've added ql/config.hpp.cmake which is processed into config.hpp . This is done from the file config.cmake . As it stands, this is not actually incompatible, but it will always require sync between changes to any input config.hpp.

- in the test suite, autotools creates automatically a main.cpp. It was not easy for me to see the reason for this, so I've put it statically in the test folder.

It is because of these caveats that I started above by advising use of a clean QuantLib tree. Nevertheless, I was able to have a tree with both build systems working.


OK - done for now. Please tell me what you think of this.

Best regards,
João Paulo Magalhães




------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev

QuantLib-1.2-cmake.tar.gz (27K) Download Attachment