Skip to content

Commit

Permalink
Finally fixed the the Cmakelists.txt for everything to build correctl…
Browse files Browse the repository at this point in the history
…y. mehsfem2d/3d can also build standalone now. including configuration
  • Loading branch information
lsawade committed Feb 12, 2025
1 parent f3e1bd2 commit c085006
Show file tree
Hide file tree
Showing 16 changed files with 447 additions and 1,596 deletions.
32 changes: 6 additions & 26 deletions fortran/meshfem2d/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,18 @@ message("-- MESHFEM2D is build without SCOTCH support")
option(ENABLE_DOUBLE_PRECISION "Enable double precision" OFF)
option(WITH_MPI "Build with MPI support" OFF)
option(WITH_SCOTCH "Build with SCOTCH support" OFF)
option(FORCE_VECTORIZATION "Force vectorization" OFF)

# Set output file directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/archive)

message("-- CMAKE_RUNTIME_OUTPUT_DIRECTORY: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}")
message("-- CMAKE_Fortran_MODULE_DIRECTORY: ${CMAKE_Fortran_MODULE_DIRECTORY}")
message("-- CMAKE_ARCHIVE_OUTPUT_DIRECTORY: ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}")
message("-- CMAKE_CURRENT_BINARY_DIR: ${CMAKE_CURRENT_BINARY_DIR}")

# Custom variables
set(SETUP_DIR ${CMAKE_CURRENT_BINARY_DIR}/setup)

# Set include directories
include_directories("${CMAKE_CURRENT_BINARY_DIR}/modules")
include_directories("${CMAKE_Fortran_MODULE_DIRECTORY}")
include_directories(${SETUP_DIR})

# Setting values dependent on options
Expand Down Expand Up @@ -84,24 +80,6 @@ endif()

message("-- CFLAGS: ${CFLAGS}")


# Set Header interfaces
add_library(meshfem2D_constants INTERFACE ${SETUP_DIR}/constants.h)
add_library(meshfem2D::constants ALIAS meshfem2D_constants)

add_library(meshfem2D_precision INTERFACE ${SETUP_DIR}/precision.h)
add_library(meshfem2D::precision ALIAS meshfem2D_precision)

add_library(meshfem2D_version INTERFACE ${SETUP_DIR}/version.fh)
add_library(meshfem2D::version ALIAS meshfem2D_version)

add_library(meshfem2D_config INTERFACE ${SETUP_DIR}/config.h)
add_library(meshfem2D::config ALIAS meshfem2D_config)

add_library(meshfem2D_fh_config INTERFACE ${SETUP_DIR}/config.fh)
add_library(meshfem2D::fh_config ALIAS meshfem2D_fh_config)


