Skip to content

Allow dynamic linking on cmake exported scripts #304

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cmake: Remove '-l' prefix while parsing compile flags
  • Loading branch information
cmaglie committed Oct 17, 2018
commit e34e4b72129eb926eef26fa9f5246fffc163049d
10 changes: 4 additions & 6 deletions create_cmake_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,8 @@ func (s *ExportProjectCMake) Run(ctx *types.Context) error {
// Add SO_PATHS option for libraries not getting found by pkg_config
cmakelist += "set(EXTRA_LIBS_DIRS \"\" CACHE STRING \"Additional paths for dynamic libraries\")\n"

for i, lib := range libs {
for _, lib := range libs {
// Dynamic libraries should be discovered by pkg_config
lib = strings.TrimPrefix(lib, "-l")
libs[i] = lib
cmakelist += "pkg_search_module (" + strings.ToUpper(lib) + " " + lib + ")\n"
relLinkDirectories = append(relLinkDirectories, "${"+strings.ToUpper(lib)+"_LIBRARY_DIRS}")
}
Expand Down Expand Up @@ -205,7 +203,7 @@ func canExportCmakeProject(ctx *types.Context) bool {
return ctx.BuildProperties[constants.BUILD_PROPERTIES_COMPILER_EXPORT_CMAKE_FLAGS] != ""
}

func extractCompileFlags(ctx *types.Context, receipe string, defines, libs, linkerflags, linkDirectories *[]string, logger i18n.Logger) {
func extractCompileFlags(ctx *types.Context, receipe string, defines, dynamicLibs, linkerflags, linkDirectories *[]string, logger i18n.Logger) {
command, _ := builder_utils.PrepareCommandForRecipe(ctx, ctx.BuildProperties, receipe, true)

for _, arg := range command.Args {
Expand All @@ -214,11 +212,11 @@ func extractCompileFlags(ctx *types.Context, receipe string, defines, libs, link
continue
}
if strings.HasPrefix(arg, "-l") {
*libs = utils.AppendIfNotPresent(*libs, arg)
*dynamicLibs = utils.AppendIfNotPresent(*dynamicLibs, arg[2:])
continue
}
if strings.HasPrefix(arg, "-L") {
*linkDirectories = utils.AppendIfNotPresent(*linkDirectories, strings.TrimPrefix(arg, "-L"))
*linkDirectories = utils.AppendIfNotPresent(*linkDirectories, arg[2:])
continue
}
if strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "-I") && !strings.HasPrefix(arg, "-o") {
Expand Down