Skip to content

Commit

Permalink
Add cmake configure options
Browse files Browse the repository at this point in the history
  • Loading branch information
sethrj committed Apr 23, 2019
1 parent a30bd69 commit f51a34a
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 16 deletions.
17 changes: 17 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: doc/conf.py

# Build documentation with MkDocs
#mkdocs:
# configuration: mkdocs.yml

# Optionally build your docs in additional formats such as PDF and ePub
formats: all
73 changes: 58 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,42 @@
cmake_minimum_required(VERSION 3.8)
project(Flibcpp VERSION 0.1.0 LANGUAGES CXX Fortran)

#---------------------------------------------------------------------------#
# OPTIONS
#---------------------------------------------------------------------------#

if (NOT DEFINED(FLIBCPP_DEV))
set(FLIBCPP_DEV OFF CACHE STRING
"Default to using development-centered options")
endif()

if (NOT DEFINED(CMAKER_BUILD_SHARED))
set(FLIBCPP_DEV OFF CACHE STRING
"Default to using development-centered options")
endif()

if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
if (FLIBCPP_DEV)
set(_CMAKE_BUILD_TYPE "Debug")
else ()
set(_CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
message(STATUS "No build type selected, default to ${_CMAKE_BUILD_TYPE}")
set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type" FORCE)
endif()

option(BUILD_SHARED_LIBS "Build shared libraries" ON)

#---------------------------------------------------------------------------#
# SWIG setup
#---------------------------------------------------------------------------#

option(USE_SWIG "Enable SWIG generation" OFF)
if (USE_SWIG)
option(FLIBCPP_USE_SWIG "Enable SWIG generation" ${FLIBCPP_DEV})
if (FLIBCPP_USE_SWIG)
find_package(SWIG)
endif()

if (USE_SWIG AND SWIG_FOUND)
if (FLIBCPP_USE_SWIG AND SWIG_FOUND)
# SWIG is requested and available; make sure it's the Fortran fork.
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
include(CheckSWIGFortran)
Expand All @@ -30,18 +56,27 @@ if (USE_SWIG AND SWIG_FOUND)
include(UseSWIG)
endif()
else()
set(USE_SWIG FALSE)
set(FLIBCPP_USE_SWIG FALSE)
endif()

#---------------------------------------------------------------------------#
# GIT
#---------------------------------------------------------------------------#

set(FLIBCPP_VERSION_CPP "${CMAKE_CURRENT_BINARY_DIR}/flibcpp_version.cpp")
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/flibcpp_version.cpp.in"
"${FLIBCPP_VERSION_CPP}" @ONLY)

#---------------------------------------------------------------------------#
# LIBRARY
#---------------------------------------------------------------------------#

include(GNUInstallDirs)

set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/module)
set(FLIBCPP_GENERATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/generated)
set(FLIBCPP_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Flibcpp)
set(FLIBCPP_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR})
set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/module")
set(FLIBCPP_GENERATE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/generated")
set(FLIBCPP_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Flibcpp")
set(FLIBCPP_INSTALL_MODULEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
set(FLIBCPP_NAMESPACE Flibcpp::)

set(FLIBCPP_LIBRARIES)
Expand All @@ -53,7 +88,9 @@ function(swig_fortran_add_module name)
set_property(SOURCE src/${name}.i
PROPERTY USE_TARGET_INCLUDE_DIRECTORIES ON)

if (USE_SWIG)
message(STATUS "Extra sources for ${name}: ${ARGN}")

if (FLIBCPP_USE_SWIG)
# SWIG is available; actually generate the library dynamically.
# Create the library
swig_add_library(${name}
Expand Down Expand Up @@ -98,7 +135,7 @@ function(swig_fortran_add_module name)
endfunction()

# Four SWIG libraries
swig_fortran_add_module(flc)
swig_fortran_add_module(flc "${FLIBCPP_VERSION_CPP}")
swig_fortran_add_module(flc_random)
target_link_libraries(flc_random flc)
swig_fortran_add_module(flc_algorithm)
Expand Down Expand Up @@ -144,21 +181,27 @@ install(
# TESTING
#---------------------------------------------------------------------------#

enable_testing()
add_subdirectory(test)
option(FLIBCPP_BUILD_TESTS "Build unit tests" ${FLIBCPP_DEV})
if (FLIBCPP_BUILD_TESTS)
enable_testing()
add_subdirectory(test)
endif()

#---------------------------------------------------------------------------#
# EXECUTABLES
#---------------------------------------------------------------------------#

add_subdirectory(example)
option(FLIBCPP_BUILD_EXAMPLES "Build examples" ON)
if (FLIBCPP_BUILD_EXAMPLES)
add_subdirectory(example)
endif()

#---------------------------------------------------------------------------#
# DOCUMENTATION
#---------------------------------------------------------------------------#

option(ENABLE_DOC "Build documentation" OFF)
if (ENABLE_DOC)
option(FLIBCPP_BUILD_DOCS "Build documentation" ${FLIBCPP_DEV})
if (FLIBCPP_BUILD_DOCS)
add_subdirectory(doc)
endif()

16 changes: 16 additions & 0 deletions doc/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ software stack with a Fortran and compatible C++ compiler.
5. Make and install (by default it will install to ``/usr/local``):
``make install``.

By default, Flibcpp builds shared libraries. Add the CMake argument
``-DBUILD_SHARED_LIBS:BOOL=OFF`` to build static libraries.

.. _CMake: https://cmake.org
.. _Homebrew: https://brew.sh
.. _YUM: https://access.redhat.com/solutions/9934
Expand Down Expand Up @@ -60,6 +63,19 @@ library names. Depending on your system configuration, you might have to
also explicitly link your app against the compiler's C++ standard libraries
using ``-lstdc++``.

Developing
==========

If you are interested in extending the capabilities of Flibcpp, you will need
the latest version of the `SWIG+Fortran`_ tool installed on your machine. When
configuring CMake, you will want to configure using
``cmake -DFLIBCPP_DEV=ON ..`` to enable tests and documentation. Tests,
examples, and documentation can be independently enabled using the
``FLIBCPP_BUILD_TESTS``, ``FLIBCPP_BUILD_EXAMPLES``, and ``FLIBCPP_BUILD_DOCS``
options.

.. _SWIG+Fortran: https://github.com/swig-fortran

.. ############################################################################
.. end of doc/introduction.rst
.. ############################################################################
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# Create test with dependencies
macro(swig_fortran_add_test TESTNAME)
add_executable(${TESTNAME}.exe ${TESTNAME}.f90)
add_executable(${TESTNAME}.exe ${TESTNAME}.F90)
message("Linking ${TESTNAME} against ${ARGN}")
target_link_libraries(${TESTNAME}.exe ${ARGN})
add_test(NAME ${TESTNAME} COMMAND ${TESTNAME}.exe)
Expand Down

0 comments on commit f51a34a

Please sign in to comment.