-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
84 lines (75 loc) · 3.55 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
cmake_minimum_required(VERSION 3.0)
project(PLAN)
set(PROJECT_NAME plan)
set(SOURCE_FILES src/global.hpp src/global.cpp src/tree.hpp src/tree.cpp src/analyses.hpp src/analyses.cpp src/main.cpp)
add_executable(plan ${SOURCE_FILES})
############################################################
## Other users may add irregular header search paths here ##
############################################################
option(HYBRID "Using hybrid plan with MPI+OpenMP" OFF)
option(PARALLEL "Using parallel plan with MPI" OFF)
option(OPENMP "Using multithreading plan with OpenMP" OFF)
message("============================================================")
message("Run cmake without any option will build a serial program.")
message("The availabel build options are:")
message(" -DPARALLEL=ON to enable MPI")
message(" -DOPENMP=ON to enable OpenMP")
message(" -DHYBRID=ON to enable MPI+OpenMP")
message("N.B.: the chosen option is cached after the first use.")
message("To switch, add -DOPTION=OFF to turn off the previous choice.")
message("eg. cmake -DHYBRID=OFF -DOPENMP=ON ../")
message("You can always delete cache files/folders for a fresh start.")
message("PS: clang/gcc built-in with macOS does not support OpenMP.")
message("============================================================")
if (HYBRID OR (PARALLEL AND OPENMP))
message("============================================================")
message("Now, generating Makefile for hybrid program (MPI+OpenMP)")
message("============================================================")
target_compile_options(${PROJECT_NAME} PUBLIC -std=c++11 -Wall -DHybrid -O3 -DNDEBUG)
set(TURN_ON_MPI ON)
set(TURN_ON_OpenMP ON)
elseif (PARALLEL)
message("============================================================")
message("Now, generating Makefile for parallel program (MPI)")
message("============================================================")
target_compile_options(${PROJECT_NAME} PUBLIC -std=c++11 -Wall -DMPI_ON -O3 -DNDEBUG)
set(TURN_ON_MPI ON)
set(TURN_ON_OpenMP OFF)
elseif (OPENMP)
message("============================================================")
message("Now, generating Makefile for multithreaded program (OpenMP)")
message("============================================================")
target_compile_options(${PROJECT_NAME} PUBLIC -std=c++11 -Wall -DOpenMP_ON -O3 -DNDEBUG)
set(TURN_ON_MPI OFF)
set(TURN_ON_OpenMP ON)
else ()
message("============================================================")
message("Now, generating Makefile for serial program...")
message("============================================================")
target_compile_options(${PROJECT_NAME} PUBLIC -std=c++11 -Wall -O3 -DNDEBUG)
set(TURN_ON_MPI OFF)
set(TURN_ON_OpenMP OFF)
endif ()
if (TURN_ON_MPI)
find_package(MPI REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${MPI_C_INCLUDE_DIRS})
target_link_libraries(plan PUBLIC ${MPI_C_LIBRARIES})
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${MPI_C_LINK_FLAGS} -DMPICH_SKIP_MPICXX -DOMPI_SKIP_MPICXX")
endif ()
if (TURN_ON_OpenMP)
find_package(OpenMP REQUIRED)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif ()
if (NOT APPLE)
add_compile_options(-march=native)
endif ()
find_package(Boost REQUIRED)
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_VERBOSE_MAKEFILE ON)
unset(HYBRID)
unset(OPENMP)
unset(PARALLEL)
unset(TURN_ON_MPI)
unset(TURN_ON_OpenMP)