Skip to content

build cMocka lib manually to VCPKG#875

Merged
vhvb1989 merged 5 commits intoAzure:masterfrom
vhvb1989:path-cmocka-with-relative-path
Jul 1, 2020
Merged

build cMocka lib manually to VCPKG#875
vhvb1989 merged 5 commits intoAzure:masterfrom
vhvb1989:path-cmocka-with-relative-path

Conversation

@vhvb1989
Copy link
Member

@vhvb1989 vhvb1989 commented Jul 1, 2020

Fixes the current regression on Mac.

set(CMOCKA_LIB "debug;${CMOCKA_PREXIF}/debug${CMOCKA_STATIC_LIB};optimized;${CMOCKA_PREXIF}${CMOCKA_STATIC_LIB}")
else()
set(CMOCKA_LIB cmocka)
set(CMOCKA_LIB cmocka)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent

vhvb1989 and others added 3 commits July 1, 2020 12:28
Co-authored-by: danewalton <36710865+danewalton@users.noreply.github.com>
set(VCPKG_PATH $ENV{VCPKG_ROOT})
endif()
if(DEFINED ENV{VCPKG_INSTALLATION_ROOT})
set(VCPKG_PATH "$ENV{VCPKG_INSTALLATION_ROOT}/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the / at the end of the string intentional? Why don't we have the same thing above, in set(VCPKG_PATH $ENV{VCPKG_ROOT})

Also, is that why we surround it in quotes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is intentional.
In the above lines, (usually Linux and Windows) the VCPK_ROOT includes the / at the end of the path
For VCPK_INSTALLATION_ROOT (Mac) the / is missing, that's why we add it.

the quotes are just required in the second one to make the concatenation. Above lines we don't need to

set(VCPKG_PATH "$ENV{VCPKG_INSTALLATION_ROOT}/")
endif()

# Patch for new VCPKG cmocka returning relative path
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will we revert this once VCPKG issue is fixed (or maybe after the version pinning changes that @danieljurek was considering)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, this is a temporal fix.
It is setting the path to cmocka libraries manually and hardcoded. This fix would work always while the name of the static library for cmocka doesn't change.

I am not sure if there is a bug for VCPKG, it might be that it used to be one and they fixed it and we were just making it work by luck wrongly before.

but, at any way, we need follow up on this

Copy link
Member

@danewalton-msft danewalton-msft Jul 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note from my message thread on Teams. I notified the person which made the change that there was an issue here. The issue is open here and I'm working with her on the fix here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @danewalton .
That's good news.
I though cmocka could've done the change to work the same as when not using VCPKG.
when not working with VCPKG, cmake gets the path to the libs in a relative way, just like it is now now. That's why I thought that's how they wanted now.

So, as soon as VCPKG fix is merged, we can revert the changes here and it should work the same (and better without the hardcoded hot fix)

if(MSVC)
set(CMOCKA_STATIC_LIB "/lib/cmocka-static.lib")
else()
set(CMOCKA_STATIC_LIB "/lib/libcmocka-static.a")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is the name of the .a file accurate? Is it supposed to be libcmocka-static?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is .a on Posix (lin/mac) and .lib on windows.

the expectation is that cmoka will use whatever is loaded on ${CMOCKA_LIBRARIES}. That variable is provided by VCPKG when cmocka is installed. Cmocka provides the scripts to VCPKG to generate this variable.

In the past, this variable was generated like:
degug;/path/to/VCPKG/{vcpkg packages installed path}/libraries;optimized;/path/to/VCPKG/{vcpkg packages installed path}/libraries
but cmocka made a change and now it looks like:
debug;/libraries;optimized;/libraries

So the prefix path to the libraries was removed from both, debug and optimized libs.

I am just manually building the value we used to have before

else()
set(CMOCKA_STATIC_LIB "/lib/libcmocka-static.a")
endif()
set(CMOCKA_PREFIX "${VCPKG_PATH}installed/${VCPKG_TARGET_TRIPLET}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Does this need a directory separator?

Suggested change
set(CMOCKA_PREFIX "${VCPKG_PATH}installed/${VCPKG_TARGET_TRIPLET}")
set(CMOCKA_PREFIX "${VCPKG_PATH}/installed/${VCPKG_TARGET_TRIPLET}")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, VCPKG_PATH is expected to have the / at the end

set(CMOCKA_STATIC_LIB "/lib/libcmocka-static.a")
endif()
set(CMOCKA_PREFIX "${VCPKG_PATH}installed/${VCPKG_TARGET_TRIPLET}")
set(CMOCKA_LIB "debug;${CMOCKA_PREFIX}/debug${CMOCKA_STATIC_LIB};optimized;${CMOCKA_PREFIX}${CMOCKA_STATIC_LIB}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: How did you know this is what we need to set CMOCKA_LIB to? Will we always have debug?

I am trying to understand what this means.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no,
this is how a package tells VCPKG where to find libraries for debug and for optimized.
The string looks like degug;path;optimized;path

Then, depending on what cmake is building, it will pick debug or optimized.

Then one on optimized does not have the debug/

@vhvb1989 vhvb1989 merged commit 90c9007 into Azure:master Jul 1, 2020
danewalton-msft added a commit to danewalton-msft/azure-sdk-for-c that referenced this pull request Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants