Skip to content

Commit f51a34a

Browse files
committed
Add cmake configure options
1 parent a30bd69 commit f51a34a

File tree

4 files changed

+92
-16
lines changed

4 files changed

+92
-16
lines changed

.readthedocs.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# .readthedocs.yml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Build documentation in the docs/ directory with Sphinx
9+
sphinx:
10+
configuration: doc/conf.py
11+
12+
# Build documentation with MkDocs
13+
#mkdocs:
14+
# configuration: mkdocs.yml
15+
16+
# Optionally build your docs in additional formats such as PDF and ePub
17+
formats: all

CMakeLists.txt

Lines changed: 58 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,42 @@
88
cmake_minimum_required(VERSION 3.8)
99
project(Flibcpp VERSION 0.1.0 LANGUAGES CXX Fortran)
1010

11+
#---------------------------------------------------------------------------#
12+
# OPTIONS
13+
#---------------------------------------------------------------------------#
14+
15+
if (NOT DEFINED(FLIBCPP_DEV))
16+
set(FLIBCPP_DEV OFF CACHE STRING
17+
"Default to using development-centered options")
18+
endif()
19+
20+
if (NOT DEFINED(CMAKER_BUILD_SHARED))
21+
set(FLIBCPP_DEV OFF CACHE STRING
22+
"Default to using development-centered options")
23+
endif()
24+
25+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
26+
if (FLIBCPP_DEV)
27+
set(_CMAKE_BUILD_TYPE "Debug")
28+
else ()
29+
set(_CMAKE_BUILD_TYPE "RelWithDebInfo")
30+
endif()
31+
message(STATUS "No build type selected, default to ${_CMAKE_BUILD_TYPE}")
32+
set(CMAKE_BUILD_TYPE "${_CMAKE_BUILD_TYPE}" CACHE STRING "Build type" FORCE)
33+
endif()
34+
35+
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
36+
1137
#---------------------------------------------------------------------------#
1238
# SWIG setup
1339
#---------------------------------------------------------------------------#
1440

15-
option(USE_SWIG "Enable SWIG generation" OFF)
16-
if (USE_SWIG)
41+
option(FLIBCPP_USE_SWIG "Enable SWIG generation" ${FLIBCPP_DEV})
42+
if (FLIBCPP_USE_SWIG)
1743
find_package(SWIG)
1844
endif()
1945

20-
if (USE_SWIG AND SWIG_FOUND)
46+
if (FLIBCPP_USE_SWIG AND SWIG_FOUND)
2147
# SWIG is requested and available; make sure it's the Fortran fork.
2248
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
2349
include(CheckSWIGFortran)
@@ -30,18 +56,27 @@ if (USE_SWIG AND SWIG_FOUND)
3056
include(UseSWIG)
3157
endif()
3258
else()
33-
set(USE_SWIG FALSE)
59+
set(FLIBCPP_USE_SWIG FALSE)
3460
endif()
3561

62+
#---------------------------------------------------------------------------#
63+
# GIT
64+
#---------------------------------------------------------------------------#
65+
66+
set(FLIBCPP_VERSION_CPP "${CMAKE_CURRENT_BINARY_DIR}/flibcpp_version.cpp")
67+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/flibcpp_version.cpp.in"
68+
"${FLIBCPP_VERSION_CPP}" @ONLY)
69+
3670
#---------------------------------------------------------------------------#
3771
# LIBRARY
3872
#---------------------------------------------------------------------------#
73+
3974
include(GNUInstallDirs)
4075

