Skip to content

Commit 74e279f

Browse files
Add CMake support
1 parent 8f1f4e4 commit 74e279f

File tree

11 files changed

+339
-0
lines changed

11 files changed

+339
-0
lines changed

CMakeLists.txt

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Master CMAKE Build Script
2+
cmake_minimum_required(VERSION 3.24)
3+
project(
4+
fftpack
5+
LANGUAGES Fortran
6+
VERSION 1.0.0
7+
)
8+
9+
# Get helper macros and functions
10+
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
11+
12+
# Confgiure everything
13+
add_subdirectory(configure)
14+
15+
# Source
16+
add_subdirectory(src)
17+
add_fortran_library(
18+
${PROJECT_NAME}
19+
${PROJECT_INCLUDE_DIR}
20+
${CMAKE_INSTALL_INCLUDEDIR}
21+
${PROJECT_VERSION}
22+
${PROJECT_VERSION_MAJOR}
23+
${FFTPACK_SOURCES}
24+
)
25+
26+
# Installation
27+
add_subdirectory(install)
28+
29+
# Testing
30+
option(BUILD_TESTING "Build tests")
31+
include(CTest)
32+
message(STATUS "Build FFTPACK tests: ${BUILD_TESTING}")
33+
if (BUILD_TESTING)
34+
enable_testing()
35+
add_subdirectory(dependencies)
36+
add_subdirectory(test)
37+
endif()
38+
39+
# Examples
40+
option(BUILD_FFTPACK_EXAMPLES "Build FFTPACK examples")
41+
message(STATUS "Build FFTPACK examples: ${BUILD_FFTPACK_EXAMPLES}")
42+
if (BUILD_FFTPACK_EXAMPLES)
43+
add_subdirectory(example)
44+
endif()

cmake/helper.cmake

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# helper.cmake
2+
#
3+
# A collection of macros and functions making life with CMake and Fortran a
4+
# bit simpler.
5+
6+
# Use to include and export headers
7+
function(include_headers lib dir install_dir)
8+
target_include_directories(
9+
${lib}
10+
INTERFACE
11+
$<BUILD_INTERFACE:${dir}>
12+
$<INSTALL_INTERFACE:${install_dir}>
13+
)
14+
endfunction()
15+
16+
# Use instead of add_library.
17+
function(add_fortran_library lib_name mod_dir include_install_dir version major)
18+
add_library(${lib_name} ${ARGN})
19+
set_target_properties(
20+
${lib_name}
21+
PROPERTIES
22+
POSITION_INDEPENDENT_CODE TRUE
23+
OUTPUT_NAME ${lib_name}
24+
VERSION ${version}
25+
SOVERSION ${major}
26+
Fortran_MODULE_DIRECTORY ${include_install_dir}
27+
)
28+
target_include_directories(
29+
${lib_name}
30+
PUBLIC
31+
$<BUILD_INTERFACE:${mod_dir}>
32+
$<INSTALL_INTERFACE:${include_install_dir}>
33+
)
34+
endfunction()
35+
36+
# Installs the library
37+
function(install_library lib_name lib_install_dir bin_install_dir mod_dir install_dir)
38+
install(
39+
TARGETS ${lib_name}
40+
EXPORT ${lib_name}Targets
41+
RUNTIME DESTINATION ${bin_install_dir}
42+
LIBRARY DESTINATION ${lib_install_dir}
43+
ARCHIVE DESTINATION ${lib_install_dir}
44+
INCLUDES DESTINATION ${install_dir}/include
45+
)
46+
install(
47+
DIRECTORY ${mod_dir}
48+
DESTINATION ${install_dir}
49+
)
50+
endfunction()
51+
52+
# Install the documentation files
53+
function(install_documentation doc_dir install_dir)
54+
install(
55+
DIRECTORY ${doc_dir}
56+
DESTINATION ${install_dir}
57+
)
58+
endfunction()
59+
60+
# Links the supplied library
61+
function(link_library targ lib include_dir)
62+
target_link_libraries(${targ} ${lib})
63+
target_include_directories(${targ} PUBLIC $<BUILD_INTERFACE:${include_dir}>)
64+
endfunction()
65+
66+
# ------------------------------------------------------------------------------
67+
# Helpful Macros
68+
macro(print_all_variables)
69+
message(STATUS "---------- CURRENTLY DEFINED VARIABLES -----------")
70+
get_cmake_property(varNames VARIABLES)
71+
foreach(varName ${varNames})
72+
message(STATUS ${varName} = ${${varName}})
73+
endforeach()
74+
message(STATUS "---------- END ----------")
75+
endmacro()

