1+ cmake_minimum_required (VERSION 3.18 )
2+
3+ set (project remhos)
4+ project (${project} LANGUAGES CXX )
5+ set (CMAKE_CXX_STANDARD 17)
6+ set (CMAKE_CXX_STANDARD_REQUIRED ON )
7+ set (CMAKE_CXX_COMPILER_LAUNCHER ccache)
8+ set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
9+
10+ # CXX flags *******************************************************************
11+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
12+ add_compile_options (-fsanitize=address -O0 )
13+ add_link_options (-fsanitize=address )
14+ endif ()
15+
16+ # remove -DNDEBUG from default RelWithDebInfo flags
17+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2" CACHE STRING "" FORCE )
18+
19+ # Verbosity options ***********************************************************
20+ set (CMAKE_VERBOSE_MAKEFILE OFF CACHE BOOL "" FORCE )
21+ # set(CUDA_VERBOSE_BUILD OFF CACHE BOOL "" FORCE)
22+
23+ # Include paths ***************************************************************
24+ include_directories (${CMAKE_CURRENT_SOURCE_DIR} )
25+ include_directories (${CMAKE_CURRENT_SOURCE_DIR} /../mfem )
26+ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
27+ include_directories (/usr/include/hypre /usr/include )
28+ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
29+ include_directories (/opt/homebrew/opt/fmt/include
30+ /opt/homebrew/opt/openmpi/include
31+ /opt/homebrew/opt/metis/include
32+ /opt/homebrew/opt/hypre/include )
33+ add_compile_definitions (MFEM_USE_CMAKE_TESTS )
34+ else ()
35+ message (FATAL_ERROR "Unsupported system" )
36+ endif ()
37+
38+ # Copy mesh files *************************************************************
39+ file (GLOB SRC_MESH_FILES LIST_DIRECTORIES false data/*.mesh )
40+ set (BUILD_DATA_DIR ${CMAKE_CURRENT_BINARY_DIR} /data)
41+ add_custom_command (OUTPUT data_is_copied
42+ COMMAND ${CMAKE_COMMAND} -E make_directory ${BUILD_DATA_DIR}
43+ COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SRC_MESH_FILES} ${BUILD_DATA_DIR}
44+ COMMAND ${CMAKE_COMMAND} -E touch data_is_copied
45+ COMMENT "Copying mesh files ..." )
46+ add_custom_target (copy_mesh_files DEPENDS data_is_copied )
47+
48+ # Library source files ********************************************************
49+ add_library (Remhos STATIC remhos.cpp remhos_fct.cpp
50+ remhos_ho.cpp remhos_lo.cpp
51+ remhos_mono.cpp remhos_sync.cpp
52+ remhos_tools.cpp )
53+
54+ # Testing options *************************************************************
55+ enable_testing ()
56+ function (add_remhos_test name )
57+ set (file ${name} .cpp)
58+ set (target ${name} )
59+ list (LENGTH ARGN ARGN_COUNT)
60+ if (ARGN_COUNT GREATER 0)
61+ list (GET ARGN 0 extra)
62+ string (APPEND name "_" ${extra} )
63+ string (APPEND target "_" ${extra} )
64+ endif ()
65+ message (STATUS "Adding target: ${target} " )
66+ add_executable (${target} ${file} )
67+ add_dependencies (${target} copy_mesh_files )
68+ target_link_libraries (${target} Remhos -lmpi -lmfem -lhypre -lmetis -lfmt )
69+ if (${CMAKE_SYSTEM_NAME} MATCHES "Linux" )
70+ target_link_directories (${target} PUBLIC /usr/lib/x86_64-linux-gnu )
71+ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
72+ target_link_directories (${target} PUBLIC /opt/homebrew/opt/openmpi/lib
73+ /opt/homebrew/opt/metis/lib
74+ /opt/homebrew/opt/hypre/lib
75+ /opt/homebrew/opt/fmt/lib )
76+ endif ()
77+ target_link_directories (${target} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} /../mfem )
78+ message (STATUS "Adding test: ${target} _n1" )
79+ add_test (NAME ${target} _n1 COMMAND mpirun -n 1 ${target} ${extra} )
80+ message (STATUS "Adding test: ${target} _n3" )
81+ add_test (NAME ${target} _n3 COMMAND mpirun -n 3 ${target} )
82+ endfunction ()
83+
84+ add_remhos_test (remhos_main )
85+ add_remhos_test (remhos_tests )
0 commit comments