-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
161 lines (138 loc) · 5.47 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
160
161
cmake_minimum_required(VERSION 2.8)
project(moose)
set(CMAKE_BUILD_TYPE Release)
# If from command line, version info is not passed, use the git to generate a
# version file. If GIT fails, use the previous known version.
find_program(GIT_EXEC "git")
message( STATUS "Looking for git ${GIT_EXEC}" )
if(VERSION_MOOSE)
message( STATUS "MOOSE version is set to ${VERSION_MOOSE} at build time" )
elseif(GIT_EXEC)
message( STATUS "Getting version by reading git tags" )
execute_process(
COMMAND ${GIT_EXEC} describe --tags --long
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION_MOOSE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif( )
message( STATUS "Building version ${VERSION_MOOSE}" )
# Prefix
message( STATUS "CMAKE_INSTALL_PREFIX= ${CMAKE_INSTALL_PREFIX}" )
# Options to pass down to moose-core
option(WITH_DOC "Build documentation" OFF)
option(DEBUG "Build with DEBUG support" OFF)
option(WITH_BOOST "Use Boost libraries instead of GSL" OFF)
option(WITH_CUDA "Use CUDA/GPU" OFF)
option(WITH_MPI "Use MPI (experimental)" OFF)
option(WITH_GUI "Install moose-gui. Works only with python2." ON )
# Required packages.
find_package(PythonInterp REQUIRED)
if(PYTHON_VERSION_MAJOR VERSION_EQUAL 3)
set(WITH_GUI OFF)
endif( )
add_custom_target(moose ALL)
## intialize paths
set(PYMOOSE_SOURCE_DIR "${CMAKE_SOURCE_DIR}/moose-core")
set(PYMOOSE_BUILD_DIR ${CMAKE_BINARY_DIR}/__moose-core_build)
set(PYMOOSE_INSTALL_DIR ${CMAKE_BINARY_DIR}/__moose-core_install)
file(MAKE_DIRECTORY ${PYMOOSE_INSTALL_DIR})
if(WITH_GUI)
set(MOOSE_GUI_DIR ${CMAKE_SOURCE_DIR}/moose-gui)
set(MOOSE_GUI_INSTALL_DIR ${CMAKE_BINARY_DIR}/__moose-gui_install)
endif()
set(MOOSE_EXAMPLE_DIR ${CMAKE_SOURCE_DIR}/moose-examples)
set(MOOSE_EXAMPLE_INSTALL_DIR ${CMAKE_BINARY_DIR}/__moose-examples_install)
file(MAKE_DIRECTORY ${PYMOOSE_BUILD_DIR})
# Its a good target since we can not be sure of python module extension on
# different platform.
set(OUTPUT_MOOSEBIN ${PYMOOSE_BUILD_DIR}/moose.bin)
# NOTE: Do not use ExternalProject to build moose-core. There is no simple way
# to export environment variable in ExrernalProject command to subshell.
# HDF_ROOT and GSL_ROOT etc variable are used by cmake of moose-core repo to
# find appropriate libraries. Using ExternalProject is *most* likely to cause
# build failure on OBS.
configure_file(
${CMAKE_SOURCE_DIR}/cmake/build_moose-core.sh.in
${PYMOOSE_BUILD_DIR}/build_moose-core.sh
)
# Build pymoose module, create bdist and and unarchive the bdist to
# PYMOOSE_INSTALL_DIR.
add_custom_target( moose-core DEPENDS ${OUTPUT_MOOSEBIN} )
add_custom_command( OUTPUT ${OUTPUT_MOOSEBIN}
COMMAND ${PYMOOSE_BUILD_DIR}/build_moose-core.sh
WORKING_DIRECTORY ${PYMOOSE_BUILD_DIR}
COMMENT "Building pymoose in ${PYMOOSE_BUILD_DIR}"
VERBATIM
)
add_custom_command( TARGET moose-core POST_BUILD
COMMAND ${CMAKE_COMMAND} -E chdir ${PYMOOSE_INSTALL_DIR} tar xvf
${PYMOOSE_BUILD_DIR}/bdist/pymoose-${VERSION_MOOSE}.CMAKE.tar.gz
COMMENT "Unarchiving pymoose bdist"
VERBATIM
)
if(WITH_GUI)
# Now build moose-gui and moose-examples.
# Make sure each script is compilable. Else report an error.
add_custom_target( gui ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${MOOSE_GUI_DIR} ${MOOSE_GUI_INSTALL_DIR}
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q ${MOOSE_GUI_INSTALL_DIR}
COMMENT "Building moose-gui"
VERBATIM
)
add_custom_target( examples ALL
COMMAND ${CMAKE_COMMAND} -E copy_directory ${MOOSE_EXAMPLE_DIR} ${MOOSE_EXAMPLE_INSTALL_DIR}
COMMAND ${PYTHON_EXECUTABLE} -m compileall -q ${MOOSE_EXAMPLE_INSTALL_DIR}
VERBATIM
)
endif()
add_dependencies(moose moose-core)
if(WITH_GUI)
add_dependencies(moose gui examples)
add_dependencies(examples gui)
endif()
install(DIRECTORY ${PYMOOSE_INSTALL_DIR}/
DESTINATION ${CMAKE_INSTALL_PREFIX}
CONFIGURATIONS Release
PATTERN ".git" EXCLUDE
PATTERN "*.pyc" EXCLUDE
)
if(WITH_GUI)
# moose-gui
set(MOOSE_GUI_DIR ${CMAKE_SOURCE_DIR}/moose-gui)
install(DIRECTORY ${MOOSE_GUI_INSTALL_DIR}/
DESTINATION lib/moose/gui
CONFIGURATIONS Release
PATTERN ".git*" EXCLUDE
PATTERN "*.pyc" EXCLUDE
)
install(DIRECTORY ${MOOSE_EXAMPLE_DIR}/
DESTINATION lib/moose/moose-examples
CONFIGURATIONS Release
PATTERN ".git*" EXCLUDE
PATTERN "_travis*" EXCLUDE
PATTERN ".travis*" EXCLUDE
PATTERN "*.pyc" EXCLUDE
)
configure_file( ${CMAKE_SOURCE_DIR}/cmake/moosegui.in ${CMAKE_BINARY_DIR}/moosegui )
install(PROGRAMS ${CMAKE_BINARY_DIR}/moosegui
DESTINATION bin
CONFIGURATIONS Release
)
endif()
## UNINSTALL
add_custom_target(uninstall DEPENDS __uninstall_moose-core__ )
add_custom_command(OUTPUT __uninstall_moose-core__
COMMAND xargs rm -rf < install_manifest.txt
COMMAND pip uninstall -y moose
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_INSTALL_PREFIX}/bin/moosegui
)
if(WITH_GUI)
add_custom_target( __uninstall_moose-gui__ )
add_custom_command(TARGET __uninstall_moose-gui__
COMMAND ${CMAKE_COMMAND} -E remove_directory
${CMAKE_INSTALL_PREFIX}/lib/moose/gui
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_INSTALL_PREFIX}/bin/moosegui
)
add_dependencies( uninstall __uninstall_moose-gui__ )
endif()