Conan unable to execute UnitTest as a part of build process

Viewed 16

I am just trying my hand at Conan-IO+CMake, I am trying to execute UnitTests at build time and Conan/CMake is just not able to find the test executable. I have included my conanfile.py and CMakeLists.txt in the question itself.

from conans import ConanFile, CMake, tools
from conan.tools.cmake import CMakeToolchain,CMakeDeps
from conan.tools.layout import cmake_layout


class MylibConan(ConanFile):
    name = "mylib"
    version = "1.0.0"
    license = "<Put the package license here>"
    author = "<Put your name here> <And your email here>"
    url = "<Package recipe repository url here, for issues about the package>"
    description = "<Description of Mylib here>"
    topics = ("<Put some tag here>", "<here>", "<and here>")
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False],}
    default_options = {"boost:shared":False,"shared": False, "fPIC": True} # if shared is true, we would have this as a shared library
    
    generators="cmake","cmake_find_package","json","virtualenv"
    exports_sources = (
        "CMakeLists.txt"
    )
    no_copy_source = True
    #The below method would be triggered iff you unset the no_copy_source variable
    #def export_source(self):
    #    self.copy("*")
    @property
    def _cmake(self):
        cmake = CMake(self)
        return cmake
    def requirements(self):
        self.requires("gtest/1.12.1")
    def config_options(self):
        if self.settings.os == "Windows":
            del self.options.fPIC
    def generator(self): #Preprocessor
        tc = CMakeToolchain(self,generator='Ninja')
        tc.generate()
        CMakeDeps(self).generate() #creates findBoost.cmake
    def test(self):
        self.run("bin/runUnitTests")
    def build(self):
        cmake = CMake(self,generator='Ninja')
        cmake.configure(source_folder=self.source_folder)
        cmake.build()
        cmake.test(output_on_failure=True)
        # Explicit way:
        # self.run('cmake %s/hello %s'
        #          % (self.source_folder, cmake.command_line))
        # self.run("cmake --build . %s" % cmake.build_config)

    def package(self):
        self._cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["hello"]


The following is my CMakeLists.txt file located in the same folder. This is the only CMakeFile in the entire project. I have included only the relevant portions

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

find_package(GTest REQUIRED)


add_executable(runUnitTests UniteTest.cpp)
target_link_libraries(runUnitTests GTest::gtest)
add_test(runUnitTests runUnitTests)

I get the following error Message. Any ideas on how can I remedy this?

Test project <project_location>/build
    Start 1: runUnitTests
Could not find executable runUnitTests
Looked in the following places:
runUnitTests
runUnitTests.exe
Release/runUnitTests
Release/runUnitTests.exe
Debug/runUnitTests
Debug/runUnitTests.exe
MinSizeRel/runUnitTests
MinSizeRel/runUnitTests.exe
RelWithDebInfo/runUnitTests
RelWithDebInfo/runUnitTests.exe
Deployment/runUnitTests
Deployment/runUnitTests.exe
Development/runUnitTests
Development/runUnitTests.exe
Unable to find executable: runUnitTests
1/1 Test #1: runUnitTests .....................Not Run   0.00 sec
0 Answers
Related