configure/CMakeLists.txt

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Get the macros and functions we'll need
2+
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
3+
4+
# Set a default build type if none was specified
5+
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
6+
message(STATUS "Setting build type to 'Release' as none was specified.")
7+
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
8+
# Set the possible values of build type for cmake-gui
9+
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release")
10+
endif()
11+
12+
# By default, static library
13+
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
14+
15+
# Export all symbols on Windows when building libraries
16+
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
17+
18+
# Utilize the GNU installation structure
19+
include(GNUInstallDirs)
20+
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)

dependencies/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_subdirectory(test-drive)
2+
set(test-drive_LIBRARY ${test-drive_LIBRARY} PARENT_SCOPE)
3+
set(test-drive_INCLUDE_DIR ${test-drive_INCLUDE_DIR} PARENT_SCOPE)
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Get the macros and functions we'll need
2+
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
3+
include(FetchContent)
4+
5+
# If found, use the installed version; else, import the library
6+
if (${test-drive_FOUND})
7+
# Inform the user of what's going on
8+
message(STATUS "TEST-DRIVE (${test-drive_VERSION}) library found.")
9+
10+
# Get the mod file location
11+
get_target_property(test-drive_INCLUDE_DIR test-drive INTERFACE_INCLUDE_DIRECTORIES)
12+
else()
13+
# Inform the user of what's going on
14+
message(STATUS "TEST-DRIVE library not found. Downloading appropriate repository.")
15+
16+
# Fetch the proper content
17+
FetchContent_Declare(
18+
test-drive
19+
GIT_TAG "origin/main"
20+
GIT_REPOSITORY "https://github.com/fortran-lang/test-drive"
21+
OVERRIDE_FIND_PACKAGE
22+
)
23+
24+
FetchContent_MakeAvailable(test-drive)
25+
set(test-drive_INCLUDE_DIR ${test-drive_BINARY_DIR}/include)
26+
endif()
27+
28+
# Make a parent-scope variable for the library
29+
set(test-drive_LIBRARY test-drive)
30+
set(test-drive_LIBRARY ${test-drive_LIBRARY} PARENT_SCOPE)
31+
32+
# Make a parent-scope variable locating the include directory for test-drive
33+
set(test-drive_INCLUDE_DIR ${test-drive_INCLUDE_DIR} PARENT_SCOPE)

example/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_executable(bench1 bench1.f90)
2+
target_link_libraries(bench1 fftpack)

