forked from nasa/cea
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
149 lines (127 loc) · 5.33 KB
/
Copy pathCMakeLists.txt
File metadata and controls
149 lines (127 loc) · 5.33 KB
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
cmake_minimum_required(VERSION 3.19)
# Force static linking of runtime libraries
# for Intel & MS compilers on windows
cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
project(CEA
VERSION 3.3.4
LANGUAGES Fortran
)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(GNUInstallDirs)
include(cea_utilities)
#-----------------------------------------------------------------------
# Configuration
#-----------------------------------------------------------------------
# Establish if we are part of a bigger project
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(PROJECT_IS_TOP_LEVEL TRUE)
else()
set(PROJECT_IS_TOP_LEVEL FALSE)
endif()
if(PROJECT_IS_TOP_LEVEL)
# Default Install Path: Local install in current build dir
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install"
CACHE PATH "CEA installation directory"
FORCE)
set(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT FALSE)
message(STATUS "Setting install path to '${CMAKE_INSTALL_PREFIX}' since none specified.")
endif()
# Default Build Type: Standard release build
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "MinSizeRel" "RelWithDebInfo")
message(STATUS "Setting build type to 'Release' since none specified.")
endif()
endif()
# Testing
option(CEA_BUILD_TESTING "Build test harness for CEA" ${PROJECT_IS_TOP_LEVEL})
if(CEA_BUILD_TESTING)
find_package(PFUNIT)
endif()
include(CTest)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# change some build systems on windows
if(WIN32)
# Intel's Windows toolchains use MSVC-style librarian flags for static
# libraries, so forcing GNU ar there produces invalid archive commands.
if(NOT (CMAKE_Fortran_COMPILER_ID STREQUAL "IntelLLVM" OR
CMAKE_Fortran_COMPILER_ID STREQUAL "Intel" OR
CMAKE_Fortran_SIMULATE_ID STREQUAL "MSVC"))
# find an alternative to 'ar' archive utility
find_program(AR_EXECUTABLE NAMES ar)
if(AR_EXECUTABLE)
message(STATUS "Found archive utility: ${AR_EXECUTABLE}")
set(CMAKE_AR ${AR_EXECUTABLE} CACHE FILEPATH "Path to a program." FORCE)
else()
find_program(AR_EXECUTABLE NAMES gcc-ar)
if(AR_EXECUTABLE)
message(STATUS "Found archive utility: ${AR_EXECUTABLE}")
set(CMAKE_AR ${AR_EXECUTABLE} CACHE FILEPATH "Path to a program." FORCE)
else()
message(WARNING "Archive utility not found.")
endif()
endif()
endif()
endif()
#-----------------------------------------------------------------------
# Targets
#-----------------------------------------------------------------------
add_subdirectory(extern/fbasics)
add_subdirectory(source)
# Build the thermodynamic properties database
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/thermo.lib
COMMAND $<TARGET_FILE:cea> --compile-thermo ${CMAKE_SOURCE_DIR}/data/thermo.inp
DEPENDS cea ${CMAKE_SOURCE_DIR}/data/thermo.inp
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Compiling thermodynamic database from thermo.inp"
)
# Build the transport properties database
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/trans.lib
COMMAND $<TARGET_FILE:cea> --compile-trans ${CMAKE_SOURCE_DIR}/data/trans.inp
DEPENDS cea ${CMAKE_SOURCE_DIR}/data/trans.inp
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Compiling transport database from trans.inp"
)
# Create a custom target that depends on both database files
add_custom_target(compile_databases ALL
DEPENDS ${CMAKE_BINARY_DIR}/thermo.lib ${CMAKE_BINARY_DIR}/trans.lib
)
if(PROJECT_IS_TOP_LEVEL)
add_custom_command(TARGET compile_databases POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/thermo.lib ${CMAKE_SOURCE_DIR}/data/thermo.lib
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/trans.lib ${CMAKE_SOURCE_DIR}/data/trans.lib
COMMAND ${CMAKE_COMMAND} -E make_directory
${CMAKE_SOURCE_DIR}/source/bind/python/cea/data
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/thermo.lib
${CMAKE_SOURCE_DIR}/source/bind/python/cea/data/thermo.lib
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/trans.lib
${CMAKE_SOURCE_DIR}/source/bind/python/cea/data/trans.lib
COMMENT "Copying compiled databases to source data directory"
)
endif()
#-----------------------------------------------------------------------
# Installation
#-----------------------------------------------------------------------
install(
FILES ${CMAKE_BINARY_DIR}/thermo.lib ${CMAKE_BINARY_DIR}/trans.lib
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cea
)
install(
FILES ${CMAKE_BINARY_DIR}/thermo.lib ${CMAKE_BINARY_DIR}/trans.lib
DESTINATION ${CMAKE_INSTALL_PREFIX}/data
)
install(EXPORT cea-config
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cea
NAMESPACE cea::
)