forked from xiongyw/Xyce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
189 lines (164 loc) · 7.35 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
cmake_policy(SET CMP0075 NEW)
cmake_policy(SET CMP0076 NEW)
option(Xyce_USE_SUPERBUILD "Use superbuild to install Trilinos?")
if(Xyce_USE_SUPERBUILD)
include("XyceSuperBuild.cmake")
return()
endif()
# Xyce should use the same compilers as Trilinos. To ensure this, Trilinos
# should be loaded before "project" is called. However, "project" probes the
# system and sets up some critical variables. Therefore, make an initial call
# to "project" with "NONE" as the compiler set, then find Trilinos, then set up
# the compilers and call project again.
project(Xyce NONE)
# A TriBITS project that performs a coupled build with Trilinos, like Charon,
# changes the names of all the Trilinos variables. Therefore, we have to jump
# through a bunch of hoops to take that use case into account. Here we set a
# cache variable to handle that name "mangling."
set(TriBITS_prefix "Trilinos" CACHE STRING "Prefix of the Trilinos/TriBITS project")
# Charon can use a specific part of Xyce as a TPL. However, that use case
# results in a build of Xyce that is unusable for any other purpose.
# "Xyce_AS_SPECIAL_CHARON_TPL" is a "hidden" variable that must be set at the
# initial CMake invocation with the "-D" flag. If set, CMake looks only for
# the Trilinos packages supplied by Charon. The variable also forces CMake to
# skip some checks in "tps.cmake" that are required for a fully-functional Xyce
# build.
if(Xyce_AS_SPECIAL_CHARON_TPL)
find_package(${TriBITS_prefix} CONFIG
REQUIRED Amesos Epetra EpetraExt Ifpack NOX Teuchos Sacado Triutils
AztecOO Belos TrilinosCouplings Isorropia Zoltan)
else()
message(STATUS "Looking for Trilinos\n"
" Required packages:\n"
" Amesos Epetra EpetraExt Ifpack NOX Teuchos Sacado\n"
" Triutils AztecOO Belos TrilinosCouplings\n"
" Optional packages:\n"
" Isorropia Zoltan ShyLU ShyLU_DDCore Amesos2 Stokhos ROL")
find_package(${TriBITS_prefix} CONFIG
REQUIRED Amesos Epetra EpetraExt Ifpack NOX Teuchos Sacado Triutils
AztecOO Belos TrilinosCouplings
OPTIONAL_COMPONENTS Isorropia Zoltan ShyLU ShyLU_DDCore
Amesos2 Stokhos ROL)
message(STATUS "Looking for Trilinos - found")
endif()
# This is behind an if() statement due to the TriBITS name "mangling" issue.
# From what I tell, there is no way to probe the version of Trilinos when it
# is built as part of a different Tribits project.
if(${TriBITS_prefix} STREQUAL "Trilinos" )
if(Trilinos_VERSION VERSION_LESS "12.12")
message(FATAL_ERROR
"ERROR: Trilinos version ${Trilinos_VERSION} is less than the required minimum of 12.12. Install a version of Trilinos of 12.12 or greater.")
endif()
else()
# This is where we mitigate the TriBITS name mangling. We change the
# variable names to the "correct" names so we minimize pollution of the
# rest of the configure process.
set( Trilinos_CXX_COMPILER_FLAGS ${${TriBITS_prefix}_CXX_COMPILER_FLAGS} )
set( Trilinos_PACKAGE_LIST ${${TriBITS_prefix}_PACKAGE_LIST} )
set( Trilinos_INCLUDE_DIRS ${${TriBITS_prefix}_INCLUDE_DIRS} )
set( Trilinos_LIBRARIES ${${TriBITS_prefix}_LIBRARIES} )
set( Trilinos_TPL_LIST ${${TriBITS_prefix}_TPL_LIST} )
set( Trilinos_TPL_INCLUDE_DIRS ${${TriBITS_prefix}_TPL_INCLUDE_DIRS} )
set( Trilinos_TPL_LIBRARIES ${${TriBITS_prefix}_TPL_LIBRARIES} )
endif()
# If the user explicitly set the compilers, use those; otherwise use the same
# compilers as Trilinos.
if( DEFINED CMAKE_C_COMPILER )
message( "Using the user-defined C compiler: ${CMAKE_C_COMPILER}" )
else()
message( STATUS "Using the ${TriBITS_prefix} C compiler: ${${TriBITS_prefix}_C_COMPILER}" )
set( CMAKE_C_COMPILER ${${TriBITS_prefix}_C_COMPILER} )
endif()
if( DEFINED CMAKE_CXX_COMPILER )
message( "Using the user-defined C++ compiler: ${CMAKE_CXX_COMPILER}" )
else()
message( STATUS "Using the ${TriBITS_prefix} C++ compiler: ${${TriBITS_prefix}_CXX_COMPILER}" )
set( CMAKE_CXX_COMPILER ${${TriBITS_prefix}_CXX_COMPILER} )
endif()
enable_language(C)
enable_language(CXX)
# Set a default build type if none was specified (using the fact that
# CMAKE_CONFIGURATION_TYPES is non-zero for mutli-configuration generators).
#
# This has to be before "project" is called, because, for compilers targeting
# the MSVC ABI on Windows, "project" sets the build type. This behavior was
# changed in CMake version 3.15, but was not made the *default* behavior.
# Since we're compatible with CMake 3.13, we can't use the new behavior. When
# the minimum CMake version requirement is increased, see CMake policy CMP0091:
# <https://cmake.org/cmake/help/latest/policy/CMP0091.html>
# (Originally, this block was placed right before the
# "include(cmake/config.cmake)" call, below.)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
message("Setting the build type to \"Release\", since it was not explicitly set.")
# Set the possible values of build type for ccmake and cmake-gui.
# If a new build type is ever added to Xyce, then this list should be updated.
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "None" "Debug" "Release"
"RelWithDebInfo" "MinSizeRel")
endif()
project(Xyce VERSION 7.5.0 LANGUAGES CXX C)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
option(BUILD_SHARED_LIBS "Build shared libraries?" OFF)
include(cmake/config.cmake)
if(Xyce_PLUGIN_SUPPORT)
if(NOT BUILD_SHARED_LIBS)
message(WARNING "Forcing BUILD_SHARED_LIBS to ON for plugin support.")
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries?" FORCE)
endif()
endif()
add_subdirectory(src)
# JCV: this needs to be cleaned up a bit, along with all the other interfaces,
# which are kind of all over the place in the repo
if (Xyce_SIMULINK)
add_subdirectory(utils)
endif()
# add in unit tests subdirectory if it exists
if ( EXISTS ${Xyce_SOURCE_DIR}/Xyce_UnitTests)
add_subdirectory (Xyce_UnitTests)
endif ( EXISTS ${Xyce_SOURCE_DIR}/Xyce_UnitTests)
# Enable Xyce plugin capability
if(Xyce_PLUGIN_SUPPORT)
find_program(ADMS_XML admsXml)
if(ADMS_XML)
configure_file(
utils/buildxyceplugin.cmake.in
buildxyceplugin.sh
@ONLY)
configure_file(
utils/XycePluginProject.cmake.in
XycePluginProject.cmake
@ONLY)
install(
PROGRAMS
${ADMS_XML}
${CMAKE_BINARY_DIR}/buildxyceplugin.sh
DESTINATION bin)
install(
FILES
utils/ADMS/adms.implicit.xml
utils/ADMS/xyceVersion_nosac.xml
utils/ADMS/xyceBasicTemplates_nosac.xml
utils/ADMS/xyceAnalogFunction_nosac.xml
utils/ADMS/xyceHeaderFile_nosac.xml
utils/ADMS/xyceImplementationFile_nosac.xml
${CMAKE_BINARY_DIR}/XycePluginProject.cmake
DESTINATION share)
install(
DIRECTORY utils/ADMS/examples/toys
DESTINATION share/examples)
message(STATUS "Plugin compatibility enabled")
else()
message(WARNING "ADMS not found. Disabling the plugin capability.")
set(Xyce_PLUGIN_SUPPORT OFF CACHE BOOL "Install Xyce with plugin compatibility" FORCE)
endif()
else()
message(STATUS "Plugin compatibility not enabled")
endif()
# if no generator type is specified, use RPM
set(GEN_TYPE "RPM" CACHE STRING "What generator to use.")
include(CPack)
#See the CPackConfig.cmake in Xyce/cmake for settings