Skip to content

Commit d697b2b

Browse files
Merge pull request #25 from jchristopherson/v1.5.1
2 parents 4b13404 + a473a28 commit d697b2b

File tree

15 files changed

+235
-228
lines changed

15 files changed

+235
-228
lines changed

CMakeLists.txt

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,23 @@ cmake_minimum_required(VERSION 3.24)
33
project(
44
fstats
55
LANGUAGES Fortran
6-
VERSION 1.5.0
6+
VERSION 1.5.1
77
)
8+
set(CMAKE_Fortran_STANDARD 2018)
9+
set(CMAKE_Fortran_STANDARD_REQUIRED TRUE)
810

911
# Confgiure everything
1012
add_subdirectory(configure)
1113

12-
# Deal with the dependencies
13-
add_subdirectory(dependencies)
14-
15-
# Get OpenMP
16-
find_package(OpenMP REQUIRED COMPONENTS Fortran)
17-
1814
# Source
1915
add_subdirectory(src)
20-
set_source_files_properties(
21-
${FSTATS_SOURCES}
22-
PROPERTIES Fortran_PREPROCESS ON
23-
)
24-
add_fortran_library(
25-
${PROJECT_NAME}
26-
${PROJECT_INCLUDE_DIR}
27-
${CMAKE_INSTALL_INCLUDEDIR}
28-
${PROJECT_VERSION}
29-
${PROJECT_VERSION_MAJOR}
30-
${FSTATS_SOURCES}
31-
)
32-
target_link_libraries(${PROJECT_NAME} PUBLIC
33-
${ferror_LIBRARY}
34-
${linalg_LIBRARY}
35-
${collections_LIBRARY}
36-
)
37-
target_include_directories(${PROJECT_NAME} PUBLIC
38-
$<BUILD_INTERFACE:${ferror_INCLUDE_DIR}>
39-
$<BUILD_INTERFACE:${linalg_INCLUDE_DIR}>
40-
$<BUILD_INTERFACE:${collections_INCLUDE_DIR}>
16+
17+
# Install
18+
install(
19+
EXPORT ${PROJECT_NAME}-targets
20+
NAMESPACE ${PROJECT_NAME}::
21+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
4122
)
42-
if (OpenMP_Fortran_FOUND)
43-
target_link_libraries(${PROJECT_NAME} PUBLIC OpenMP::OpenMP_Fortran)
44-
target_compile_definitions(${PROJECT_NAME} PRIVATE USEOPENMP=1)
45-
endif()
4623

4724
# Testing
4825
option(BUILD_TESTING "Build tests")

cmake/helper.cmake

Lines changed: 0 additions & 75 deletions
This file was deleted.

configure/CMakeLists.txt

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Get the macros and functions we'll need
2-
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
3-
41
# Set a default build type if none was specified
52
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
63
message(STATUS "Setting build type to 'Release' as none was specified.")
@@ -13,11 +10,64 @@ endif()
1310
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
1411

1512
# Export all symbols on Windows when building libraries
16-
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
13+
SET(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
1714

1815
# Utilize the GNU installation structure
1916
include(GNUInstallDirs)
2017

21-
# Locate the local include directory
22-
set(PROJECT_INCLUDE_DIR ${PROJECT_BINARY_DIR}/include)
23-
set(PROJECT_INCLUDE_DIR ${PROJECT_INCLUDE_DIR} PARENT_SCOPE)
18+
# Module directory
19+
if(NOT DEFINED CMAKE_INSTALL_MODULEDIR)
20+
set(
21+
CMAKE_INSTALL_MODULEDIR
22+
"${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}"
23+
CACHE
24+
STRING
25+
"Directory in prefix to install generated module files"
26+
)
27+
endif()
28+
29+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
30+
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
31+
32+
# Export a pkg-config file
33+
configure_file(
34+
"${CMAKE_CURRENT_SOURCE_DIR}/template.pc"
35+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
36+
@ONLY
37+
)
38+
39+
install(
40+
FILES
41+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
42+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
43+
)
44+
45+
# Export CMake package file
46+
include(CMakePackageConfigHelpers)
47+
configure_package_config_file(
48+
"${CMAKE_CURRENT_SOURCE_DIR}/template.cmake"
49+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
50+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
51+
)
52+
53+
if(BUILD_SHARED_LIBS OR PROJECT_VERSION_MAJOR EQUAL 0)
54+
# Due to the uncertain ABI compatibility of Fortran shared libraries
55+
# limit compatibility for dynamic linking to same minor version.
56+
set(COMPATIBILITY SameMinorVersion)
57+
else()
58+
# Require API compatibility via semantic versioning for static linking.
59+
set(COMPATIBILITY SameMajorVersion)
60+
endif()
61+
62+
write_basic_package_version_file(
63+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
64+
VERSION "${PROJECT_VERSION}"
65+
COMPATIBILITY ${COMPATIBILITY}
66+
)
67+
68+
install(
69+
FILES
70+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake"
71+
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake"
72+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
73+
)

configure/template.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@PACKAGE_INIT@
2+
3+
if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@")
4+
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
5+
endif()

configure/template.pc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
3+
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
4+
moduledir=${prefix}/@CMAKE_INSTALL_MODULEDIR@
5+
6+
Name: @PROJECT_NAME@
7+
Description: @PROJECT_DESCRIPTION@
8+
Version: @PROJECT_VERSION@
9+
Libs: -L${libdir} -l@PROJECT_NAME@
10+
Cflags: -I${includedir} -I${moduledir}

dependencies/CMakeLists.txt

Lines changed: 0 additions & 16 deletions
This file was deleted.

dependencies/collections/CMakeLists.txt

Lines changed: 0 additions & 17 deletions
This file was deleted.

dependencies/ferror/CMakeLists.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

dependencies/linalg/CMakeLists.txt

Lines changed: 0 additions & 22 deletions
This file was deleted.

examples/CMakeLists.txt

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
# Get helper macros and functions
2-
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
3-
41
# Include Dependencies
5-
add_subdirectory(fplot)
62
add_subdirectory(fortran_csv_module)
3+
include(FetchContent)
4+
FetchContent_Declare(
5+
fplot
6+
GIT_REPOSITORY "https://github.com/jchristopherson/fplot"
7+
)
8+
FetchContent_MakeAvailable(fplot)
9+
set(fplot_LIBRARY fplot)
710

811
# Full Factorial Example
912
add_executable(full_factorial_example full_factorial_example.f90)
@@ -30,56 +33,46 @@ configure_file(
3033
add_executable(allan_example allan_example.f90)
3134
target_link_libraries(allan_example fstats)
3235
target_link_libraries(allan_example ${fplot_LIBRARY})
33-
target_include_directories(allan_example PUBLIC ${fplot_INCLUDE_DIR})
3436
target_link_libraries(allan_example ${fortran-csv-module_LIBRARY})
3537
target_include_directories(allan_example PUBLIC ${fortran-csv-module_INCLUDE_DIR})
3638

3739
# Box-Muller Example
3840
add_executable(box_muller_example box_muller_example.f90)
3941
target_link_libraries(box_muller_example fstats ${fplot_LIBRARY})
40-
target_include_directories(box_muller_example PUBLIC ${fplot_INCLUDE_DIR})
4142

4243
# Rejection Sampling Example
4344
add_executable(rejection_sample_example rejection_sample_example.f90)
4445
target_link_libraries(rejection_sample_example fstats ${fplot_LIBRARY})
45-
target_include_directories(rejection_sample_example PUBLIC ${fplot_INCLUDE_DIR})
4646

4747
# LOWESS Example
4848
add_executable(lowess_example lowess_example.f90)
4949
target_link_libraries(lowess_example fstats ${fplot_LIBRARY})
50-
target_include_directories(lowess_example PUBLIC ${fplot_INCLUDE_DIR})
5150

5251
# Bootstrap Example
5352
add_executable(bootstrap_example bootstrap_example.f90)
5453
target_link_libraries(bootstrap_example fstats ${fplot_LIBRARY})
55-
target_include_directories(bootstrap_example PUBLIC ${fplot_INCLUDE_DIR})
5654

5755
# MCMC Regression Example
5856
add_executable(mcmc_regression_example mcmc_regression_example.f90)
5957
target_link_libraries(mcmc_regression_example fstats)
6058
target_link_libraries(mcmc_regression_example ${fplot_LIBRARY})
61-
target_include_directories(mcmc_regression_example PUBLIC ${fplot_INCLUDE_DIR})
6259

6360
# MCMC Regression Example 2
6461
add_executable(mcmc_regression_example_2 mcmc_regression_example_2.f90)
6562
target_link_libraries(mcmc_regression_example_2 fstats)
6663
target_link_libraries(mcmc_regression_example_2 ${fplot_LIBRARY})
67-
target_include_directories(mcmc_regression_example_2 PUBLIC ${fplot_INCLUDE_DIR})
6864

6965
# MCMC Regression Example 3
7066
add_executable(mcmc_regression_example_3 mcmc_regression_example_3.f90)
7167
target_link_libraries(mcmc_regression_example_3 fstats)
7268
target_link_libraries(mcmc_regression_example_3 ${fplot_LIBRARY})
73-
target_include_directories(mcmc_regression_example_3 PUBLIC ${fplot_INCLUDE_DIR})
7469

7570
# Distribution Example
7671
add_executable(distribution_example distribution_example.f90)
7772
target_link_libraries(distribution_example fstats)
7873
target_link_libraries(distribution_example ${fplot_LIBRARY})
79-
target_include_directories(distribution_example PUBLIC ${fplot_INCLUDE_DIR})
8074

8175
# Interpolation Example
8276
add_executable(interpolation_example interpolation_example.f90)
8377
target_link_libraries(interpolation_example fstats)
8478
target_link_libraries(interpolation_example ${fplot_LIBRARY})
85-
target_include_directories(interpolation_example PUBLIC ${fplot_INCLUDE_DIR})

0 commit comments

Comments
 (0)