11import os , typing , dataclasses
22
3- from .state import ARG
3+ from .state import ARG , CFG
44from .printer import cons
55from . import common
66from .run .input import MFCInputFile
@@ -20,25 +20,24 @@ def compute(self) -> typing.List[str]:
2020
2121 return r
2222
23- name : str
24- flags : typing .List [str ]
25- isDependency : bool
26- isDefault : bool
27- isRequired : bool
28- requires : Dependencies
23+ name : str # Name of the target
24+ flags : typing .List [str ] # Extra flags to pass to CMake
25+ isDependency : bool # Is it a dependency of an MFC target?
26+ isDefault : bool # Should it be built by default? (unspecified -t | --targets)
27+ isRequired : bool # Should it always be built? (no matter what -t | --targets is)
28+ requires : Dependencies # Build dependencies of the target
2929
3030
31- TARGETS : typing .List [MFCTarget ] = [
32- MFCTarget ('fftw' , ['-DMFC_FFTW=ON' ], True , False , False , MFCTarget .Dependencies ([], [], [])),
33- MFCTarget ('hdf5' , ['-DMFC_HDF5=ON' ], True , False , False , MFCTarget .Dependencies ([], [], [])),
34- MFCTarget ('silo' , ['-DMFC_SILO=ON' ], True , False , False , MFCTarget .Dependencies (["hdf5" ], [], [])),
35- MFCTarget ('pre_process' , ['-DMFC_PRE_PROCESS=ON' ], False , True , False , MFCTarget .Dependencies ([], [], [])),
36- MFCTarget ('simulation' , ['-DMFC_SIMULATION=ON' ], False , True , False , MFCTarget .Dependencies ([], ["fftw" ], [])),
37- MFCTarget ('post_process' , ['-DMFC_POST_PROCESS=ON' ], False , True , False , MFCTarget .Dependencies (['fftw' , 'silo' ], [], [])),
38- MFCTarget ('syscheck' , ['-DMFC_SYSCHECK=ON' ], False , False , True , MFCTarget .Dependencies ([], [], [])),
39- MFCTarget ('documentation' , ['-DMFC_DOCUMENTATION=ON' ], False , False , False , MFCTarget .Dependencies ([], [], []))
40- ]
31+ FFTW = MFCTarget ('fftw' , ['-DMFC_FFTW=ON' ], True , False , False , MFCTarget .Dependencies ([], [], []))
32+ HDF5 = MFCTarget ('hdf5' , ['-DMFC_HDF5=ON' ], True , False , False , MFCTarget .Dependencies ([], [], []))
33+ SILO = MFCTarget ('silo' , ['-DMFC_SILO=ON' ], True , False , False , MFCTarget .Dependencies (["hdf5" ], [], []))
34+ PRE_PROCESS = MFCTarget ('pre_process' , ['-DMFC_PRE_PROCESS=ON' ], False , True , False , MFCTarget .Dependencies ([], [], []))
35+ SIMULATION = MFCTarget ('simulation' , ['-DMFC_SIMULATION=ON' ], False , True , False , MFCTarget .Dependencies ([], ["fftw" ], []))
36+ POST_PROCESS = MFCTarget ('post_process' , ['-DMFC_POST_PROCESS=ON' ], False , True , False , MFCTarget .Dependencies (['fftw' , 'silo' ], [], []))
37+ SYSCHECK = MFCTarget ('syscheck' , ['-DMFC_SYSCHECK=ON' ], False , False , True , MFCTarget .Dependencies ([], [], []))
38+ DOCUMENTATION = MFCTarget ('documentation' , ['-DMFC_DOCUMENTATION=ON' ], False , False , False , MFCTarget .Dependencies ([], [], []))
4139
40+ TARGETS : typing .List [MFCTarget ] = [ FFTW , HDF5 , SILO , PRE_PROCESS , SIMULATION , POST_PROCESS , SYSCHECK , DOCUMENTATION ]
4241
4342def get_mfc_target_names () -> typing .List [str ]:
4443 return [ target .name for target in TARGETS if target .isDefault ]
@@ -66,23 +65,53 @@ def get_target(name: str) -> MFCTarget:
6665
6766# Get path to directory that will store the build files
6867def get_build_dirpath (target : MFCTarget ) -> str :
69- return os .sep .join ([os .getcwd (), "build" , target .name ])
68+ return os .sep .join ([
69+ os .getcwd (),
70+ "build" ,
71+ [CFG ().make_slug (), 'dependencies' ][int (target .isDependency )],
72+ target .name
73+ ])
7074
7175
7276# Get the directory that contains the target's CMakeLists.txt
7377def get_cmake_dirpath (target : MFCTarget ) -> str :
74- subdir = ["" , os .sep .join (["toolchain" , "dependencies" ])][int (target .isDependency )]
75-
76- return os .sep .join ([os .getcwd (), subdir ])
77-
78+ # The CMakeLists.txt file is located:
79+ # * Regular: <root>/CMakelists.txt
80+ # * Dependency: <root>/toolchain/dependencies/CMakelists.txt
81+ return os .sep .join ([
82+ os .getcwd (),
83+ os .sep .join (["toolchain" , "dependencies" ]) if target .isDependency else "" ,
84+ ])
85+
86+
87+ def get_install_dirpath (target : MFCTarget ) -> str :
88+ # The install directory is located:
89+ # Regular: <root>/build/install/<configuration_slug>
90+ # Dependency: <root>/build/install/dependencies (shared)
91+ return os .sep .join ([
92+ os .getcwd (),
93+ "build" ,
94+ "install" ,
95+ 'dependencies' if target .isDependency else CFG ().make_slug ()
96+ ])
97+
98+
99+ def get_dependency_install_dirpath () -> str :
100+ # Since dependencies share the same install directory, we can just return
101+ # the install directory of the first dependency we find.
102+ for target in TARGETS :
103+ if target .isDependency :
104+ return get_install_dirpath (target )
78105
79- def get_install_dirpath () -> str :
80- return os .sep .join ([os .getcwd (), "build" , "install" ])
106+ raise common .MFCException ("No dependency target found." )
81107
82108
83109def is_target_configured (target : MFCTarget ) -> bool :
84- cmake_cachepath = os .sep .join ([get_build_dirpath (target ), "CMakeCache.txt" ])
85- return os .path .isfile (cmake_cachepath )
110+ # We assume that if the CMakeCache.txt file exists, then the target is
111+ # configured. (this isn't perfect, but it's good enough for now)
112+ return os .path .isfile (
113+ os .sep .join ([get_build_dirpath (target ), "CMakeCache.txt" ])
114+ )
86115
87116
88117def clean_target (name : str ):
@@ -146,7 +175,9 @@ def build_target(name: str, history: typing.List[str] = None):
146175
147176 build_dirpath = get_build_dirpath (target )
148177 cmake_dirpath = get_cmake_dirpath (target )
149- install_dirpath = get_install_dirpath ()
178+ install_dirpath = get_install_dirpath (target )
179+
180+ install_prefixes = ';' .join ([install_dirpath , get_dependency_install_dirpath ()])
150181
151182 flags : list = target .flags .copy () + [
152183 # Disable CMake warnings intended for developers (us).
@@ -163,10 +194,10 @@ def build_target(name: str, history: typing.List[str] = None):
163194 # second heighest level of priority, still letting users manually
164195 # specify <PackageName>_ROOT, which has precedence over CMAKE_PREFIX_PATH.
165196 # See: https://cmake.org/cmake/help/latest/command/find_package.html.
166- f"-DCMAKE_PREFIX_PATH={ install_dirpath } " ,
197+ f"-DCMAKE_PREFIX_PATH={ install_prefixes } " ,
167198 # First directory that FIND_LIBRARY searches.
168199 # See: https://cmake.org/cmake/help/latest/command/find_library.html.
169- f"-DCMAKE_FIND_ROOT_PATH={ install_dirpath } " ,
200+ f"-DCMAKE_FIND_ROOT_PATH={ install_prefixes } " ,
170201 # Location prefix to install bin/, lib/, include/, etc.
171202 # See: https://cmake.org/cmake/help/latest/command/install.html.
172203 f"-DCMAKE_INSTALL_PREFIX={ install_dirpath } " ,
0 commit comments