diff --git a/CMakeLists.txt b/CMakeLists.txt index d9c2103c8..a6412f782 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,12 @@ set(CMAKE_CXX_STANDARD 11) set(CMAKE_C_STANDARD 99) # Add warning flags to help with debugging -set(CMAKE_C_FLAGS "-Wall -Wextra -Wpedantic -Wshadow") -set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -Wshadow") +string(TOLOWER ${CMAKE_BUILD_TYPE} build_type) +message(STATUS "Build type: ${CMAKE_BUILD_TYPE} -> ${build_type}") +if(build_type STREQUAL "debug") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Wshadow") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow") +endif() # Build Options option(USE_CUDA "Enable NVIDIA CUDA support" OFF) @@ -22,26 +26,15 @@ set(MPICXX "mpicxx" CACHE STRING "MPICXX command") set(MPIRUN "mpirun" CACHE STRING "MPIRUN command") set(CUDA_ARCH "75" CACHE STRING "CUDA Architecture") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}") -include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src") - # Find MPI find_package(MPI REQUIRED) -if (MPI_COMPILER_FLAGS) - add_compile_options(${MPI_COMPILER_FLAGS}) -endif() -include_directories(${MPI_INCLUDE_PATH}) -set(EXTERNAL_LIBS ${MPI_LIBRARIES}) +set(EXTERNAL_LIBS "MPI::MPI_CXX") # Find OpenMP (not required) find_package(OpenMP) if (${OpenMP_CXX_FOUND}) - # Add OpenMP flags to compile options - add_compile_options(${OpenMP_CXX_FLAGS}) - - set(EXTERNAL_LIBS ${EXTERNAL_LIBS} ${OpenMP_CXX_LIBRARIES}) + list(APPEND EXTERNAL_LIBS "OpenMP::OpenMP_CXX") add_definitions(-DOPENMP) - message(STATUS "Found OpenMP ${OpenMP_CXX_LIBRARIES}") endif() # Set default language of .cpp files @@ -71,14 +64,9 @@ elseif (USE_HIP) endif() endif() -add_subdirectory(src/utils) -add_subdirectory(src/communicator) -add_subdirectory(src/persistent) -add_subdirectory(src/collective) -add_subdirectory(src/neighborhood) -if(USE_CUDA OR USE_HIP) - add_subdirectory(src/heterogeneous) -endif() +message(STATUS "Compiling all files as: ${locality_aware_LANG}") + +add_subdirectory(src) set_source_files_properties( ${utils_SOURCES} @@ -97,14 +85,19 @@ add_library(mpi_advance ${neighborhood_SOURCES} ${neighborhood_HEADERS} ${heterogeneous_SOURCES} ${heterogeneous_HEADERS} ) + +set_target_properties(mpi_advance PROPERTIES PUBLIC_HEADER src/mpi_advance.h) + +target_include_directories(mpi_advance PUBLIC + $ + $ + ) + target_link_libraries(mpi_advance PUBLIC ${EXTERNAL_LIBS}) -install(TARGETS mpi_advance - ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib - LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib - RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin) +install(TARGETS mpi_advance) -install(FILES src/mpi_advance.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include) +### Install all headers that locality_aware exports install(FILES ${utils_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/utils) install(FILES ${communicator_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/communicator) install(FILES ${collective_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/collective) @@ -112,15 +105,28 @@ install(FILES ${persistent_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/ install(FILES ${neighborhood_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/neighborhood) install(FILES ${heterogeneous_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/heterogeneous) -if (ENABLE_UNIT_TESTS) - enable_testing() - add_subdirectory(src/collective/tests) - add_subdirectory(src/neighborhood/tests) - if (USE_GPU) - add_subdirectory(src/heterogeneous/tests) - endif(USE_GPU) -endif() - add_subdirectory(benchmarks) +### Installation Requirements for Spack Package ### +include(CMakePackageConfigHelpers) + +# Install the actual target(s) and register them for export +install(TARGETS mpi_advance + EXPORT mpiadvanceTargets + DESTINATION lib) + +# Export the targets into a CMake package +install(EXPORT mpiadvanceTargets + NAMESPACE MPIAdvance:: + DESTINATION share/mpiadvance) + +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/locality_aware-config.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/mpiadvance-config.cmake" + INSTALL_DESTINATION share/mpiadvance) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/mpiadvance-config.cmake" + DESTINATION share/mpiadvance) +############## End of Spack Section ################ diff --git a/cmake/mpiadvanceConfig.cmake b/cmake/locality_aware-config.cmake.in similarity index 61% rename from cmake/mpiadvanceConfig.cmake rename to cmake/locality_aware-config.cmake.in index 4957b958a..b489d0198 100644 --- a/cmake/mpiadvanceConfig.cmake +++ b/cmake/locality_aware-config.cmake.in @@ -1,3 +1,6 @@ @PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/mpiadvanceTargets.cmake") + +find_package(OpenMP) +find_package(MPI REQUIRED) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cd168e63b..9fd6dd3fc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,3 @@ -include_directories(".") - add_subdirectory(utils) add_subdirectory(communicator) add_subdirectory(persistent) @@ -9,26 +7,6 @@ if(USE_CUDA OR USE_HIP) add_subdirectory(heterogeneous) endif() -set_source_files_properties( - ${utils_SOURCES} - ${communicator_SOURCES} - ${collective_SOURCES} - ${persistent_SOURCES} - ${neighborhood_SOURCES} - ${heterogeneous_SOURCES} - PROPERTIES LANGUAGE ${locality_aware_LANG}) - -add_library(mpi_advance - ${utils_SOURCES} ${utils_HEADERS} - ${communicator_SOURCES} ${communicator_HEADERS} - ${collective_SOURCES} ${collective_HEADERS} - ${persistent_SOURCES} ${persistent_HEADERS} - ${neighborhood_SOURCES} ${neighborhood_HEADERS} - ${heterogeneous_SOURCES} ${heterogeneous_HEADERS} -) - -target_link_libraries(mpi_advance ${MPI_LIBRARIES}) - if (ENABLE_UNIT_TESTS) add_subdirectory(collective/tests) add_subdirectory(neighborhood/tests) diff --git a/src/collective/CMakeLists.txt b/src/collective/CMakeLists.txt index a96875c1e..34878cb6c 100644 --- a/src/collective/CMakeLists.txt +++ b/src/collective/CMakeLists.txt @@ -1,11 +1,6 @@ -set(CMAKE_INCLUDE_CURRENT_DIR ON) file(GLOB collective_HEADERS CONFIGURE_DEPENDS "*.h") file(GLOB collective_SOURCES CONFIGURE_DEPENDS "*.c") -set_source_files_properties( - ${collective_HEADERS} ${collective_SOURCES} - PROPERTIES LANGUAGE ${locality_aware_LANG}) - -set(collective_HEADERS ${collective_HEADERS} PARENT_SCOPE) -set(collective_SOURCES ${collective_SOURCES} PARENT_SCOPE) +set(collective_HEADERS ${collective_HEADERS} CACHE INTERNAL "All headers for collective files.") +set(collective_SOURCES ${collective_SOURCES} CACHE INTERNAL "All source files for collective directory.") diff --git a/src/communicator/CMakeLists.txt b/src/communicator/CMakeLists.txt index 80892a66c..17e5f970e 100644 --- a/src/communicator/CMakeLists.txt +++ b/src/communicator/CMakeLists.txt @@ -1,8 +1,6 @@ -set(CMAKE_INCLUDE_CURRENT_DIR ON) - file(GLOB communicator_HEADERS CONFIGURE_DEPENDS "*.h") file(GLOB communicator_SOURCES CONFIGURE_DEPENDS "*.c") -set(communicator_HEADERS ${communicator_HEADERS} PARENT_SCOPE) -set(communicator_SOURCES ${communicator_SOURCES} PARENT_SCOPE) +set(communicator_HEADERS ${communicator_HEADERS} CACHE INTERNAL "All headers for communicator files.") +set(communicator_SOURCES ${communicator_SOURCES} CACHE INTERNAL "All source files for communicator directory.") diff --git a/src/heterogeneous/CMakeLists.txt b/src/heterogeneous/CMakeLists.txt index 3f90eb2ec..0f0c764e9 100644 --- a/src/heterogeneous/CMakeLists.txt +++ b/src/heterogeneous/CMakeLists.txt @@ -1,9 +1,7 @@ -set(CMAKE_INCLUDE_CURRENT_DIR ON) - file(GLOB heterogeneous_HEADERS CONFIGURE_DEPENDS "*.h") file(GLOB heterogeneous_SOURCES CONFIGURE_DEPENDS "*.c") -set(heterogeneous_HEADERS ${heterogeneous_HEADERS} PARENT_SCOPE) -set(heterogeneous_SOURCES ${heterogeneous_SOURCES} PARENT_SCOPE) +set(heterogeneous_HEADERS ${heterogeneous_HEADERS} CACHE INTERNAL "All headers for heterogeneous files.") +set(heterogeneous_SOURCES ${heterogeneous_SOURCES} CACHE INTERNAL "All source files for heterogeneous directory.") message(STATUS ${heterogeneous_HEADERS} ${heterogeneous_SOURCES}) diff --git a/src/neighborhood/CMakeLists.txt b/src/neighborhood/CMakeLists.txt index 21b1e596f..35bdb6792 100644 --- a/src/neighborhood/CMakeLists.txt +++ b/src/neighborhood/CMakeLists.txt @@ -1,8 +1,6 @@ -set(CMAKE_INCLUDE_CURRENT_DIR ON) - file(GLOB neighborhood_HEADERS CONFIGURE_DEPENDS "*.h") file(GLOB neighborhood_SOURCES CONFIGURE_DEPENDS "*.c" "*.cpp") -set(neighborhood_HEADERS ${neighborhood_HEADERS} PARENT_SCOPE) -set(neighborhood_SOURCES ${neighborhood_SOURCES} PARENT_SCOPE) +set(neighborhood_HEADERS ${neighborhood_HEADERS} CACHE INTERNAL "All headers for neighborhood files.") +set(neighborhood_SOURCES ${neighborhood_SOURCES} CACHE INTERNAL "All source files for neighborhood directory.") diff --git a/src/persistent/CMakeLists.txt b/src/persistent/CMakeLists.txt index 18fca06ad..6e3fa98f5 100644 --- a/src/persistent/CMakeLists.txt +++ b/src/persistent/CMakeLists.txt @@ -1,8 +1,6 @@ -set(CMAKE_INCLUDE_CURRENT_DIR ON) - file(GLOB persistent_HEADERS CONFIGURE_DEPENDS "*.h") file(GLOB persistent_SOURCES CONFIGURE_DEPENDS "*.c") -set(persistent_HEADERS ${persistent_HEADERS} PARENT_SCOPE) -set(persistent_SOURCES ${persistent_SOURCES} PARENT_SCOPE) +set(persistent_HEADERS ${persistent_HEADERS} CACHE INTERNAL "All headers for persistent files.") +set(persistent_SOURCES ${persistent_SOURCES} CACHE INTERNAL "All source files for persistent directory.") diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index ccf470c70..215ddaaf7 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1,5 +1,3 @@ -set(CMAKE_INCLUDE_CURRENT_DIR ON) - if (USE_CUDA) set(gpu_util_HEADERS src/utils/utils_cuda.h @@ -11,17 +9,12 @@ elseif (USE_HIP) endif() file(GLOB utils_SOURCES CONFIGURE_DEPENDS "*.cpp") -set(utils_SOURCES ${utils_SOURCES} PARENT_SCOPE) +set(utils_SOURCES ${utils_SOURCES} CACHE INTERNAL "All source files for utils directory.") set(utils_HEADERS src/utils/utils.h ${gpu_util_HEADERS} - PARENT_SCOPE + CACHE INTERNAL "All headers for utils files." ) -#set(utils_SOURCES -# src/utils/utils.cpp -# PARENT_SCOPE -# ) -