[question] Creating a "test_package" that will work cross platform with multiple compilers/configurations
See original GitHub issueI’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?
- I’ve read the CONTRIBUTING guide.
Issue Analytics
- State:
- Created 3 years ago
- Comments:17 (7 by maintainers)
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.
Thanks, using both generators and adding this to the
test_package
CMakeLists file worked!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!