41-
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/module)
42-
set(FLIBCPP_GENERATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/generated)
43-
set(FLIBCPP_INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/Flibcpp)
44-
set(FLIBCPP_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR})
76+
set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/module")
77+
set(FLIBCPP_GENERATE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/generated")
78+
set(FLIBCPP_INSTALL_CONFIGDIR "${CMAKE_INSTALL_LIBDIR}/cmake/Flibcpp")
79+
set(FLIBCPP_INSTALL_MODULEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
4580
set(FLIBCPP_NAMESPACE Flibcpp::)
4681

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

56-
if (USE_SWIG)
91+
message(STATUS "Extra sources for ${name}: ${ARGN}")
92+
93+
if (FLIBCPP_USE_SWIG)
5794
# SWIG is available; actually generate the library dynamically.
5895
# Create the library
5996
swig_add_library(${name}
@@ -98,7 +135,7 @@ function(swig_fortran_add_module name)
98135
endfunction()
99136

100137
# Four SWIG libraries
101-
swig_fortran_add_module(flc)
138+
swig_fortran_add_module(flc "${FLIBCPP_VERSION_CPP}")
102139
swig_fortran_add_module(flc_random)
103140
target_link_libraries(flc_random flc)
104141
swig_fortran_add_module(flc_algorithm)
@@ -144,21 +181,27 @@ install(
144181
# TESTING
145182
#---------------------------------------------------------------------------#
146183

147-
enable_testing()
148-
add_subdirectory(test)
184+
option(FLIBCPP_BUILD_TESTS "Build unit tests" ${FLIBCPP_DEV})
185+
if (FLIBCPP_BUILD_TESTS)
186+
enable_testing()
187+
add_subdirectory(test)
188+
endif()
149189

150190
#---------------------------------------------------------------------------#
151191
# EXECUTABLES
152192
#---------------------------------------------------------------------------#
153193

154-
add_subdirectory(example)
194+
option(FLIBCPP_BUILD_EXAMPLES "Build examples" ON)
195+
if (FLIBCPP_BUILD_EXAMPLES)
196+
add_subdirectory(example)
197+
endif()
155198

156199
#---------------------------------------------------------------------------#
157200
# DOCUMENTATION
158201
#---------------------------------------------------------------------------#
159202

160-
option(ENABLE_DOC "Build documentation" OFF)
161-
if (ENABLE_DOC)
203+
option(FLIBCPP_BUILD_DOCS "Build documentation" ${FLIBCPP_DEV})
204+
if (FLIBCPP_BUILD_DOCS)
162205
add_subdirectory(doc)
163206
endif()
164207

doc/introduction.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ software stack with a Fortran and compatible C++ compiler.
2626
5. Make and install (by default it will install to ``/usr/local``):
2727
``make install``.
2828

29+
By default, Flibcpp builds shared libraries. Add the CMake argument
30+
``-DBUILD_SHARED_LIBS:BOOL=OFF`` to build static libraries.
31+
2932
.. _CMake: https://cmake.org
3033
.. _Homebrew: https://brew.sh
3134
.. _YUM: https://access.redhat.com/solutions/9934
@@ -60,6 +63,19 @@ library names. Depending on your system configuration, you might have to
6063
also explicitly link your app against the compiler's C++ standard libraries
6164
using ``-lstdc++``.
6265

66+
Developing
67+
==========
68+
69+
If you are interested in extending the capabilities of Flibcpp, you will need
70+
the latest version of the `SWIG+Fortran`_ tool installed on your machine. When
71+
configuring CMake, you will want to configure using
72+
``cmake -DFLIBCPP_DEV=ON ..`` to enable tests and documentation. Tests,
73+
examples, and documentation can be independently enabled using the
74+
``FLIBCPP_BUILD_TESTS``, ``FLIBCPP_BUILD_EXAMPLES``, and ``FLIBCPP_BUILD_DOCS``
75+
options.
76+
77+
.. _SWIG+Fortran: https://github.com/swig-fortran
78+
6379
.. ############################################################################
6480
.. end of doc/introduction.rst
6581
.. ############################################################################

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
# Create test with dependencies
99
macro(swig_fortran_add_test TESTNAME)
10-
add_executable(${TESTNAME}.exe ${TESTNAME}.f90)
10+
add_executable(${TESTNAME}.exe ${TESTNAME}.F90)
1111
message("Linking ${TESTNAME} against ${ARGN}")
1212
target_link_libraries(${TESTNAME}.exe ${ARGN})
1313
add_test(NAME ${TESTNAME} COMMAND ${TESTNAME}.exe)

0 commit comments

Comments
 (0)