# Shared Fortran Module
add_library(meshfem2D_shared_module shared_par.f90)
add_library(meshfem2D::shared_module ALIAS meshfem2D_shared_module)
Expand Down Expand Up @@ -196,7 +174,8 @@ add_library(meshfem2D_mesh
save_stations_file.f90
)
add_library(meshfem2D::mesh ALIAS meshfem2D_mesh)
target_link_libraries(meshfem2D_mesh PRIVATE
target_link_libraries(meshfem2D_mesh
PRIVATE
meshfem2D::shared_module
meshfem2D::parameters)

Expand All @@ -211,7 +190,8 @@ add_library(meshfem2D_mesh_mpi
meshfem2D.F90
)
add_library(meshfem2D::mesh_mpi ALIAS meshfem2D_mesh_mpi)
target_link_libraries(meshfem2D_mesh_mpi PRIVATE
target_link_libraries(meshfem2D_mesh_mpi
PRIVATE
meshfem2D::shared_module
meshfem2D::parameters
meshfem2D::mesh
Expand Down
93 changes: 58 additions & 35 deletions fortran/meshfem2d/setup/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ cmake_minimum_required(VERSION 3.10)
message("-- Configuring meshfem2D headers...")

enable_language(Fortran)

set(SETUP_DIR ${CMAKE_CURRENT_BINARY_DIR})

# ===================== config.h.in START =====================
enable_language(C)

include(CheckIncludeFile)
include(CheckFunctionExists)
Expand All @@ -23,9 +20,32 @@ foreach(header inttypes.h pthread.h scotch.h stdint.h stdio.h stdlib.h strings.h
check_include_file(${header} HAVE_${UPPER_HEADER})
endforeach()

# -----------------------------------------------------------------------------

# Define package information
set(PACKAGE_NAME "SPECFEM2D")
set(PACKAGE_VERSION "8.0.0")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME "specfem2d")
set(PACKAGE_URL "https://github.com/geodynamics/specfem2d")
set(PACKAGE_BUGREPORT "[email protected]")

# Git-related details (can be dynamically retrieved)
set(SPECFEM2D_GIT_BRANCH "main") # You can use 'git rev-parse --abbrev-ref HEAD' dynamically
set(SPECFEM2D_GIT_DATE "2024-02-11")
set(SPECFEM2D_GIT_HASH "abcd1234")
set(SPECFEM2D_GIT_REVISION "abcd1234")
set(SPECFEM2D_VERSION "${PACKAGE_VERSION}")
set(SPECFEM2D_RELEASE_VERSION 1)

set(GIT_PACKAGE_VERSION "v8.0.0-11-gf8c66778")
set(GIT_COMMIT_VERSION "f8c66778e3bcff99be726113a1aca338255ed87e")
set(GIT_DATE_VERSION "2023-03-21 19:54:51 +0100")


# ====== FIGURE OUT THE FORTRAN NAME MANGLING START ===========

# Write test Fortran subroutines
file(WRITE "${CMAKE_BINARY_DIR}/test.f90" "
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test.f90" "
subroutine foobar()
return
end
Expand Down Expand Up @@ -71,7 +91,7 @@ foreach(TEST_CASE
endif()

# Write C test file
file(WRITE "${CMAKE_BINARY_DIR}/test.c" "
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/test.c" "
extern void ${NAME1}(void);
extern void ${NAME2}(void);
int main() {
Expand All @@ -82,10 +102,10 @@ foreach(TEST_CASE
")

try_compile(COMPILE_SUCCESS
${CMAKE_BINARY_DIR}
${CMAKE_CURRENT_BINARY_DIR}
SOURCES
"${CMAKE_BINARY_DIR}/test.f90"
"${CMAKE_BINARY_DIR}/test.c"
"${CMAKE_CURRENT_BINARY_DIR}/test.f90"
"${CMAKE_CURRENT_BINARY_DIR}/test.c"
OUTPUT_VARIABLE COMPILE_OUTPUT
)

Expand Down Expand Up @@ -146,55 +166,58 @@ else()
endif()
endif()

# -----------------------------------------------------------------------------
# ====== FIGURE OUT THE FORTRAN NAME MANGLING END =============

# ===================== config.h.in START =====================

# Generate config.h file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
${SETUP_DIR}/config.h @ONLY)
${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY)

# ===================== config.h.in END =====================

# ===================== config.fh.in START ==================
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.fh.in
${SETUP_DIR}/config.fh @ONLY)
${CMAKE_CURRENT_BINARY_DIR}/config.fh @ONLY)
# ===================== config.fh.in END ====================


# ===================== constants.h.in START ================
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/constants.h.in
${SETUP_DIR}/constants.h @ONLY)
${CMAKE_CURRENT_BINARY_DIR}/constants.h @ONLY)
# ===================== constants.h.in END ==================

# ===================== precision.h.in START ================
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/precision.h.in
${SETUP_DIR}/precision.h @ONLY)
${CMAKE_CURRENT_BINARY_DIR}/precision.h @ONLY)
# ===================== precision.h.in END ==================


# ===================== version.fh.in START ================

# Define package information
set(PACKAGE_NAME "SPECFEM2D")
set(PACKAGE_VERSION "8.0.0")
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
set(PACKAGE_TARNAME "specfem2d")
set(PACKAGE_URL "https://github.com/geodynamics/specfem2d")
set(PACKAGE_BUGREPORT "[email protected]")
# Configure the config.h file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.fh.in
${CMAKE_CURRENT_BINARY_DIR}/version.fh @ONLY)

# Git-related details (can be dynamically retrieved)
set(SPECFEM2D_GIT_BRANCH "main") # You can use 'git rev-parse --abbrev-ref HEAD' dynamically
set(SPECFEM2D_GIT_DATE "2024-02-11")
set(SPECFEM2D_GIT_HASH "abcd1234")
set(SPECFEM2D_GIT_REVISION "abcd1234")
set(SPECFEM2D_RELEASE_VERSION 0) # Set to 1 if it's a stable release
# ===================== version.h.in START ================

set(GIT_PACKAGE_VERSION "v8.0.0-11-gf8c66778")
set(GIT_COMMIT_VERSION "f8c66778e3bcff99be726113a1aca338255ed87e")
set(GIT_DATE_VERSION "2023-03-21 19:54:51 +0100")
# Set Header interfaces
add_library(meshfem2D_constants INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/constants.h)
add_library(meshfem2D::constants ALIAS meshfem2D_constants)
target_include_directories(meshfem2D_constants INTERFACE ${CMAKE_CURRENT_BINARY_DIR})

# Configure the config.h file
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version.fh.in
${SETUP_DIR}/version.fh @ONLY)
add_library(meshfem2D_precision INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/precision.h)
add_library(meshfem2D::precision ALIAS meshfem2D_precision)
target_include_directories(meshfem2D_precision INTERFACE ${CMAKE_CURRENT_BINARY_DIR})

