Skip to content
Snippets Groups Projects
Commit 8546076c authored by Stéphane Del Pino's avatar Stéphane Del Pino
Browse files

CMake improvements

- a bit of clean-up
- now uses kokkos compiler's flag

In a (far?) future should work on deactivation of Kokkos and
eventually use Kokkos as a TPL
parent 4b245d6c
Branches
Tags
No related merge requests found
cmake_minimum_required (VERSION 3.4) cmake_minimum_required (VERSION 3.4)
if (${CMAKE_BINARY_DIR} MATCHES "^${CMAKE_SOURCE_DIR}") # CMake utils
if (NOT ${CMAKE_BINARY_DIR} MATCHES "^${CMAKE_SOURCE_DIR}/build") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
message("")
message("##############################################")
message(" In-source building is not allowed! ")
message("##############################################")
message("")
message(" Run cmake outside from source directory ")
message(" or from ${CMAKE_SOURCE_DIR}/build")
message("")
message("----------------------------------------------")
message(" warning: remaining generated files!")
message(" ${CMAKE_BINARY_DIR}/CMakeCache.txt")
message(" ${CMAKE_BINARY_DIR}/CMakeFiles")
message("----------------------------------------------")
message("")
message(" Please remove remaining generated files ")
message(" and run cmake from an appropriate location")
message("")
message(FATAL_ERROR "\n** CMake aborted **") # Forbids in-source builds
endif() include(CheckNotInSources)
endif()
project (Pastis) #------------------------------------------------------
#----------------- Main configuration -----------------
#------------------------------------------------------
list(APPEND CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -O3) project (Pastis)
# Kokkos
add_subdirectory(${CMAKE_SOURCE_DIR}/packages/kokkos) add_subdirectory(${CMAKE_SOURCE_DIR}/packages/kokkos)
add_subdirectory(utils) include(GetKokkosCompilerFlags)
include_directories(${Kokkos_INCLUDE_DIRS_RET}) include_directories(${Kokkos_INCLUDE_DIRS_RET})
# Pastis utils
add_subdirectory(utils)
include_directories(utils) include_directories(utils)
# Pastis binary
add_executable(pastis main.cpp) add_executable(pastis main.cpp)
target_link_libraries(pastis kokkos PastisUtils) target_link_libraries(pastis kokkos PastisUtils)
# -----------------------------------------------------------------
# Checks we are not building in source-tree
# -----------------------------------------------------------------
# Explicitely authorize ${CMAKE_SOURCE_DIR}/build since some people
if (${CMAKE_BINARY_DIR} MATCHES "^${CMAKE_SOURCE_DIR}")
if (NOT ${CMAKE_BINARY_DIR} MATCHES "^${CMAKE_SOURCE_DIR}/build")
message("")
message("##############################################")
message(" In-source building is not allowed! ")
message("##############################################")
message("")
message(" Run cmake outside from source directory ")
message(" or from ${CMAKE_SOURCE_DIR}/build")
message("")
message("----------------------------------------------")
message(" warning: remaining generated files!")
message(" ${CMAKE_BINARY_DIR}/CMakeCache.txt")
message(" ${CMAKE_BINARY_DIR}/CMakeFiles")
message("----------------------------------------------")
message("")
message(" Please remove remaining generated files ")
message(" and run cmake from an appropriate location")
message("")
message(FATAL_ERROR "\n** CMake aborted **\n")
endif()
endif()
# -----------------------------------------------------------------
# Let Kokkos do the job and find good compilier flags
# -----------------------------------------------------------------
#
# This file is slightly adapted from Trilinos build system
# (https://trilinos.org/)
#
set(KOKKOS_SRC_PATH ${Kokkos_SOURCE_DIR})
set(KOKKOS_PATH ${KOKKOS_SRC_PATH})
set(Kokkos_GEN_DIR ${CMAKE_BINARY_DIR})
set_kokkos_cxx_compiler()
set_kokkos_cxx_standard()
include(${KOKKOS_SRC_PATH}/cmake/kokkos_options.cmake)
#------------ COMPUTE KOKKOS_SETTINGS ----------------------------------------
include(${KOKKOS_SRC_PATH}/cmake/kokkos_settings.cmake)
#------------ GENERATE HEADER AND SOURCE FILES -------------------------------
execute_process(
COMMAND ${KOKKOS_SETTINGS} make -f ${KOKKOS_SRC_PATH}/cmake/Makefile.generate_cmake_settings CXX=${CMAKE_CXX_COMPILER} generate_build_settings
WORKING_DIRECTORY "${Kokkos_GEN_DIR}"
OUTPUT_FILE ${Kokkos_GEN_DIR}/core_src_make.out
RESULT_VARIABLE GEN_SETTINGS_RESULT
)
if (GEN_SETTINGS_RESULT)
message(FATAL_ERROR "Kokkos settings generation failed:\n"
"${KOKKOS_SETTINGS} make -f ${KOKKOS_SRC_PATH}/cmake/Makefile.generate_cmake_settings CXX=${CMAKE_CXX_COMPILER} generate_build_settings")
endif()
include(${Kokkos_GEN_DIR}/kokkos_generated_settings.cmake)
#------------ GET KOKKOS COMPILER OPTIONS ------------------------------------
set(CMAKE_CXX_FLAGSl "")
foreach(opt ${KOKKOS_CXX_FLAGS})
set(CMAKE_CXX_FLAGSl "${CMAKE_CXX_FLAGSl} ${opt}")
endforeach()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGSl}")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment