Skip to content
CMakeLists.txt 2.4 KiB
Newer Older
# Packages are optional: if they are not present, certain code samples are not compiled
cmake_minimum_required(VERSION 2.8.10 FATAL_ERROR)

find_package(OpenMP)   # Built-in in CMake
find_package(MPI)      # Built-in in CMake

include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/common.cmake)

# ==================================================================================================

if ("${DWARF_PREFIX}" STREQUAL "")
  set(DWARF_PREFIX 7_montecarlo)
endif()
set(NAME1_OMP ${DWARF_PREFIX}_integral1_omp)
set(NAME1_SERIAL ${DWARF_PREFIX}_integral1_serial)
set(NAME1_MPI ${DWARF_PREFIX}_integral1_mpi)
set(NAME2_OMP ${DWARF_PREFIX}_integral2_omp)
set(NAME2_SERIAL ${DWARF_PREFIX}_integral2_serial)
set(NAME2_MPI ${DWARF_PREFIX}_integral2_mpi)
set(NAME3_OMP ${DWARF_PREFIX}_integral3_omp)
set(NAME3_SERIAL ${DWARF_PREFIX}_integral3_serial)
set(NAME3_MPI ${DWARF_PREFIX}_integral3_mpi)

# C compiler settings

find_package(Common)

if (OPENMP_FOUND)
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    add_executable(${NAME1_OMP} integral1_openmp.c)
    target_link_libraries(${NAME1_OMP} m)
    install(TARGETS ${NAME1_OMP} DESTINATION bin)
    add_executable(${NAME2_OMP} integral2_openmp.c)
    target_link_libraries(${NAME2_OMP} m)
    install(TARGETS ${NAME2_OMP} DESTINATION bin)
    add_executable(${NAME3_OMP} integral3_openmp.c)
    target_link_libraries(${NAME3_OMP} m)
    install(TARGETS ${NAME3_OMP} DESTINATION bin)
else()
     message("## Skipping 'integral 1/2/3 advanced': no OpenMP support found")
endif()

if (MPI_FOUND)
    set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
    include_directories(${MPI_INCLUDE_PATH})
    add_executable(${NAME1_MPI} integral1_mpi.c)
    target_link_libraries(${NAME1_MPI} m ${MPI_LIBRARIES} stdc++)
    install(TARGETS ${NAME1_MPI} DESTINATION bin)
    add_executable(${NAME2_MPI} integral2_mpi.c)
    target_link_libraries(${NAME2_MPI} m ${MPI_LIBRARIES} stdc++)
    install(TARGETS ${NAME2_MPI} DESTINATION bin)
    add_executable(${NAME3_MPI} integral3_mpi.c)
    target_link_libraries(${NAME3_MPI} m ${MPI_LIBRARIES} stdc++)
    install(TARGETS ${NAME3_MPI} DESTINATION bin)
else()
    message("## Skipping 'integral 1/2/3 advanced': no MPI support found")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${C_FLAGS}")


# ==================================================================================================