[Samples/Doc] Generate CMakeLists.txt files for C++ and F90 samples

This commit is contained in:
Ray Speth
2016-10-28 23:39:33 -04:00
parent af076bad0b
commit f959fa67c9
5 changed files with 70 additions and 0 deletions

View File

@@ -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
====

View File

@@ -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)

View File

@@ -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'
@@ -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'])

View File

@@ -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)

View File

@@ -44,6 +44,12 @@ 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'
@@ -51,3 +57,4 @@ for programName, sources in samples:
install('$inst_sampledir/f90', makefile)
install('$inst_sampledir/f90', sconstruct)
install('$inst_sampledir/f90', cmakelists)