add_library(meshfem2D_version INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/version.fh)
add_library(meshfem2D::version ALIAS meshfem2D_version)
target_include_directories(meshfem2D_version INTERFACE ${CMAKE_CURRENT_BINARY_DIR})

# ===================== version.h.in START ================
add_library(meshfem2D_config INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/config.h)
add_library(meshfem2D::config ALIAS meshfem2D_config)
target_include_directories(meshfem2D_config INTERFACE ${CMAKE_CURRENT_BINARY_DIR})

add_library(meshfem2D_fh_config INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/config.fh)
add_library(meshfem2D::fh_config ALIAS meshfem2D_fh_config)
target_include_directories(meshfem2D_fh_config INTERFACE ${CMAKE_CURRENT_BINARY_DIR})
4 changes: 2 additions & 2 deletions fortran/meshfem2d/setup/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#cmakedefine01 HAVE_UNISTD_H

/* Define if xmmintrin.h exists */
#cmakedefine HAVE_XMMINTRIN
#cmakedefine01 HAVE_XMMINTRIN

/* Define to the address where bug reports for this package should be sent. */
#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
Expand Down Expand Up @@ -89,7 +89,7 @@
#cmakedefine SPECFEM2D_GIT_REVISION "@SPECFEM2D_GIT_REVISION@"

/* Set to 0 if source is from GIT, 1 otherwise. */
#cmakedefine SPECFEM2D_RELEASE_VERSION
#cmakedefine SPECFEM2D_RELEASE_VERSION @SPECFEM2D_RELEASE_VERSION@

/* Define SPECFEM2D version */
#cmakedefine SPECFEM2D_VERSION "@SPECFEM2D_VERSION@"
Expand Down
4 changes: 0 additions & 4 deletions fortran/meshfem2d/version.fh

This file was deleted.

29 changes: 21 additions & 8 deletions fortran/meshfem3d/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
# Minimum CMake version required
cmake_minimum_required(VERSION 3.10)

# Project name and language
project(meshfem3D LANGUAGES Fortran C)

# Set the Fortran standard to 95
set(CMAKE_Fortran_STANDARD 95)
set(CMAKE_Fortran_STANDARD_REQUIRED ON)
# Minimum CMake version required
cmake_minimum_required(VERSION 3.10)

# languages
enable_language(Fortran)
enable_language(C)

# Set the Fortran standard to 95
set(CMAKE_Fortran_STANDARD 95)
set(CMAKE_Fortran_STANDARD_REQUIRED ON)

option(ENABLE_DOUBLE_PRECISION "Enable double precision" OFF)
option(WITH_MPI "Build with MPI support" OFF)
option(WITH_SCOTCH "Build with SCOTCH support" OFF)
option(WITH_ADIOS "Build with ADIOS support" OFF)
option(FORCE_VECTORIZATION "Force vectorization" OFF)
option(BEOWULF_CLUSTER "Build for Beowulf cluster" OFF)

# For the runtime we use the same directory as the main project
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# For output files we use the current directory
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/modules)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/archive)

# Custom variables
set(SETUP_DIR ${CMAKE_CURRENT_BINARY_DIR}/setup)

set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran/meshfem3d/modules)
include_directories("${CMAKE_BINARY_DIR}/fortran/meshfem3d/modules")
# include_directories
include_directories(${CMAKE_Fortran_MODULE_DIRECTORY})
include_directories(${SETUP_DIR})

# Setting values dependent on options
if (ENABLE_DOUBLE_PRECISION)
Expand Down
4 changes: 2 additions & 2 deletions fortran/meshfem3d/generate_databases/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ project(MESHFEM3D_MESHFEM3D LANGUAGES Fortran C)
set(CMAKE_Fortran_STANDARD 95)
set(CMAKE_Fortran_STANDARD_REQUIRED ON)

set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran/meshfem3d/modules)
include_directories("${CMAKE_BINARY_DIR}/fortran/meshfem3d/modules")
# set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../modules)
# include_directories(CMAKE_Fortran_MODULE_DIRECTORY)

set(MESHFEM3D_GENERATE_DATABASES_MODULE
calc_jacobian.f90
Expand Down
5 changes: 2 additions & 3 deletions fortran/meshfem3d/meshfem3D/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ project(MESHFEM3D_MESHFEM3D LANGUAGES Fortran C)
set(CMAKE_Fortran_STANDARD 95)
set(CMAKE_Fortran_STANDARD_REQUIRED ON)


set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/fortran/meshfem3d/modules)
include_directories("${CMAKE_BINARY_DIR}/fortran/meshfem3d/modules")
# set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/../modules)
# include_directories("${CMAKE_Fortran_MODULE_DIRECTORY}")

set(MESHFEM3D_MESH_MODULE
calc_gll_points.f90
Expand Down
Loading

0 comments on commit c085006

Please sign in to comment.