conanfile.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. from conans import ConanFile, CMake, tools
  3. class CatchConan(ConanFile):
  4. name = "catch2"
  5. description = "A modern, C++-native, framework for unit-tests, TDD and BDD"
  6. topics = ("conan", "catch2", "unit-test", "tdd", "bdd")
  7. url = "https://github.com/catchorg/Catch2"
  8. homepage = url
  9. license = "BSL-1.0"
  10. exports = "LICENSE.txt"
  11. exports_sources = ("src/*", "CMakeLists.txt", "CMake/*", "extras/*")
  12. settings = "os", "compiler", "build_type", "arch"
  13. generators = "cmake"
  14. def _configure_cmake(self):
  15. cmake = CMake(self)
  16. cmake.definitions["BUILD_TESTING"] = "OFF"
  17. cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF"
  18. cmake.definitions["CATCH_INSTALL_EXTRAS"] = "ON"
  19. cmake.configure(build_folder="build")
  20. return cmake
  21. def build(self):
  22. # We need this workaround until the toolchains feature
  23. # to inject stuff like MD/MT
  24. line_to_replace = 'list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")'
  25. tools.replace_in_file("CMakeLists.txt", line_to_replace,
  26. '''{}
  27. include("{}/conanbuildinfo.cmake")
  28. conan_basic_setup()'''.format(line_to_replace, self.install_folder.replace("\\", "/")))
  29. cmake = self._configure_cmake()
  30. cmake.build()
  31. def package(self):
  32. self.copy(pattern="LICENSE.txt", dst="licenses")
  33. cmake = self._configure_cmake()
  34. cmake.install()
  35. def package_info(self):
  36. lib_suffix = "d" if self.settings.build_type == "Debug" else ""
  37. self.cpp_info.names["cmake_find_package"] = "Catch2"
  38. self.cpp_info.names["cmake_find_package_multi"] = "Catch2"
  39. # Catch2
  40. self.cpp_info.components["catch2base"].names["cmake_find_package"] = "Catch2"
  41. self.cpp_info.components["catch2base"].names["cmake_find_package_multi"] = "Catch2"
  42. self.cpp_info.components["catch2base"].names["pkg_config"] = "Catch2"
  43. self.cpp_info.components["catch2base"].libs = ["Catch2" + lib_suffix]
  44. self.cpp_info.components["catch2base"].builddirs.append("lib/cmake/Catch2")
  45. # Catch2WithMain
  46. self.cpp_info.components["catch2main"].names["cmake_find_package"] = "Catch2WithMain"
  47. self.cpp_info.components["catch2main"].names["cmake_find_package_multi"] = "Catch2WithMain"
  48. self.cpp_info.components["catch2main"].names["pkg_config"] = "Catch2WithMain"
  49. self.cpp_info.components["catch2main"].libs = ["Catch2Main" + lib_suffix]
  50. self.cpp_info.components["catch2main"].requires = ["catch2base"]