diff --git a/CMakeLists.txt b/CMakeLists.txt index db9182ba..9982f84e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,93 +2,181 @@ cmake_minimum_required (VERSION 3.5) project (korc_proj C CXX Fortran) +# FIXME: Remove once link issues are resolved with the new macos linker. +if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + SET (CMAKE_EXE_LINKER_FLAGS -ld_classic) +endif () + +#------------------------------------------------------------------------------- +# Setup build types. +#------------------------------------------------------------------------------- +set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + Debug + Release + Sanitized +) + +# Make sure the prefix path appears as a ccmake variable. +set (CMAKE_PREFIX_PATH "" CACHE PATH "Search paths for dependency look up.") + +#------------------------------------------------------------------------------- +# Build Options +#------------------------------------------------------------------------------- +option (USE_ACC "Use OpenACC" OFF) +option (USE_PSPLINE "Use PSPLINE interpolation" OFF) +option (USE_FIO "Use FIO interpolation support" OFF) +#FIXME: CORI is decomissioned. Is this necessary anymore? +option (CORI_DIR "Use Cori directories" OFF) + +#------------------------------------------------------------------------------- +# Sanitizer options +#------------------------------------------------------------------------------- +add_library (sanitizer INTERFACE) +target_compile_options (sanitizer + INTERFACE + $<$:-g> +) + +macro (register_sanitizer_option name default) + string (TOUPPER ${name} upper_name) + + option (SANITIZE_${upper_name} "Enable the ${name} sanitizer" ${default}) + + target_compile_options (sanitizer + INTERFACE + $<$:$<$:-fsanitize=${name}>> + ) + target_link_options (sanitizer + INTERFACE + $<$:$<$:-fsanitize=${name}>> + ) +endmacro () + +register_sanitizer_option (address ON) +register_sanitizer_option (leak OFF) +register_sanitizer_option (memory OFF) +register_sanitizer_option (thread OFF) +register_sanitizer_option (undefined ON) +register_sanitizer_option (float-divide-by-zero ON) + +#------------------------------------------------------------------------------- +# Build Locations +#------------------------------------------------------------------------------- +# FIXME: Leave this as is for now but check if we want to use the cmake install +# functions better. + # Set directories to build all binary files. set (EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/build/bin) - -# Fortran specific settings. -set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -cpp") set (CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/modules) -set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/lib) +set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/lib) -# Set definitions. -add_definitions (-DDOUBLE_PRECISION) -add_definitions (-DPARALLEL_RANDOM) -if (CMAKE_BUILD_TYPE STREQUAL "Debug") -# add_definitions (-DDBG_CHECK) -endif() - -# Configure OpenMP +#------------------------------------------------------------------------------- +# Dependencies +#------------------------------------------------------------------------------- find_package (OpenMP) -set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${OpenMP_Fortran_FLAGS}") -set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_Fortran_FLAGS}") -option (USE_OMP "Use OpenOMP" OFF) -if (${USE_OMP}) - add_definitions (-DOMP) -endif() - -option (USE_ACC "Use OpenACC" OFF) -if (${USE_ACC}) - add_definitions (-DACC) -endif() - -# Configure MPI find_package (MPI REQUIRED) -set (CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${MPI_Fortran_COMPILE_FLAGS}") -set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_Fortran_LINK_FLAGS}") -include_directories (${MPI_Fortran_INCLUDE_PATH}) - -# Configure HDF5 -find_package (HDF5 REQUIRED COMPONENTS Fortran) -include_directories (${HDF5_INCLUDE_DIRS}) - -# Configure EZspline -option (USE_PSPLINE "Use PSPLINE interpolation" OFF) -if (${USE_PSPLINE}) - #include_directories (${EZSpline_INCLUDE_PATH}) - #set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${EZSpline_LINK_FLAGS}") - add_definitions (-DPSPLINE) -endif () - -# Configure FIO interpolation -option (USE_FIO "Use FIO interpolation support" OFF) -if (${USE_FIO}) - include_directories (${FIO_INCLUDE_PATH} ${NIMROD_INCLUDE_PATH} ${NIMFIO_INCLUDE_PATH} ${NIMCORE_INCLUDE_PATH} ${NIMLIB_INCLUDE_PATH} ${NIMEXT_INCLUDE_PATH}) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FIO_LINK_FLAGS} ${NIMFIO_LINK_FLAGS} ${NIMCORE_LINK_FLAGS} ${NIMLIB_LINK_FLAGS} ${NIMEXT_LINK_FLAGS}") - add_definitions (-DFIO) -endif () - +find_package (HDF5 REQUIRED COMPONENTS C Fortran) + +add_library (korc_depends INTERFACE) + +target_link_libraries (korc_depends + + INTERFACE + + sanitizer + $<$:OpenMP::OpenMP_Fortran> + $<$:OpenMP::OpenMP_CXX> + $<$:MPI::MPI_Fortran> + $<$:hdf5::hdf5_fortran> + $<$:${FIO_LIBRARIES}> + $<$:${M3DC1_LIBRARIES}> + $<$:${NIMFIO_LIBRARIES}> + $<$:${NIMBLK_LIBRARIES}> + $<$:${NIMBTY_LIBRARIES}> + $<$:${NIMLOC_LIBRARIES}> + $<$:${NIMITER_LIBRARIES}> + $<$:${NIMMAT_LIBRARIES}> + $<$:${NIMPAR_LIBRARIES}> + $<$:${NIMLIB_LIBRARIES}> + $<$:${NIMMPI_LIBRARIES}> + $<$:${NIMLAP_LIBRARIES}> + $<$:${NIMSLU_LIBRARIES}> + $<$:${NIMLUD_LIBRARIES}> + +) +target_compile_options (korc_depends + + INTERFACE + + $<$:-cpp> +) +# FIXME: Consider making FIO a cmake module and using find_package(FIO) to set +# the dependencies. +target_include_directories (korc_depends + + INTERFACE + + $<$:${FIO_INCLUDE_PATH}> + $<$:${NIMROD_INCLUDE_PATH}> + $<$:${NIMFIO_INCLUDE_PATH}> + $<$:${NIMCORE_INCLUDE_PATH}> + $<$:${NIMLIB_INCLUDE_PATH}> + $<$:${NIMEXT_INCLUDE_PATH}> +) +target_compile_definitions (korc_depends + + INTERFACE + + DOUBLE_PRECISION + PARALLEL_RANDOM +# $<$:DBG_CHECK> + $<$:OMP> + $<$:ACC> + $<$:PSPLINE> + $<$:FIO> + $<$>:MAC> +) +target_link_options (korc_depends + + INTERFACE + + $<$:${FIO_LINK_FLAGS}> + $<$:${NIMFIO_LINK_FLAGS}> + $<$:${NIMCORE_LINK_FLAGS}> + $<$:${NIMLIB_LINK_FLAGS}> + $<$:${NIMEXT_LINK_FLAGS}> +) + +#------------------------------------------------------------------------------- +# Source files. +#------------------------------------------------------------------------------- add_subdirectory (src) -# Add machine dependent definition for finding included scripts -option (CORI_DIR "Use Cori directories" OFF) -if (${CORI_DIR}) - add_definitions (-DCORI) -else () - add_definitions (-DMAC) +#------------------------------------------------------------------------------- +# Testing +#------------------------------------------------------------------------------- +if (${KORC_TEST}) + enable_testing () - if(${KORC_TEST}) - # Configure FRUIT - include_directories (${FRUIT_INCLUDE_PATH}) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FRUIT_LINK_FLAGS}") + add_library (korc_test INTERFACE) - # Configure KORCSRC - include_directories (${KORCSRC_INCLUDE_PATH}) - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${KORCSRC_LINK_FLAGS}") + target_include_directories (korc_test - add_subdirectory (test) + INTERFACE - enable_testing() + ${FRUIT_INCLUDE_PATH} + ${KORCSRC_INCLUDE_PATH} + ) + target_link_options (korc_depends - add_test (NAME unit_testing - COMMAND xtest TEST_OUT - WORKING_DIRECTORY build/bin) + INTERFACE - add_test (NAME regression_test_1 - COMMAND korc_regtest1.sh - WORKING_DIRECTORY test/reg_tests) + ${FRUIT_LINK_FLAGS} + ${KORCSRC_LINK_FLAGS} + ) - endif () + add_subdirectory (test) + add_test (NAME unit_testing COMMAND xtest TEST_OUT WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/build/bin) + add_test (NAME regression_test_1 COMMAND korc_regtest1.sh WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test/reg_tests) endif () - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4fe4988f..9ab5ea66 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,56 +1,52 @@ -# Append all source files to variable korc_sources. As new files are added, -# this must be updated. -set (korc_sources "") -list (APPEND korc_sources - korc_collisions.f90 - korc_fields.f90 - korc_interp.f90 - korc_spatial_distribution.f90 - korc_constants.f90 - korc_finalize.f90 - korc_ppusher.f90 - korc_HDF5.f90 - korc_coords.f90 - korc_hammersley_generator.f90 - korc_profiles.f90 - korc_types.f90 - korc_avalanche.f90 - korc_hpc.f90 - korc_rnd_numbers.f90 - korc_units.f90 - korc_experimental_pdf.f90 - korc_initialize.f90 - korc_velocity_distribution.f90 - korc_c_random.cpp - korc_random.f90 - korc_fio_interface.f90 - korc_input.f90 - korc_pspline.f90 - main.f90 +add_library(korc STATIC) + +target_sources(korc + + PRIVATE + + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ ) +target_link_libraries (korc -add_executable (xkorc ${korc_sources}) -set_property(TARGET xkorc PROPERTY LINKER_LANGUAGE Fortran) + PUBLIC -option (CORI_DIR "Use Cori directories" OFF) -if (${CORI_DIR}) - add_definitions (-DCORI) -else () - add_definitions (-DMAC) - if (${KORC_TEST}) - add_library (korcsrc STATIC ${korc_sources}) - endif () -endif () + korc_depends +) +add_executable (xkorc) +target_sources (xkorc -target_link_libraries (xkorc ${MPI_Fortran_LIBRARIES}) -target_link_libraries (xkorc ${HDF5_LIBRARIES}) + PRIVATE -if (${USE_PSPLINE}) - #target_link_libraries (xkorc ${EZSpline_LIBRARIES}) -endif() + $ +) +target_link_libraries (xkorc + + PUBLIC -if(${USE_FIO}) - target_link_libraries (xkorc ${FIO_LIBRARIES} ${M3DC1_LIBRARIES}) - target_link_libraries (xkorc ${NIMFIO_LIBRARIES} ${NIMBLK_LIBRARIES} ${NIMBTY_LIBRARIES} ${NIMLOC_LIBRARIES} ${NIMITER_LIBRARIES} ${NIMMAT_LIBRARIES} ${NIMPAR_LIBRARIES} ${NIMLIB_LIBRARIES} ${NIMMPI_LIBRARIES} ${NIMLAP_LIBRARIES} ${NIMSLU_LIBRARIES} ${NIMLUD_LIBRARIES}) -endif() + korc +) +set_property (TARGET xkorc PROPERTY LINKER_LANGUAGE Fortran) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9b13f2d4..bef7ca44 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,10 +7,19 @@ list (APPEND korc_tests test_hpc.f90 ) -add_executable (xtest ${korc_tests}) -set_property(TARGET xtest PROPERTY LINKER_LANGUAGE Fortran) +add_executable (xtest) +target_sources(v + + PRIVATE + + $ + $ + $ +) +target_link_libraries (xtest -target_link_libraries (xtest ${FRUIT_LIBRARIES}) -target_link_libraries (xtest ${MPI_Fortran_LIBRARIES}) -target_link_libraries (xtest ${HDF5_LIBRARIES}) -target_link_libraries (xtest ${KORCSRC_LIBRARIES}) + PUBLIC + + korc +) +set_property(TARGET xtest PROPERTY LINKER_LANGUAGE Fortran)