diff --git a/samples/cxx/Makefile.in b/samples/cxx/Makefile.in index 18ca914cf01..54db95cd9cd 100644 --- a/samples/cxx/Makefile.in +++ b/samples/cxx/Makefile.in @@ -17,4 +17,4 @@ clean: $(RM) $(OBJS) @tmpl_progname@ dist-clean: clean - $(RM) *~ + $(RM) *~ diff --git a/samples/cxx/SConscript b/samples/cxx/SConscript index 4e8826c4d1b..4764b041062 100644 --- a/samples/cxx/SConscript +++ b/samples/cxx/SConscript @@ -52,22 +52,41 @@ set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}) # Note: These Makefiles and SConstruct files are automatically installed # by the "RecursiveInstall" that grabs everything in the cxx directory. - incdirs = (localenv['ct_incroot'], localenv['sundials_include'], - localenv['boost_inc_dir']) + tuple(localenv['extra_inc_dirs']) - libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'], - localenv['blas_lapack_dir']) + tuple(localenv['extra_lib_dirs'])) - # Remove sysroot and macOS min version flags in templated output files - # Users should compile against their local SDKs, which should be backwards - # compatible with the SDK used for building. This only applies to the - # conda package for now. - if env['OS'] == 'Darwin' and os.environ.get('CONDA_BUILD', False): - ccFlags = [] - for flag in localenv['CCFLAGS'] + localenv['CXXFLAGS']: - if not flag.startswith(('-isysroot', '-mmacosx', '/App')): - ccFlags.append(flag) + incdirs = [localenv["ct_incroot"]] + libdirs = [localenv["ct_libdir"]] + if localenv["conda_build"]: + # Remove sysroot flags in templated output files. This only applies to the + # conda package for now. + # Users should compile against their local SDKs, which should be backwards + # compatible with the SDK used for building. + def split_compiler_flags(flags, excludes=[]): + """ + Separate concatenated compiler flags in flag list. + Entries listed in 'exclude' are omitted. + """ + flags = " ".join(flags) + flags = f" {flags}".split(" -")[1:] + # split concatenated entries + flags = [f"-{flag}" for flag in flags] + cc_flags = [] + for flag in flags: + if not flag.startswith(excludes) and flag not in cc_flags: + cc_flags.append(flag) + return cc_flags + + excludes = ( + "-isysroot", "-mmacosx", "-march", "-mtune", "-fdebug-prefix-map") + cc_flags = split_compiler_flags(localenv["CCFLAGS"] + localenv["CXXFLAGS"], + excludes) else: - ccFlags = localenv['CCFLAGS'] + localenv['CXXFLAGS'] - localenv['tmpl_compiler_flags'] = repr(ccFlags) + incdirs.extend([localenv["sundials_include"], localenv["boost_inc_dir"]]) + incdirs.extend(localenv["extra_inc_dirs"]) + libdirs.extend([localenv["sundials_libdir"], localenv["blas_lapack_dir"]]) + libdirs.extend(localenv["extra_lib_dirs"]) + + cc_flags = localenv["CCFLAGS"] + localenv["CXXFLAGS"] + + localenv["tmpl_compiler_flags"] = repr(cc_flags) localenv['tmpl_cantera_frameworks'] = repr(localenv['FRAMEWORKS']) localenv['tmpl_cantera_incdirs'] = repr([x for x in incdirs if x]) localenv['cmake_cantera_incdirs'] = ' '.join(quoted(x) for x in incdirs if x) @@ -90,12 +109,20 @@ set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}) env_args.append('MSVC_VERSION={0!r}'.format(localenv['MSVC_VERSION'])) localenv['tmpl_env_args'] = ', '.join(env_args) - # If this is a conda build on macOS, we do not want to specify the conda - # compilers from the build environment, because those won't be installed - # on the user's system. - if env['OS'] == 'Darwin' and os.environ.get('CONDA_BUILD', False): - localenv['CXX'] = 'clang++' - localenv['CC'] = 'clang' + if localenv["conda_build"]: + # We do not want to specify the conda compilers from the build environment, + # because those won't be installed on the user's system. + if localenv["OS"] == "Darwin": + localenv["CXX"] = "clang++" + localenv["CC"] = "clang" + elif env["OS"] == "Windows": + # compilation needs the Visual Studio Command Prompt + # TODO: verify + localenv["CXX"] = "" + localenv["CC"] = "" + else: + localenv["CXX"] = "g++" + localenv["CC"] = "gcc" sconstruct = localenv.SubstFile(pjoin(subdir, 'SConstruct'), 'SConstruct.in') install(pjoin('$inst_sampledir', 'cxx', subdir), sconstruct) @@ -106,7 +133,7 @@ set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}) ## Generate Makefiles to be installed mak_path = pjoin(localenv['ct_incroot'], 'cantera', 'Cantera.mak') - localenv['mak_compiler_flags'] = ' '.join(ccFlags) + localenv["mak_compiler_flags"] = " ".join(cc_flags) if ' ' in mak_path: # There is no reasonable way to handle spaces in Makefile 'include' # statement, so we fall back to using the relative path instead diff --git a/samples/f77/Makefile.in b/samples/f77/Makefile.in index 8e53770f670..3f2f4b4593f 100644 --- a/samples/f77/Makefile.in +++ b/samples/f77/Makefile.in @@ -12,7 +12,7 @@ OBJS=isentropic.o demo_ftnlib.o all: isentropic isentropic: $(OBJS) - $(F77) $(LDFLAGS) -o isentropic $(OBJS) $(LDLIBS) + $(F77) $(LDFLAGS) -o isentropic $(OBJS) $(LDLIBS) -Wl,-rpath=$(CANTERA_LIBS) clean: $(RM) $(OBJS) diff --git a/samples/f77/SConscript b/samples/f77/SConscript index 541dedfb7c0..0cde60d36a6 100644 --- a/samples/f77/SConscript +++ b/samples/f77/SConscript @@ -23,11 +23,15 @@ for program_name, fortran_sources in samples: LINK='$FORTRAN_LINK') # Generate SConstruct file to be installed -incdirs = (localenv['ct_incroot'], localenv['sundials_include'], - localenv['boost_inc_dir']) + tuple(localenv['extra_inc_dirs']) +incdirs = [localenv["ct_incroot"]] +libdirs = [localenv["ct_libdir"]] +if not localenv["conda_build"]: + incdirs.extend([localenv["sundials_include"], localenv["boost_inc_dir"]]) + incdirs.extend(localenv["extra_inc_dirs"]) + libdirs.extend([localenv["sundials_libdir"], localenv["blas_lapack_dir"]]) + libdirs.extend(localenv["extra_lib_dirs"]) + libs = ['cantera_fortran'] + localenv['cantera_libs'] + env['cxx_stdlib'] -libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'], - localenv['blas_lapack_dir']) + tuple(localenv['extra_lib_dirs'])) linkflags = ('-g', localenv['thread_flags']) mak_path = pjoin(localenv['ct_incroot'], 'cantera', 'Cantera.mak') @@ -43,6 +47,19 @@ localenv['tmpl_cantera_libdirs'] = repr([x for x in libdirs if x]) localenv['tmpl_cantera_linkflags'] = repr([x for x in linkflags if x]) localenv['tmpl_cantera_frameworks'] = repr(localenv['FRAMEWORKS']) +if localenv["conda_build"]: + # We do not want to specify the conda compilers from the build environment, + # because those won't be installed on the user's system. + if localenv["OS"] == "Darwin": + localenv["CC"] = "clang" + elif env["OS"] == "Windows": + # compilation needs the Visual Studio Command Prompt + # TODO: verify + localenv["CC"] = "" + else: + localenv["F77"] = "gfortran" + localenv["CC"] = "gcc" + sconstruct = localenv.SubstFile('SConstruct', 'SConstruct.in') # Generate Makefile to be installed diff --git a/samples/f90/Makefile.in b/samples/f90/Makefile.in index 8f15129979a..7a44759bf96 100644 --- a/samples/f90/Makefile.in +++ b/samples/f90/Makefile.in @@ -13,7 +13,7 @@ OBJS=$(subst .f90,.o,$(SRCS)) all: @make_target@ @make_target@: $(OBJS) - $(F90) $(LDFLAGS) -o @make_target@ $(OBJS) $(LDLIBS) + $(F90) $(LDFLAGS) -o @make_target@ $(OBJS) $(LDLIBS) -Wl,-rpath=$(CANTERA_LIBS) %.o : %.f90 $(F90) -c $< @FORTRANMODDIRPREFIX@$(F90MODDIR) $(F90FLAGS) diff --git a/samples/f90/SConscript b/samples/f90/SConscript index 21a8bb80849..068d965908f 100644 --- a/samples/f90/SConscript +++ b/samples/f90/SConscript @@ -18,10 +18,15 @@ for programName, sources in samples: LINK='$FORTRAN_LINK') # Generate SConstruct files to be installed - incdirs = [pjoin(localenv['ct_incroot'], 'cantera')] + localenv['extra_inc_dirs'] + incdirs = [pjoin(localenv["ct_incroot"], "cantera")] # path to fortran .mod + libdirs = [localenv["ct_libdir"]] + if not localenv["conda_build"]: + incdirs.extend([localenv["sundials_include"], localenv["boost_inc_dir"]]) + incdirs.extend(localenv["extra_inc_dirs"]) + libdirs.extend([localenv["sundials_libdir"], localenv["blas_lapack_dir"]]) + libdirs.extend(localenv["extra_lib_dirs"]) + libs = ['cantera_fortran'] + localenv['cantera_libs'] + env['cxx_stdlib'] - libdirs = ((localenv['ct_libdir'], localenv['sundials_libdir'], - localenv['blas_lapack_dir']) + tuple(localenv['extra_lib_dirs'])) linkflags = ('-g', localenv['thread_flags']) mak_path = pjoin(localenv['ct_incroot'], 'cantera', 'Cantera.mak')