(includeDir string)
| 368 | } |
| 369 | |
| 370 | func (b *BuildConfig) appendIncludeDir(includeDir string) { |
| 371 | // Windows: MSVC/Clang-cl ------------------------------ Linux: GCC/Clang |
| 372 | // INCLUDE=xxx\include;%INCLUDE% ---------------------- -I "xxx\include" |
| 373 | // CL=/external:anglebrackets /external:W0 %CL% -------- -I "xxx\include" |
| 374 | |
| 375 | // Toolchain may throw error if include dir not exists. |
| 376 | if !fileio.PathExists(includeDir) { |
| 377 | return |
| 378 | } |
| 379 | |
| 380 | toolchain := b.Ctx.Platform().GetToolchain() |
| 381 | switch toolchain.GetName() { |
| 382 | case "gcc", "clang", "qcc": |
| 383 | cflags := strings.Fields(os.Getenv("CFLAGS")) |
| 384 | cxxflags := strings.Fields(os.Getenv("CXXFLAGS")) |
| 385 | |
| 386 | // Check if this is a dependency include dir (tmpDeps/include) - if so, prepend it. |
| 387 | tmpDepsPrefix := filepath.Join(dirs.TmpDepsDir, b.PortConfig.LibraryDir) |
| 388 | isDepsIncludeDir := strings.Contains(includeDir, tmpDepsPrefix) |
| 389 | |
| 390 | // Append include dir if not exists. |
| 391 | // Prepend dependency include dir flags to prioritize them. |
| 392 | includeFlag := "-I" + includeDir |
| 393 | var newAppended = false |
| 394 | if !slices.Contains(cflags, includeFlag) { |
| 395 | if isDepsIncludeDir { |
| 396 | cflags = append([]string{includeFlag}, cflags...) |
| 397 | } else { |
| 398 | cflags = append(cflags, includeFlag) |
| 399 | } |
| 400 | newAppended = true |
| 401 | } |
| 402 | if !slices.Contains(cxxflags, includeFlag) { |
| 403 | if isDepsIncludeDir { |
| 404 | cxxflags = append([]string{includeFlag}, cxxflags...) |
| 405 | } else { |
| 406 | cxxflags = append(cxxflags, includeFlag) |
| 407 | } |
| 408 | newAppended = true |
| 409 | } |
| 410 | |
| 411 | // Update environment variable with modified flags. |
| 412 | if newAppended { |
| 413 | b.envBackup.setenv("CFLAGS", strings.Join(cflags, " ")) |
| 414 | b.envBackup.setenv("CXXFLAGS", strings.Join(cxxflags, " ")) |
| 415 | } |
| 416 | |
| 417 | case "msvc", "clang-cl": |
| 418 | // Append include dir if not exists. |
| 419 | includes := strings.Fields(os.Getenv("INCLUDE")) |
| 420 | if !slices.Contains(includes, includeDir) { |
| 421 | includes = append(includes, includeDir) |
| 422 | b.envBackup.setenv("INCLUDE", strings.Join(includes, ";")) |
| 423 | } |
| 424 | |
| 425 | // Avoid warning by setting "CL=/external:anglebrackets /external:W0 %CL%" |
| 426 | cl := strings.Fields(os.Getenv("CL")) |
| 427 | if !slices.Contains(cl, "/external:anglebrackets") { |
no test coverage detected