2

I'm trying to create a conan-package (hint: the names contain forward-slashes) as a postbuild operation with something like this:

    add_custom_command(
    TARGET ${PROJECT_NAME} POST_BUILD
    WORKING_DIRECTORY ${PROJECT_DIR}
    COMMAND conan export-pkg .. "gtest/1.10.0@shared/testing" -f -pr ${CONAN_PROFILE}
    COMMENT "Uploading conan package..."
    )

On Linux/Ubuntu/WSL this works fine.

conan export-pkg . 'gtest/1.10.0@shared/testing' -f -pr './platforms/platform_linux-x86-clang/conan_profile/linux-x86-clang'

On Windows the executed command looks like this:

conan export-pkg . 'gtest\1.10.0@shared\testing' -f -pr .\platforms\platform_win-x86-clang\conan_profile\win-x86-clang 

How do I keep cmake from replacing / with \? Is there a setting for this?

zeroflag
  • 21
  • 2

1 Answers1

3

You can use the file(TO_CMAKE_PATH "<path>" <variable>) command. It force the path to have a format with / separator.

In your case you have to put gtest/1.10.0@shared/testing in a variable with the command :

file(TO_CMAKE_PATH "gtest/1.10.0@shared/testing" GTEST_PATH)
file(TO_CMAKE_PATH ${CONAN_PROFILE} CONAN_PROFILE)

add_custom_command(
    TARGET ${PROJECT_NAME} POST_BUILD
    WORKING_DIRECTORY ${PROJECT_DIR}
    COMMAND conan export-pkg .. ${GTEST_PATH} -f -pr ${CONAN_PROFILE}
    COMMENT "Uploading conan package..."
)