Re: [CMake] Hard to do if in Macro
Okay... but then with function I can't set external variables; but if( __ANDROID__ ) works. `result` never changes. --- set( __ANDROID__ 1 ) function( test __ANDROID__ RETVAL ) if( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON") set( ${RETVAL} ${${RETVAL}} qwer2 ) message( "Included. " ) endif( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON") if( __ANDROID__ ) set( ${RETVAL} ${${RETVAL}} asdf ) message( "ALWAYS Included ${__ANDROID__}" ) endif( __ANDROID__ ) endfunction( test ) set( result "default" ) test( __ANDROID__ "result" ) message( "REsult:${result}" ) test( ${__ANDROID__} "result" ) message( "REsult:${result}" ) test( OFF "result") message( "REsult:${result}" ) --- On Tue, Jan 30, 2018 at 12:35 AM, Petr Kmoch wrote: > Macros aren't functions, and macro parameters aren't CMake variables. > Expanding a macro parameter is effectively *textual* substitution, whereas > dereferencing a CMake variable is a semantic one. > > In other words, inside your macro, the text __ANDROID__ (when not > expanded) never refers to the macro parameter. Macro parameters "don't > exist" outside of expansion context. The `if(__ANDROID__)` bit therefore > always refers to the variable __ANDROID__, never to the macro parameter > __ANDROID__. > > You still don't have to spell out the conditional as explicitly as you're > doing it now, but you have to expand the parameter: > > macro(test __ANDROID__) > if(${__ANDROID__}) > message( "Included. " ) > endif() > endmacro() > > This is what the evaluation will look like based on how you call it: > > test(__ANDROID__) -> if(__ANDROID__) -> refers to the variable > set(__ANDROID__ 1) > test(${__ANDROID__}) -> if(1) > set(__ANDROID__ 0) > test(${__ANDROID__}) -> if(0) > test(OFF) -> if(OFF) > > CMake macros have a lot of specific and potentially weird/counterintuitive > behaviour. In general, you should always write your commands as functions > and only resort to macros if you explicitly need their specific behaviour. > > Petr > > > > On 30 January 2018 at 09:11, J Decker wrote: > >> Why do I have to do >> >> if( ${M__ANDROID__} EQUAL 1 OR ${M__ANDROID__} STREQUAL "ON") >> endif( ${M__ANDROID__} EQUAL 1 OR ${M__ANDROID__} STREQUAL "ON") >> >> in a macro like... >> -- >> >> set( __ANDROID__ 1 ) >> >> macro( test __ANDROID__ ) >> >> if( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON") >> message( "Included. " ) >> endif( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON") >> >> if( __ANDROID__ ) >> message( "ALWAYS Included ${__ANDROID__}" ) >> endif( __ANDROID__ ) >> >> endmacro( test ) >> >> test( __ANDROID__ ) >> test( ${__ANDROID__} ) >> test( OFF ) >> >> -- >> Output >> >> Included. >> ALWAYS Included __ANDROID__ >> Included. >> ALWAYS Included 1 >> ALWAYS Included OFF >> >> -- >> >> Powered by www.kitware.com >> >> Please keep messages on-topic and check the CMake FAQ at: >> http://www.cmake.org/Wiki/CMake_FAQ >> >> Kitware offers various services to support the CMake community. For more >> information on each offering, please visit: >> >> CMake Support: http://cmake.org/cmake/help/support.html >> CMake Consulting: http://cmake.org/cmake/help/consulting.html >> CMake Training Courses: http://cmake.org/cmake/help/training.html >> >> Visit other Kitware open-source projects at >> http://www.kitware.com/opensource/opensource.html >> >> Follow this link to subscribe/unsubscribe: >> https://cmake.org/mailman/listinfo/cmake >> >> > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
[CMake] Referencing nuget packages in csharp csproj files
Hello, we're looking into generating our C# projects using CMAKE. We can generate working solution files, but we're still struggling with dependencies. We would like to manage nuget packages via the nuget.exe command line tool. With the install or restore parameter this deems us a good approach for managing dependencies. However, CMAKE currently only supports the Reference tag in the csproj file. Without an additional HintPath subtag into the package's folder the reference is not resolved. This HintPath points down the whole path to the DLL of the package, including version etc. So far I have not found a way how to extract this path from nuget.exe and I would not like having to guess it to fill the HintPath tag. Any ideas how to solve this issue? We found that using the new PackageReference tag (new since VS2017) would work fine without a HintPath and would offer complete configuration of dependencies via nuget. So we wondered if CMAKE could support this new PackageReference tag, too, like it does for the Reference tag by means of the VS_DOTNET_REFERENCES? Or is there any way how we could inject the XML into the generated csproj file ourselves from the project's CMakeLists.txt? Looking into the CMAKE source code, I think supporting the PackageReference tag would basically require going along the lines of the VS_DOTNET_REFERENCES property handling. However, I don't know if another property like this (e.g. VS_DOTNET_PACKAGEREFERENCES) would be appreciated by the CMAKE team or whether there are better solutions? If such a property were acceptable maybe we could even try to offer a patch for CMAKE. Thank you! Cheers, Jörn -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
Re: [CMake] Hard to do if in Macro
Macros aren't functions, and macro parameters aren't CMake variables. Expanding a macro parameter is effectively *textual* substitution, whereas dereferencing a CMake variable is a semantic one. In other words, inside your macro, the text __ANDROID__ (when not expanded) never refers to the macro parameter. Macro parameters "don't exist" outside of expansion context. The `if(__ANDROID__)` bit therefore always refers to the variable __ANDROID__, never to the macro parameter __ANDROID__. You still don't have to spell out the conditional as explicitly as you're doing it now, but you have to expand the parameter: macro(test __ANDROID__) if(${__ANDROID__}) message( "Included. " ) endif() endmacro() This is what the evaluation will look like based on how you call it: test(__ANDROID__) -> if(__ANDROID__) -> refers to the variable set(__ANDROID__ 1) test(${__ANDROID__}) -> if(1) set(__ANDROID__ 0) test(${__ANDROID__}) -> if(0) test(OFF) -> if(OFF) CMake macros have a lot of specific and potentially weird/counterintuitive behaviour. In general, you should always write your commands as functions and only resort to macros if you explicitly need their specific behaviour. Petr On 30 January 2018 at 09:11, J Decker wrote: > Why do I have to do > > if( ${M__ANDROID__} EQUAL 1 OR ${M__ANDROID__} STREQUAL "ON") > endif( ${M__ANDROID__} EQUAL 1 OR ${M__ANDROID__} STREQUAL "ON") > > in a macro like... > -- > > set( __ANDROID__ 1 ) > > macro( test __ANDROID__ ) > > if( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON") > message( "Included. " ) > endif( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON") > > if( __ANDROID__ ) > message( "ALWAYS Included ${__ANDROID__}" ) > endif( __ANDROID__ ) > > endmacro( test ) > > test( __ANDROID__ ) > test( ${__ANDROID__} ) > test( OFF ) > > -- > Output > > Included. > ALWAYS Included __ANDROID__ > Included. > ALWAYS Included 1 > ALWAYS Included OFF > > -- > > Powered by www.kitware.com > > Please keep messages on-topic and check the CMake FAQ at: > http://www.cmake.org/Wiki/CMake_FAQ > > Kitware offers various services to support the CMake community. For more > information on each offering, please visit: > > CMake Support: http://cmake.org/cmake/help/support.html > CMake Consulting: http://cmake.org/cmake/help/consulting.html > CMake Training Courses: http://cmake.org/cmake/help/training.html > > Visit other Kitware open-source projects at http://www.kitware.com/ > opensource/opensource.html > > Follow this link to subscribe/unsubscribe: > https://cmake.org/mailman/listinfo/cmake > > -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
[CMake] Hard to do if in Macro
Why do I have to do if( ${M__ANDROID__} EQUAL 1 OR ${M__ANDROID__} STREQUAL "ON") endif( ${M__ANDROID__} EQUAL 1 OR ${M__ANDROID__} STREQUAL "ON") in a macro like... -- set( __ANDROID__ 1 ) macro( test __ANDROID__ ) if( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON") message( "Included. " ) endif( ${__ANDROID__} EQUAL 1 OR ${__ANDROID__} STREQUAL "ON") if( __ANDROID__ ) message( "ALWAYS Included ${__ANDROID__}" ) endif( __ANDROID__ ) endmacro( test ) test( __ANDROID__ ) test( ${__ANDROID__} ) test( OFF ) -- Output Included. ALWAYS Included __ANDROID__ Included. ALWAYS Included 1 ALWAYS Included OFF -- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake