I'm trying to create a header only package with conan which is based on CMake and CTest. It's as empty as possible and just contains two tests with empty main()
functions.
While conan create . conantest/stable
works fine on linux it stop with the error
conantest/0.1@conantest/stable: ERROR: Package '...' build failed
conantest/0.1@conantest/stable: WARN: Build folder C:\Users\...\.conan\data\conantest\0.1\conantest\stable\build\...
ERROR: conantest/0.1@conantest/stable: Error in build() method, line 17
cmake.test()
ConanException: Error 1 while executing cmake --build "C:\Users\...\.conan\data\conantest\0.1\conantest\stable\build\..." --target test
on windows.
The problem is that on windows with this example cmake.test()
doesn't invoke the multi-config RUN_TESTS
target as described here but test
.
From the docs i got the impression that it should distinguish automatically but i also don't know if that's correct or what's missing to enable this automatism.
It is possible to hint at the build type by providing settings:
settings = "os", "compiler", "build_type", "arch"
When Conan generates a compiled binary for a package with a given combination of the settings above, it generates a unique ID for that binary by hashing the current values of these settings.
but as described here usually those are set to None
explicitely for header only libraries.
As i understand it, the tests are only built and executed during packaging but their binary form is not part of the package. Is there a way to define the recipe for only one unique ID while still being able to build and run the tests during packaging on any platform?
The test project is available on git.
These are its contents:
CMakeLists.txt
cmake_minimum_required(VERSION 3.8.0)
project(conantest VERSION 0.1 LANGUAGES CXX)
include(CTest)
enable_testing()
add_executable(conantest1 conantest1.cpp)
add_test(conantest1 conantest1)
add_executable(conantest2 conantest2.cpp)
add_test(conantest2 conantest2)
conanfile.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from conans import ConanFile, CMake
class ConantestConan(ConanFile):
name = "conantest"
version = "0.1"
generators = "cmake"
exports_sources = "*"
no_copy_source = True
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
cmake.test()
def package(self):
self.copy("*.hpp")
def package_id(self):
self.info.header_only()
conantest1.cpp and conantest2.cpp
#include <cstdlib>
int main() {
return EXIT_SUCCESS;
}