From 152636387709539134a71fff89e4831cbffbb040 Mon Sep 17 00:00:00 2001 From: Renaud Guillard Date: Wed, 4 Nov 2020 10:55:30 +0100 Subject: [PATCH 1/2] Add frameworkdirs support to gmake and gmake2 with gcc/clang toolsets on macOS systems * Add new optional parameter to toolset.getincludedirs(dirs, sysdirs, frameworkdirs) * Translate frameworkdirs to -F build & linker flags * Add tests Co-authored-by: Joris Dauphin Co-authored-by: Samuel Surtees --- modules/gmake/gmake_cpp.lua | 2 +- modules/gmake2/gmake2_cpp.lua | 6 ++--- src/tools/clang.lua | 4 +-- src/tools/gcc.lua | 17 ++++++++++++- src/tools/msc.lua | 2 +- tests/tools/test_gcc.lua | 48 +++++++++++++++++++++++++++++++++++ 6 files changed, 71 insertions(+), 8 deletions(-) diff --git a/modules/gmake/gmake_cpp.lua b/modules/gmake/gmake_cpp.lua index e1e561ef..5fa7d168 100644 --- a/modules/gmake/gmake_cpp.lua +++ b/modules/gmake/gmake_cpp.lua @@ -521,7 +521,7 @@ end function make.includes(cfg, toolset) - local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs) + local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs, cfg.frameworkdirs) _p(' INCLUDES +=%s', make.list(includes)) end diff --git a/modules/gmake2/gmake2_cpp.lua b/modules/gmake2/gmake2_cpp.lua index bc45cbd2..d9d4a2c4 100644 --- a/modules/gmake2/gmake2_cpp.lua +++ b/modules/gmake2/gmake2_cpp.lua @@ -386,7 +386,7 @@ function cpp.includes(cfg, toolset) - local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs) + local includes = toolset.getincludedirs(cfg, cfg.includedirs, cfg.sysincludedirs, cfg.frameworkdirs) p.outln('INCLUDES +=' .. gmake2.list(includes)) end @@ -531,8 +531,8 @@ end end - if fcfg.includedirs or fcfg.sysincludedirs then - local includes = toolset.getincludedirs(cfg, fcfg.includedirs, fcfg.sysincludedirs) + if fcfg.includedirs or fcfg.sysincludedirs or fcfg.frameworkdirs then + local includes = toolset.getincludedirs(cfg, fcfg.includedirs, fcfg.sysincludedirs, fcfg.frameworkdirs) if #includes > 0 then value = value .. gmake2.list(includes) end diff --git a/src/tools/clang.lua b/src/tools/clang.lua index 1da61dfb..4eede91d 100644 --- a/src/tools/clang.lua +++ b/src/tools/clang.lua @@ -186,10 +186,10 @@ -- An array of symbols with the appropriate flag decorations. -- - function clang.getincludedirs(cfg, dirs, sysdirs) + function clang.getincludedirs(cfg, dirs, sysdirs, frameworkdirs) -- Just pass through to GCC for now - local flags = gcc.getincludedirs(cfg, dirs, sysdirs) + local flags = gcc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs) return flags end diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index d7942747..d6bcd71f 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -284,12 +284,20 @@ -- Decorate include file search paths for the GCC command line. -- - function gcc.getincludedirs(cfg, dirs, sysdirs) + function gcc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs) local result = {} for _, dir in ipairs(dirs) do dir = project.getrelative(cfg.project, dir) table.insert(result, '-I' .. p.quoted(dir)) end + + if table.contains(os.getSystemTags(cfg.system), "darwin") then + for _, dir in ipairs(frameworkdirs or {}) do + dir = project.getrelative(cfg.project, dir) + table.insert(result, '-F' .. p.quoted(dir)) + end + end + for _, dir in ipairs(sysdirs or {}) do dir = project.getrelative(cfg.project, dir) table.insert(result, '-isystem ' .. p.quoted(dir)) @@ -481,6 +489,13 @@ table.insert(flags, '-L' .. p.quoted(dir)) end + if table.contains(os.getSystemTags(cfg.system), "darwin") then + for _, dir in ipairs(cfg.frameworkdirs) do + dir = project.getrelative(cfg.project, dir) + table.insert(flags, '-F' .. p.quoted(dir)) + end + end + if cfg.flags.RelativeLinks then for _, dir in ipairs(config.getlinks(cfg, "siblings", "directory")) do local libFlag = "-L" .. p.project.getrelative(cfg.project, dir) diff --git a/src/tools/msc.lua b/src/tools/msc.lua index c4d5fddf..9a4c37ca 100644 --- a/src/tools/msc.lua +++ b/src/tools/msc.lua @@ -231,7 +231,7 @@ -- Decorate include file search paths for the MSVC command line. -- - function msc.getincludedirs(cfg, dirs, sysdirs) + function msc.getincludedirs(cfg, dirs, sysdirs, frameworkdirs) local result = {} dirs = table.join(dirs, sysdirs) for _, dir in ipairs(dirs) do diff --git a/tests/tools/test_gcc.lua b/tests/tools/test_gcc.lua index 4a81c42d..faf2e9a9 100644 --- a/tests/tools/test_gcc.lua +++ b/tests/tools/test_gcc.lua @@ -674,6 +674,54 @@ test.contains("-L/usr/local/lib", gcc.getLibraryDirectories(cfg)) end +-- +-- Check handling of Apple frameworks search paths +-- + function suite.includeDirs_notDarwin_onFrameworkDirs() + system "Linux" + frameworkdirs { "/Library/Frameworks" } + prepare() + test.excludes("-F/Library/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs)) + end + + function suite.libDirs_notDarwin_onFrameworkDirs() + system "Windows" + frameworkdirs { "/Library/Frameworks" } + prepare() + test.excludes("-F/Library/Frameworks", gcc.getLibraryDirectories(cfg)) + end + + function suite.includeDirs_macosx_onFrameworkDirs() + system "MacOSX" + location "subdir" + frameworkdirs { + "/Library/Frameworks", + "subdir/Relative/Frameworks" + } + prepare() + test.contains("-F/Library/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs)) + test.contains("-FRelative/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs)) + end + + function suite.libDirs_macosx_onFrameworkDirs() + system "MacOSX" + location "subdir" + frameworkdirs { + "/Library/Frameworks", + "subdir/Relative/Frameworks" + } + prepare() + test.contains("-F/Library/Frameworks", gcc.getLibraryDirectories(cfg)) + test.contains("-FRelative/Frameworks", gcc.getLibraryDirectories(cfg)) + end + + function suite.includeDirs_ios_onFrameworkDirs() + system "iOS" + frameworkdirs { "/Library/Frameworks" } + prepare() + test.contains("-F/Library/Frameworks", gcc.getincludedirs(cfg, {}, {}, cfg.frameworkdirs)) + end + -- -- Check handling of link time optimization flag. From f78741fcf1d7294ce08b0b7cf6ecadf864890ef2 Mon Sep 17 00:00:00 2001 From: Renaud Guillard Date: Tue, 7 Sep 2021 23:26:52 +0200 Subject: [PATCH 2/2] frameworkdirs and runpathdirs support for CodeLite generator --- modules/codelite/codelite_project.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/codelite/codelite_project.lua b/modules/codelite/codelite_project.lua index 4396f0c0..c0d95e75 100755 --- a/modules/codelite/codelite_project.lua +++ b/modules/codelite/codelite_project.lua @@ -195,7 +195,7 @@ end local toolset = m.getcompiler(cfg) - local sysincludedirs = toolset.getincludedirs(cfg, {}, cfg.sysincludedirs) + local sysincludedirs = toolset.getincludedirs(cfg, {}, cfg.sysincludedirs, cfg.frameworkdirs) local forceincludes = toolset.getforceincludes(cfg) local cxxflags = table.concat(table.join(sysincludedirs, toolset.getcxxflags(cfg), forceincludes, cfg.buildoptions), ";") local cflags = table.concat(table.join(sysincludedirs, toolset.getcflags(cfg), forceincludes, cfg.buildoptions), ";") @@ -225,7 +225,7 @@ end local toolset = m.getcompiler(cfg) - local flags = table.join(toolset.getldflags(cfg), cfg.linkoptions, toolset.getlinks(cfg)) + local flags = table.join(toolset.getldflags(cfg), toolset.getincludedirs(cfg, {}, nil, cfg.frameworkdirs), toolset.getrunpathdirs(cfg, table.join(cfg.runpathdirs, config.getsiblingtargetdirs(cfg))), cfg.linkoptions, toolset.getlinks(cfg)) _x(3, '', table.concat(flags, ";"))