question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[question] Creating a "test_package" that will work cross platform with multiple compilers/configurations

See original GitHub issue

I’m working on packaging and testing a library that I wrote and everything seems to work fine but when I wrote the test_package for the library I followed the example in the documentation and it was failing because the binary file was not being placed in a bin folder, but instead MSVC decided to put it in a Release folder.

Here is my working conanfile.py for the test_package of my library.

import os

from conans import ConanFile, CMake, tools

class TestPackage(ConanFile):
    settings = "os", "compiler", "build_type", "arch"
    generators = "cmake_paths"

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def test(self):
        if not tools.cross_building(self):

            # MSVC doesn't put the output in "bin", it is putting it in "Release" instead
            #os.chdir("bin")
            os.chdir("Release")

            self.run(".%test_package_exe" % os.sep)

The issue is that this is a multi-configuration project and I also want it to be cross platform compatible. If I try to create a package from a debug build the executable would be in a Debug folder instead and the test package would fail. Also if I tried to use gcc instead of MSVC the executable would be in the bin folder like the example in the documentation.

What is the proper way to make the test package work in all cases without having to modify the conanfile every time I change configurations or compilers?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
tjwronacommented, Sep 28, 2020

Okay thank you that answers all of my questions. I am personally okay with this library being dependent on CMake because that is the only way I plan on consuming it so I will proceed with “cmake_paths” but it is good to know what all of my options are and how this all works. With this information I might update it in the future to be more generic that way it can be consumed by other build systems.

It would be really cool if Conan could automatically extract that info from the CMake target somehow and use it to generate its own target but I’m not sure that is even possible.

1reaction
tjwronacommented, Sep 27, 2020

Thanks, using both generators and adding this to the test_package CMakeLists file worked!

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

The other things you mentioned are very interesting though so I’ll definitely have to look deeper into that and see if I can get it to work that way!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Design and unit-test cross-platform application - Stack Overflow
run GOOS=windows GOARCH=amd64 go build -o application.exe. It builds just fine and I don't have any troubles with it. Another problem come up ......
Read more >
Cross-platform LAN (Minecraft) - Microsoft Community
Yes, you can play cross platforms on a LAN connection. First, make sure every player that wants to join is connected to the...
Read more >
WHAT YOU NEED TO CROSS PLAY MINECRAFT ON THE ...
... try restarting your device. Your browser can 't play this video. ... WHAT YOU NEED TO CROSS PLAY MINECRAFT ON THE NINTENDO...
Read more >
Disney Dreamlight Valley Cross-Play And Cross-Save ...
You can take your unique village across platforms, ... Dreamlight Valley cross-save and cross-play capabilities are two big question marks.
Read more >
Klei on Twitter: "@VodenAurion @505_Games There is no ...
One last thing it say on my win 10 I can buy DS but it says xbox one will it still work? If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found