install/CMakeLists.txt

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Get the macros and functions we'll need
2+
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
3+
include(CMakePackageConfigHelpers)
4+
5+
# Install the library and necessary include files
6+
install_library(
7+
${PROJECT_NAME}
8+
${CMAKE_INSTALL_LIBDIR}
9+
${CMAKE_INSTALL_BINDIR}
10+
${PROJECT_INCLUDE_DIR}
11+
${CMAKE_INSTALL_PREFIX}
12+
)
13+
14+
# Define the version file
15+
write_basic_package_version_file(
16+
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
17+
VERSION ${PROJECT_VERSION}
18+
COMPATIBILITY AnyNewerVersion
19+
)
20+
21+
export(
22+
EXPORT ${PROJECT_NAME}Targets
23+
FILE ${CMAKE_BINARY_DIR}/${PROJECT_NAME}Targets.cmake
24+
)
25+
26+
# Define the configuration file
27+
configure_file(
28+
${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}Config.cmake.in
29+
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
30+
COPYONLY
31+
)
32+
33+
install(
34+
EXPORT ${PROJECT_NAME}Targets
35+
FILE ${PROJECT_NAME}Targets.cmake
36+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
37+
)
38+
install(
39+
FILES
40+
${CMAKE_BINARY_DIR}/${PROJECT_NAME}Config.cmake
41+
${CMAKE_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
42+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
43+
)
44+
45+
configure_file(
46+
${CMAKE_CURRENT_SOURCE_DIR}/template.pc
47+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
48+
@ONLY
49+
)
50+
install(
51+
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
52+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
53+
)

install/fftpackConfig.cmake.in

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (NOT TARGET fftpack)
2+
include("${CMAKE_CURRENT_LIST_DIR}/fftpackTargets.cmake")
3+
endif()

install/template.pc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
prefix = @CMAKE_INSTALL_PREFIX@
2+
libdir = ${prefix}/@CMAKE_INSTALL_FULL_LIBDIR@
3+
includedir = ${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
4+
5+
Name: @PROJECT_NAME@
6+
Description: FFTPACK is a package of fortran subprograms for the fast fourier transform of periodic and other symmetric sequences.
7+
Version: @PROJECT_VERSION@
8+
Libs: -L${libdir} -l@PROJECT_NAME@
9+
Cflags: -I${includedir}

src/CMakeLists.txt

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Locate the source directory
2+
set(dir ${CMAKE_CURRENT_SOURCE_DIR})
3+
4+
# The source files
5+
set(FFTPACK_SOURCES
6+
${dir}/cfftb1.f90
7+
${dir}/cfftf1.f90
8+
${dir}/cffti1.f90
9+
${dir}/cosqb1.f90
10+
${dir}/cosqf1.f90
11+
${dir}/dcosqb.f90
12+
${dir}/dcosqf.f90
13+
${dir}/dcosqi.f90
14+
${dir}/dcost.f90
15+
${dir}/dcosti.f90
16+
${dir}/dfftb.f90
17+
${dir}/dfftf.f90
18+
${dir}/dffti.f90
19+
${dir}/dsinqb.f90
20+
${dir}/dsinqf.f90
21+
${dir}/dsinqi.f90
22+
${dir}/dsint.f90
23+
${dir}/dsinti.f90
24+
${dir}/dzfftb.f90
25+
${dir}/dzfftf.f90
26+
${dir}/dzffti.f90
27+
${dir}/ezfft1.f90
28+
${dir}/fftpack.f90
29+
${dir}/fftpack_dct.f90
30+
${dir}/fftpack_fft.f90
31+
${dir}/fftpack_fftshift.f90
32+
${dir}/fftpack_ifft.f90
33+
${dir}/fftpack_ifftshift.f90
34+
${dir}/fftpack_iqct.f90
35+
${dir}/fftpack_irfft.f90
36+
${dir}/fftpack_qct.f90
37+
${dir}/fftpack_rfft.f90
38+
${dir}/passb.f90
39+
${dir}/passb2.f90
40+
${dir}/passb3.f90
41+
${dir}/passb4.f90
42+
${dir}/passb5.f90
43+
${dir}/passf.f90
44+
${dir}/passf2.f90
45+
${dir}/passf3.f90
46+
${dir}/passf4.f90
47+
${dir}/passf5.f90
48+
${dir}/radb2.f90
49+
${dir}/radb3.f90
50+
${dir}/radb4.f90
51+
${dir}/radb5.f90
52+
${dir}/radbg.f90
53+
${dir}/radf2.f90
54+
${dir}/radf3.f90
55+
${dir}/radf4.f90
56+
${dir}/radf5.f90
57+
${dir}/radfg.f90
58+
${dir}/rfftb1.f90
59+
${dir}/rfftf1.f90
60+
${dir}/rffti1.f90
61+
${dir}/rk.f90
62+
${dir}/sint1.f90
63+
${dir}/zfftb.f90
64+
${dir}/zfftf.f90
65+
${dir}/zffti.f90
66+
)
67+
set(FFTPACK_SOURCES ${FFTPACK_SOURCES} PARENT_SCOPE)

test/CMakeLists.txt

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
include("${PROJECT_SOURCE_DIR}/cmake/helper.cmake")
2+
3+
macro(build_tests testname)
4+
add_executable(${testname} ${ARGN})
5+
link_library(${testname} fftpack ${PROJECT_INCLUDE_DIR})
6+
link_library(${testname} test-drive ${test-drive_INCLUDE_DIR})
7+
add_test(
8+
NAME ${testname}
9+
WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}
10+
COMMAND $<TARGET_FILE:${testname}>
11+
)
12+
endmacro()
13+
14+
set(FFTPACK_TEST_SOURCES
15+
test_fftpack_dct.f90
16+
test_fftpack_fft.f90
17+
test_fftpack_qct.f90
18+
test_fftpack_rfft.f90
19+
test_fftpack_utils.f90
20+
test_fftpack.f90
21+
)
22+
23+
# Run the original FFTPACK test
24+
build_tests(fftpack_original_tests tstfft.f)
25+
26+
# Run the additional FFTPACK tests
27+
build_tests(fftpack_tests ${FFTPACK_TEST_SOURCES})

0 commit comments

Comments
 (0)