Skip to content

Commit

Permalink
[NEW] Init cmake build system
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleEsMar committed Jan 18, 2024
1 parent f47526e commit 00f95e3
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 0 deletions.
90 changes: 90 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
cmake_minimum_required( VERSION 3.15 )

set( project BsaLib )

# list( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
# include(defaultFlags)

# get version from FILE
file(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" PROJECT_VERSION)
string(REPLACE "." ";" VERSION_LIST ${PROJECT_VERSION})
list(GET VERSION_LIST 0 VERSION_MAJOR)
list(GET VERSION_LIST 1 VERSION_MINOR)
list(GET VERSION_LIST 2 VERSION_PATCH)
set( version ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} )
message( STATUS "Version ${version}" )
unset(VERSION_LIST)


project( ${project}
LANGUAGES Fortran
VERSION ${version}
DESCRIPTION "Library for Bispectral analysis of systems under non-Gaussian random actions"
)
include(CheckFortranSourceCompiles)
include(CheckFortranSourceRuns)


# Project configurable options
option(enable-par-compilation "Enable parallelisation of sources compilation" ON)
option(enable-single "Enable single precision real kind" OFF)
option(enable-openmp "Enable OpenMP parallelisation" ON)
option(enable-heap-arrays "Allocatable arrays are put on the heap" ON)
option(enable-mkl "Enable Intel MKL libraries (Intel compilers only)" ON)
option(enable-shared-runtime "Link to shared Fortran runtime libraries" OFF)
option(enable-sym-ev-routine "Enable usage of 'dsyev' instead of 'dgesvd'" ON)


if (WIN32)
set( CMAKE_DEBUG_POSTFIX "d" )
endif()


# check if intel compiler or not
if (CMAKE_Fortran_COMPILER_ID MATCHES "^Intel")
message( STATUS "NOTE: Using Intel compiler")
set(intel-compiler ON)
else()
message( STATUS "NOTE: Compiler ID: ${CMAKE_Fortran_COMPILER_ID}")
set(intel-compiler OFF)
endif()



# Flags common to all configurations
foreach(config ${CMAKE_CONFIGURATION_TYPES})
string( TOUPPER ${config} config )
if (intel-compiler)
add_compile_options(
$<$<CONFIG:${config}>:-warn:all>
$<$<CONFIG:${config}>:-stand:f18>
)
else()
add_compile_options(
$<$<CONFIG:${config}>:-warn all>
$<$<CONFIG:${config}>:-stand f18>
)
endif()
endforeach()


# Configuration specific options
if (intel-compiler AND enable-heap-arrays)
add_compile_options( "-heap-arrays0" )
endif()

if (intel-compiler)
add_compile_options(
$<$<CONFIG:RELEASE>:-O3>
$<$<CONFIG:RELEASE>:-Ob1>
)
else()
add_compile_options(
$<$<CONFIG:RELEASE>:-Ofast>
)
endif()


add_subdirectory( src )
add_subdirectory( app )

1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
8 changes: 8 additions & 0 deletions build_cmake.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@echo off

setlocal
if not exist "build_cmake" mkdir "build_cmake"
cmake ^
-D enable-sym-ev-routine=OFF ^
-S . -B build_cmake %~1
endlocal
106 changes: 106 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@

set(SRC
${CMAKE_CURRENT_SOURCE_DIR}/BsaLib.f90
${CMAKE_CURRENT_SOURCE_DIR}/CONSTANTS/constants.f90
${CMAKE_CURRENT_SOURCE_DIR}/IO/Logging.f90
${CMAKE_CURRENT_SOURCE_DIR}/IO/LoggingImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/IO/io.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/BsaLibImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/classic/BsaClassicImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/data/BsaLibData.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/data/BsaLibDataImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/functions/functions.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/functions/functionsImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/BsaMesherImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/point/MPoint.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/policy/MPolicy.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/zones/M2DPolygZone.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/zones/MRectZone.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/zones/MRectZoneImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/zones/MTriangZone.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/zones/MTriangZoneImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/bsa/meshing/zones/MZone.f90
${CMAKE_CURRENT_SOURCE_DIR}/settings/Settings.f90
${CMAKE_CURRENT_SOURCE_DIR}/settings/SettingsImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/structure/StructureData.f90
${CMAKE_CURRENT_SOURCE_DIR}/structure/StructureImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/timing/Timer.f90
${CMAKE_CURRENT_SOURCE_DIR}/utils/utility.f90
${CMAKE_CURRENT_SOURCE_DIR}/wind/WindPSDImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/wind/WindSetImpl.f90
${CMAKE_CURRENT_SOURCE_DIR}/wind/WindType.f90
)


# TODO: at some point, enable shared library generation
add_library( ${project} STATIC ${SRC} )
set_target_properties( ${project}
PROPERTIES DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
)


# optional compile flags
if (enable-par-compilation)
message( STATUS "NOTE: Enabling parallel sources compilation" )
if (intel-compiler)
target_compile_options( ${project} PRIVATE "-MP" )
else()
message( WARNING "Enable parallel source compilation for non MSVC!" )
endif()
endif()

if (intel-compiler AND enable-mkl)
message( STATUS "NOTE: Using Intel MKL libraries." )
target_compile_options( ${project} PRIVATE "-Qmkl:parallel" )
else()
find_package( LAPACK REQUIRED )
if (NOT LAPACK_FOUND )
message( SEND_ERROR "Could not find LAPACK." )
endif()
target_link_libraries( ${project} ${LAPACK_LIBRARIES} )
target_link_options( ${project} AFTER PUBLIC ${LAPACK_LINKER_FLAGS} )
endif()

if (enable-openmp)
if (intel-compiler)
target_compile_options( ${project} PRIVATE "-Qopenmp" )
else()
target_compile_options( ${project} PRIVATE "-fopenmp" )
endif()
endif()

if (NOT enable-shared-runtime)
if (intel-compiler)
target_compile_options( ${project} PUBLIC "-libs:static")
else()
message( WARNING "Check how to link to static runtime libraries for non MSVC!" )
endif()
else()
message( STATUS "NOTE: Using SHARED runtime libraries!")
endif()

if (NOT enable-sym-ev-routine)
message( STATUS "NOTE: Using 'dgesvd' method")
target_compile_definitions( ${project} PRIVATE "-DBSA_USE_SVD_METHOD__" )
else()
message( STATUS "NOTE: Using 'dsyev' method")
endif()


# Set module directory
set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/modules)
if(NOT EXISTS "${LIB_MOD_DIR}")
make_directory("${LIB_MOD_DIR}")
endif()
set_target_properties( ${project}
PROPERTIES
Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}
)

# target_include_directories(${project}
# PUBLIC
# $<BUILD_INTERFACE:${LIB_MOD_DIR}>
# $<INSTALL_INTERFACE:${CMAKE_INSTALL_MODULEDIR}>
# )


0 comments on commit 00f95e3

Please sign in to comment.