gyp - how to specify link library flavor
Asked Answered
A

2

13

I'm writing a native node module and I'd like to be able to build it in release and debug versions.

The node module links to another library, which has a debug and release version in two different directories.

Now this is where I'm stuck - how do I specify the library directory for the current configuration being built?

I've tried setting that in configurations.debug.link_settings key, but I get the error: 'link_settings not allowed in the Debug configuration, found in target binding.gyp

Aeri answered 20/12, 2012 at 20:20 Comment(0)
A
17

Apparently this is not possible in a cross-platform way. So hopefully this will spare you a couple of hours of experimentation.

This is a gyp file which builds the addon for Mac and Windows.

//This example assumes you have an external library 'thelibrary', located in 
//./external/thelibrary
//With the two flavors, debug and release in lib/debug and lib/release
{
    "targets": [
        {
            "target_name": "addon",
            "sources": [
                "src/addon.cpp",
                "src/expose_the_library.cpp"
            ],
            "include_dirs": [
                "external/thelibrary/include"
            ],
            "cflags!": [
                "-fno-exceptions"
            ],
            "cflags_cc!": [
                "-fno-exceptions"
            ],
            "conditions": [
                [
                    "OS=='mac'",
                    {
                        "defines": [
                            "__MACOSX_CORE__"
                        ],
                        "architecture": "i386",
                        "xcode_settings": {
                            "GCC_ENABLE_CPP_EXCEPTIONS": "YES"
                        },
                        "link_settings": {
                            "libraries": [
                                "-lthelibrary",
                                "-framework",   
                                "IOBluetooth" //this is how you use a framework on OSX
                            ],
                            "configurations": {
                                "Debug": {
                                    "xcode_settings": {
                                        "OTHER_LDFLAGS": [
                                            "-Lexternal/thelibrary/lib/debug"
                                        ]
                                    }
                                },
                                "Release": {
                                    "xcode_settings": {
                                        "OTHER_LDFLAGS": [
                                            "-Lexternal/thelibrary/lib/release"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                ],
                [
                    "OS=='win'",
                    {
                        "link_settings": {
                            "libraries": [
                                "-lthelibrary.lib",
                            ]
                        },
                        "configurations": {
                            "Debug": {
                                "msvs_settings": {
                                    "VCCLCompilerTool": {
                                        "ExceptionHandling": "0",
                                        "AdditionalOptions": [
                                            "/MP /EHsc"
                                        ]
                                    },
                                    "VCLibrarianTool": {
                                        "AdditionalOptions": [
                                            "/LTCG"
                                        ]
                                    },
                                    "VCLinkerTool": {
                                        "LinkTimeCodeGeneration": 1,
                                        "LinkIncremental": 1,
                                        "AdditionalLibraryDirectories": [
                                            "../external/thelibrary/lib/debug"
                                        ]
                                    }
                                }
                            },
                            "Release": {
                                "msvs_settings": {
                                    "VCCLCompilerTool": {
                                        "RuntimeLibrary": 0,
                                        "Optimization": 3,
                                        "FavorSizeOrSpeed": 1,
                                        "InlineFunctionExpansion": 2,
                                        "WholeProgramOptimization": "true",
                                        "OmitFramePointers": "true",
                                        "EnableFunctionLevelLinking": "true",
                                        "EnableIntrinsicFunctions": "true",
                                        "RuntimeTypeInfo": "false",
                                        "ExceptionHandling": "0",
                                        "AdditionalOptions": [
                                            "/MP /EHsc"
                                        ]
                                    },
                                    "VCLibrarianTool": {
                                        "AdditionalOptions": [
                                            "/LTCG"
                                        ]
                                    },
                                    "VCLinkerTool": {
                                        "LinkTimeCodeGeneration": 1,
                                        "OptimizeReferences": 2,
                                        "EnableCOMDATFolding": 2,
                                        "LinkIncremental": 1,
                                        "AdditionalLibraryDirectories": [
                                            "../external/thelibrary/lib/release"
                                        ]
                                    }
                                }
                            }
                        }
                    }
                ]
            ]
        }
    ]
}
Aeri answered 27/12, 2012 at 17:43 Comment(2)
Additional to find the correct settings names use MSVSSettings.pyUnshapen
can we define platform arch for msvs_settings in binding.gyp file ? Ex: Win32/X64/ARM32/ARM64Crossland
A
0

I faced this issue as well and it seems that if you pass --format=make-linux (for example) on the command line it will generate for the 'make' format but it will explicitly use the 'linux' flavor.

Abbott answered 14/4, 2020 at 9:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.