Commit c6d03b04 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit
Browse files

CMake cleanups.

Cleaning up MPI linking by adding a new interface library for MPI.
parent 3c9fd6af
#------------------------------------------------------------------------------
# Since we need MPI left and right, this makes it easier to deal with MPI.
find_package(MPI REQUIRED)
function(mpi_link target)
target_include_directories(${target}
SYSTEM PRIVATE ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
target_compile_definitions(${target}
PRIVATE ${MPI_C_COMPILE_FLAGS} ${MPI_CXX_COMPILE_FLAGS})
target_link_libraries(${target}
PRIVATE ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
if(MPI_C_LINK_FLAGS OR MPI_CXX_LINK_FLAGS)
set_target_properties(${target}
PROPERTIES LINK_FLAGS ${MPI_C_LINK_FLAGS} ${MPI_CXX_LINK_FLAGS})
endif()
endfunction()
add_library(mpi INTERFACE)
target_include_directories(mpi
SYSTEM INTERFACE ${MPI_C_INCLUDE_PATH} ${MPI_CXX_INCLUDE_PATH})
target_compile_definitions(mpi
INTERFACE ${MPI_C_COMPILE_FLAGS} ${MPI_CXX_COMPILE_FLAGS})
target_link_libraries(mpi
INTERFACE ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
if(MPI_C_LINK_FLAGS OR MPI_CXX_LINK_FLAGS)
set_target_properties(mpi
PROPERTIES LINK_FLAGS ${MPI_C_LINK_FLAGS} ${MPI_CXX_LINK_FLAGS})
endif()
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.0)
project(sensei)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
include(CMakeDependentOption)
......@@ -33,6 +33,8 @@ option(ENABLE_HISTOGRAM "Enable histogram analysis" ON)
#------------------------------------------------------------------------------
include(mpi)
# Process subdirectories.
if(ENABLE_SENSEI)
message(STATUS "Enabled: Sensei infrastructure.")
......@@ -54,3 +56,10 @@ if(ENABLE_PARALLEL3D)
else()
message(STATUS "Disabled: Parallel3D miniapp.")
endif()
if(ENABLE_OSCILLATORS)
message(STATUS "Enabled: Oscillators miniapp.")
add_subdirectory(oscillators)
else()
message(STATUS "Disabled: Histogram miniapp.")
endif()
......@@ -17,8 +17,7 @@ endif()
add_library(histogram STATIC ${sources})
target_compile_definitions(histogram INTERFACE ENABLE_HISTOGRAM)
target_include_directories(histogram INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
include(mpi)
mpi_link(histogram)
target_link_libraries(histogram PUBLIC mpi)
if(ENABLE_SENSEI)
target_link_libraries(histogram PRIVATE core)
......
project (Oscillator)
cmake_minimum_required (VERSION 2.8.11)
#------------------------------------------------------------------------------
set(sources
oscillator.cpp
analysis.cpp)
# Default to Release
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif (NOT CMAKE_BUILD_TYPE)
#------------------------------------------------------------------------------
# Build the util library.
add_library(util STATIC src/format.cc)
target_include_directories(util PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")
#------------------------------------------------------------------------------
# Build the oscillator executable.
add_executable(oscillator ${sources})
target_compile_options(oscillator PRIVATE "-std=c++11")
target_include_directories(oscillator PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Threads
find_package (Threads)
# MPI
find_package (MPI REQUIRED)
set (mpi_libraries ${MPI_C_LIBRARIES} ${MPI_CXX_LIBRARIES})
include_directories (${CMAKE_CURRENT_SOURCE_DIR}/include
SYSTEM ${MPI_INCLUDE_PATH})
# Link with MPI.
target_link_libraries(oscillator PRIVATE mpi)
# Format
add_library (util src/format.cc)
add_executable (oscillator oscillator.cpp analysis.cpp)
target_link_libraries (oscillator util ${mpi_libraries} ${CMAKE_THREAD_LIBS_INIT})
# Threads
find_package(Threads)
target_link_libraries(oscillator PRIVATE util ${CMAKE_THREAD_LIBS_INIT})
......@@ -13,10 +13,7 @@ endif()
#------------------------------------------------------------------------------
add_executable(3D_Grid ${sources})
target_compile_definitions(3D_Grid PRIVATE _FILE_OFFSET_BITS=64 _LARGEFILE64_SOURCE)
target_link_libraries(3D_Grid PRIVATE m)
include(mpi)
mpi_link(3D_Grid)
target_link_libraries(3D_Grid PRIVATE m mpi)
if(ENABLE_SENSEI)
target_link_libraries(3D_Grid PRIVATE core)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment