forked from OmarMahfoze17/MUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
159 lines (131 loc) · 6.52 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
cmake_minimum_required(VERSION 3.0)
project(MUI VERSION 1.2.1 DESCRIPTION "Multiscale Universal Interface" LANGUAGES CXX C Fortran)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# Library options
option(USE_RBF "Include RBF support" OFF)
# Wrapper options
option(C_WRAPPER "Compile C wrapper" OFF)
option(FORTRAN_WRAPPER "Compile Fortran wrapper" OFF)
option(PYTHON_WRAPPER "Compile Python wrapper" OFF)
option(PIP_INSTALL "Install compiled Python wrapper using pip" OFF)
include(CMakePackageConfigHelpers)
include(CMake/sourcelist.cmake)
find_package(MPI REQUIRED)
if(MPI_FOUND)
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
elseif(NOT MPI_FOUND)
message(SEND_ERROR "MPI not found")
endif(MPI_FOUND)
if(USE_RBF)
find_package(Eigen3 REQUIRED)
if( NOT EIGEN3_INCLUDE_DIR )
message(FATAL_ERROR "Please set the environment variable EIGEN3_INCLUDE_DIR to the include directory of valid Eigen3 installation")
endif()
endif(USE_RBF)
add_library(MUI INTERFACE)
target_include_directories (MUI INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include>)
if(USE_RBF)
target_link_libraries(MUI INTERFACE Eigen3::Eigen)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_RBF")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DUSE_RBF")
endif(USE_RBF)
target_compile_definitions(MUI INTERFACE LIBRARY_HEADER_ONLY)
install(TARGETS MUI EXPORT muiTargets INCLUDES DESTINATION include LIBRARY DESTINATION lib)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/
DESTINATION ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION}/include
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.f90"
PATTERN ".git" EXCLUDE
PATTERN "build" EXCLUDE
PATTERN "wrappers/Python" EXCLUDE
PATTERN "CMake" EXCLUDE
PATTERN "doc" EXCLUDE)
install(DIRECTORY DESTINATION ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION}/lib/)
if(C_WRAPPER)
message("-- MUI C wrapper: Selected")
add_library(MUI_C_wrapper SHARED
./wrappers/C/mui_c_wrapper_general.cpp
./wrappers/C/mui_c_wrapper_1d.cpp
./wrappers/C/mui_c_wrapper_2d.cpp
./wrappers/C/mui_c_wrapper_3d.cpp)
set_target_properties(MUI_C_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/C/mui_c_wrapper_general.h)
set_target_properties(MUI_C_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/C/mui_c_wrapper_1d.h)
set_target_properties(MUI_C_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/C/mui_c_wrapper_2d.h)
set_target_properties(MUI_C_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/C/mui_c_wrapper_3d.h)
set_target_properties(MUI_C_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/C/config_c_wrapper.h)
target_include_directories(MUI_C_wrapper PRIVATE .)
if(USE_RBF)
target_link_libraries(MUI_C_wrapper Eigen3::Eigen ${MPI_CXX_LIBRARIES})
else()
target_link_libraries(MUI_C_wrapper ${MPI_CXX_LIBRARIES})
endif(USE_RBF)
install(TARGETS MUI_C_wrapper
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION}/lib/
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION}/include/wrappers/C/)
endif(C_WRAPPER)
if(FORTRAN_WRAPPER)
message("-- MUI Fortran wrapper: Selected")
add_library(MUI_Fortran_wrapper SHARED
./wrappers/Fortran/mui_f_wrapper_general.cpp
./wrappers/Fortran/mui_f_wrapper_1d.cpp
./wrappers/Fortran/mui_f_wrapper_2d.cpp
./wrappers/Fortran/mui_f_wrapper_3d.cpp)
set_target_properties(MUI_Fortran_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/Fortran/mui_f_wrapper_general.f90)
set_target_properties(MUI_Fortran_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/Fortran/mui_f_wrapper_1d.f90)
set_target_properties(MUI_Fortran_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/Fortran/mui_f_wrapper_2d.f90)
set_target_properties(MUI_Fortran_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/Fortran/mui_f_wrapper_3d.f90)
set_target_properties(MUI_Fortran_wrapper PROPERTIES PUBLIC_HEADER ./wrappers/Fortran/config_f_wrapper.h)
target_include_directories(MUI_Fortran_wrapper PRIVATE .)
if(USE_RBF)
target_link_libraries(MUI_Fortran_wrapper Eigen3::Eigen ${MPI_CXX_LIBRARIES})
else()
target_link_libraries(MUI_Fortran_wrapper ${MPI_CXX_LIBRARIES})
endif(USE_RBF)
install(TARGETS MUI_Fortran_wrapper
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION}/lib/
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION}/include/wrappers/Fortran/)
endif(FORTRAN_WRAPPER)
if(PYTHON_WRAPPER)
message("-- MUI Python wrapper: Selected (Warning - significant compilation time and memory usage)")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
set(COMPILER_TYPE "CLANG")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(COMPILER_TYPE "GNU")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(COMPILER_TYPE "INTEL")
endif()
if(USE_RBF)
add_custom_target(mui4py ALL COMMAND $(MAKE) COMPILER=${COMPILER_TYPE} CXX=${MPI_CXX_COMPILER} USE_RBF=1 INC_EIGEN="${EIGEN3_INCLUDE_DIR}" package
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python)
else()
add_custom_target(mui4py ALL COMMAND $(MAKE) COMPILER=${COMPILER_TYPE} CXX=${MPI_CXX_COMPILER} package
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python)
endif(USE_RBF)
set_property(TARGET mui4py APPEND PROPERTY
ADDITIONAL_CLEAN_FILES ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python/mui4py.egg-info/
${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python/dist/
${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python/build/
${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python/mui4py/__pycache__
${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python/mui4py/mui4py.o
${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python/mui4py/mui4py_mod.so)
if(PIP_INSTALL)
message("-- MUI Python wrapper installation: Selected")
add_custom_target(mui4py_pip ALL COMMAND pip3 install dist/mui4py*.tar.gz
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wrappers/Python)
add_dependencies(mui4py_pip mui4py)
endif(PIP_INSTALL)
endif(PYTHON_WRAPPER)
set(MUI_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION}/include CACHE STRING "Location of MUI header files")
set(MUI_LIB_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION}/lib CACHE STRING "Location of MUI wrapper libraries")
set(MUI_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/MUI-${PROJECT_VERSION} CACHE STRING "Base location of MUI installation")
configure_package_config_file(CMake/MUIConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/MUIConfig.cmake
INSTALL_DESTINATION ${MUI_INSTALL_DIR}/share/MUI-${PROJECT_VERSION}/cmake
PATH_VARS MUI_INCLUDE_INSTALL_DIR MUI_LIB_INSTALL_DIR MUI_INSTALL_DIR)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/MUIConfig.cmake
DESTINATION ${MUI_INSTALL_DIR}/share/MUI-${PROJECT_VERSION}/cmake )