Skip to content

Commit

Permalink
[Samples/Doc] Generate CMakeLists.txt files for C++ and F90 samples
Browse files Browse the repository at this point in the history
  • Loading branch information
speth committed Oct 29, 2016
1 parent af076ba commit f959fa6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
30 changes: 30 additions & 0 deletions doc/sphinx/cxx-guide/compiling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,36 @@ contained in the ``samples`` subdirectory of the Cantera installation directory.
For more information on SCons, see the `SCons Wiki <http://scons.org/wiki/>`_
and the `SCons homepage <http://www.scons.org>`_.

CMake
=====

CMake is a multi-platform build system which uses a high-level project
description to generate platform-specific build scripts (i.e. on Linux, CMake
will generate Makefiles). The configuration file for a CMake project is called
``CMakeLists.txt``. A typical ``CMakeLists.txt`` file for compiling a program
that uses Cantera might look like this:

.. code-block:: cmake
cmake_minimum_required(VERSION 3.1)
project (sample)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 11)
find_package(Threads REQUIRED)
include_directories("/opt/cantera/include" "/opt/sundials-2.7.0/include")
link_directories("/opt/cantera/lib" "/opt/sundials-2.7.0/lib")
add_executable(sample sample.cpp)
target_link_libraries(sample cantera sundials_cvodes sundials_ida sundials_nvecserial fmt Threads::Threads)
Several example ``CMakeLists.txt`` files are included with the C++ examples
contained in the ``samples`` subdirectory of the Cantera installation directory,
which have the paths and lists of libraries correctly configured for system on
which they are installed.

Make
====

Expand Down
13 changes: 13 additions & 0 deletions samples/cxx/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.1)
project (@tmpl_progname@)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CXX_STANDARD 11)

find_package(Threads REQUIRED)

include_directories(@cmake_cantera_incdirs@)
link_directories(@cmake_cantera_libdirs@)

add_executable(@tmpl_progname@ @tmpl_sourcename@)
target_link_libraries(@tmpl_progname@ @cmake_cantera_libs@ Threads::Threads)
7 changes: 7 additions & 0 deletions samples/cxx/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ for subdir, name, extensions in samples:
localenv['tmpl_compiler_flags'] = repr(localenv['CCFLAGS'] + localenv['CXXFLAGS'])
localenv['tmpl_cantera_frameworks'] = repr(localenv['FRAMEWORKS'])
localenv['tmpl_cantera_incdirs'] = repr([x for x in incdirs if x])
localenv['cmake_cantera_incdirs'] = ' '.join(quoted(x) for x in incdirs if x)
localenv['tmpl_cantera_libs'] = repr(localenv['cantera_libs'])
localenv['cmake_cantera_libs'] = ' '.join(localenv['cantera_libs'])
localenv['tmpl_cantera_libdirs'] = repr([x for x in libdirs if x])
localenv['cmake_cantera_libdirs'] = ' '.join(quoted(x) for x in libdirs if x)
localenv['tmpl_cantera_linkflags'] = repr(localenv['LINKFLAGS'])
localenv['tmpl_progname'] = name
localenv['tmpl_sourcename'] = name + '.cpp'
Expand All @@ -46,6 +49,10 @@ for subdir, name, extensions in samples:
sconstruct = localenv.SubstFile(pjoin(subdir, 'SConstruct'), 'SConstruct.in')
install(pjoin('$inst_sampledir', 'cxx', subdir), sconstruct)

## Generate CMakeList.txt files to be installed
cmakelists = localenv.SubstFile(pjoin(subdir, 'CMakeLists.txt'), 'CMakeLists.txt.in')
install(pjoin('$inst_sampledir', 'cxx', subdir), cmakelists)

## Generate Makefiles to be installed
mak_path = pjoin(localenv['ct_incroot'], 'cantera', 'Cantera.mak')
localenv['mak_compiler_flags'] = ' '.join(localenv['CCFLAGS'] + localenv['CXXFLAGS'])
Expand Down
13 changes: 13 additions & 0 deletions samples/f90/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.1)
project (@tmpl_progname@)

set(CMAKE_VERBOSE_MAKEFILE ON)
enable_language(Fortran)

find_package(Threads REQUIRED)

include_directories(@cmake_cantera_incdirs@)
link_directories(@cmake_cantera_libdirs@)

add_executable(@tmpl_progname@ @tmpl_sourcename@)
target_link_libraries(@tmpl_progname@ @cmake_cantera_libs@ Threads::Threads)
7 changes: 7 additions & 0 deletions samples/f90/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ for programName, sources in samples:

sconstruct = localenv.SubstFile('SConstruct', 'SConstruct.in')

# Generate CMakeLists.txt to be installed
localenv['cmake_cantera_incdirs'] = ' '.join(quoted(x) for x in incdirs if x)
localenv['cmake_cantera_libs'] = ' '.join(libs)
localenv['cmake_cantera_libdirs'] = ' '.join(quoted(x) for x in libdirs if x)
cmakelists = localenv.SubstFile('CMakeLists.txt', 'CMakeLists.txt.in')

# Generate Makefile to be installed
localenv['make_target'] = programName
localenv['make_sourcefile'] = programName + '.f90'
makefile = localenv.SubstFile('Makefile', 'Makefile.in')

install('$inst_sampledir/f90', makefile)
install('$inst_sampledir/f90', sconstruct)
install('$inst_sampledir/f90', cmakelists)

0 comments on commit f959fa6

Please sign in to comment.