diff --git a/CMakeLists.txt b/CMakeLists.txt index fd25f69..d7dd7b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake) option(MYSQLPOOL_WITH_TESTS "Enable Tests" ON) -set(MYSQLPOOL_LOGGER "logfault" CACHE STRING "Log system to use. One of 'clog', 'logfault', 'boost' or 'none'") +set(MYSQLPOOL_LOGGER "logfault" CACHE STRING "Log system to use. One of 'clog', 'internal', 'logfault', 'boost' or 'none'") set(MYSQLPOOL_LOG_LEVEL_STR "info" CACHE STRING "Minimum log level to enable") set(MYSQLPOOL_DBUSER "MYSQLPOOL_DBUSER" CACHE STRING "Environment variable to get login user name name from") @@ -107,6 +107,8 @@ add_library(boost INTERFACE IMPORTED) set_property(TARGET boost PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR}) + + if (MYSQLPOOL_WITH_TESTS) enable_testing() find_package(GTest REQUIRED) @@ -115,7 +117,7 @@ if (MYSQLPOOL_WITH_TESTS) # Conan suggests to use 'gtest:gtest' which aslo don't work. if (NOT GTEST_LIBRARIES) message("GTest: GTEST_LIBRARIES unset. Setting it manually to gtest") - set(GTEST_LIBRARIES gtest) + set(GTEST_LIBRARIES GTest::gtest) endif() add_subdirectory(tests) endif() diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..5d9f0b4 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,65 @@ +from conan import ConanFile +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout +from conan.tools.build import check_max_cppstd, check_min_cppstd + +class mysqlpoolRecipe(ConanFile): + name = "mysqlpool" + version = "0.1.0" + + # Optional metadata + license = " BSL-1.0" + author = "Jarle Aase jgaa@jgaa.com" + url = "https://github.com/jgaa/mysqlpool-cpp" + description = "Lightweight async connection-pool library, built on top of boost.mysql." + topics = ("boost.mysql", "mysql", "mariadb") + + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + options = {"shared": [True, False], "fPIC": [True, False], "logger": ["clog", "internal", "boost", "none"], "log_level": ["trace", "debug", "info", "warn"]} + default_options = {"shared": False, "fPIC": True, "logger": "clog", "log_level": "info"} + + # Sources are located in the same place as this recipe, copy them to the recipe + exports_sources = "config.h.template", "CMakeLists.txt", "src/*", "include/*", "tests/*", "cmake/*" + + #def config_options(self): + + def layout(self): + cmake_layout(self) + + def generate(self): + tc = CMakeToolchain(self) + + tc.variables["MYSQLPOOL_LOGGER"] = self.options.logger + tc.variables["MYSQLPOOL_LOG_LEVEL_STR"] = self.options.log_level + + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + # if not self.conf.get("tools.build:skip_test", default=False): + # self.run(os.path.join(test_folder, "unit_tests")) + if not self.conf.get("tools.build:skip_test", default=False): + cmake.test() + + def package(self): + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.libs = ["mysqlpool"] + + def validate(self): + check_min_cppstd(self, "20") + + def requirements(self): + self.requires("zlib/[~1.3]") + self.requires("openssl/[~3]") + self.requires("boost/[>=1.83.0]") + self.test_requires("gtest/[>=1.14]") + + # def test(self): + # if can_run(self): + # cmd = os.path.join(self.cpp.build.bindir, "example") + # self.run(cmd, env="conanrun") diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index c086fbf..0000000 --- a/conanfile.txt +++ /dev/null @@ -1,12 +0,0 @@ -[requires] -zlib/1.3.1 -openssl/3.2.1 -boost/1.84.0 -gtest/1.14.0 - -[generators] -CMakeDeps -CMakeToolchain - -[layout] -cmake_layout diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a231570..6a38474 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,12 +27,15 @@ if (MYSQLPOOL_LOGDEP) endif() target_link_libraries(${PROJECT_NAME} - PRIVATE - $ - $ - $ -# $ - ) + ${Boost_LIBRARIES} + #${ZLIB_LIBRARIES} + #${OPENSSL_LIBRARIES} + OpenSSL::SSL + OpenSSL::Crypto + ZLIB::ZLIB + stdc++fs + ${CMAKE_THREAD_LIBS_INIT} +) message(STATUS "Components to pack (${PROJECT_NAME}): ${CPACK_COMPONENTS_ALL}") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2176c77..bf4cb56 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,11 +24,11 @@ target_include_directories(unit_tests target_link_libraries(unit_tests ${GTEST_LIBRARIES} mysqlpool - ${Boost_LIBRARIES} - ${ZLIB_LIBRARIES} - ${OPENSSL_LIBRARIES} - stdc++fs - ${CMAKE_THREAD_LIBS_INIT} + # ${Boost_LIBRARIES} + # ${ZLIB_LIBRARIES} + # ${OPENSSL_LIBRARIES} + # stdc++fs + # ${CMAKE_THREAD_LIBS_INIT} ) add_test(NAME unit_tests COMMAND unit_tests) @@ -61,11 +61,11 @@ target_include_directories(functional_tests target_link_libraries(functional_tests ${GTEST_LIBRARIES} mysqlpool - ${Boost_LIBRARIES} - ${ZLIB_LIBRARIES} - ${OPENSSL_LIBRARIES} - stdc++fs - ${CMAKE_THREAD_LIBS_INIT} + # ${Boost_LIBRARIES} + # ${ZLIB_LIBRARIES} + # ${OPENSSL_LIBRARIES} + # stdc++fs + # ${CMAKE_THREAD_LIBS_INIT} ) add_test(NAME functional_tests COMMAND functional_tests) diff --git a/tests/unit_tests.cpp b/tests/unit_tests.cpp index 914e131..31e9022 100644 --- a/tests/unit_tests.cpp +++ b/tests/unit_tests.cpp @@ -66,8 +66,6 @@ TEST(Logfault, Hello) { MYSQLPOOL_LOG_INFO_("Test log"); } - std::cerr << "Out: " << output << "\n"; - regex pattern{R"(.* INFO .* Test log.*)"}; EXPECT_TRUE(regex_search(output, pattern)); } @@ -79,10 +77,10 @@ TEST(Clog, Hello) { string output; { ClogRedirector redir{output}; - MYSQLPOOL_LOG_DEBUG_("Test log"); + MYSQLPOOL_LOG_INFO_("Test log"); } - regex pattern{R"(DEBUG Test log.*)"}; + regex pattern{R"(.*Test log.*)"}; EXPECT_TRUE(regex_search(output, pattern)); } #endif @@ -93,10 +91,10 @@ TEST(InternalLog, Hello) { string output; { ClogRedirector redir{output}; - MYSQLPOOL_LOG_DEBUG_("Test log"); + MYSQLPOOL_LOG_INFO_("Test log"); } - regex pattern{R"(DEBUG \d* Test log.*)"}; + regex pattern{R"(INFO \d* Test log.*)"}; EXPECT_TRUE(regex_search(output, pattern)); } #endif @@ -107,11 +105,11 @@ TEST(BoostLog, Hello) { string output; { ClogRedirector redir{output}; - MYSQLPOOL_LOG_DEBUG_("Test log"); + MYSQLPOOL_LOG_INFO_("Test log"); boost::log::core::get()->flush(); } - regex pattern{R"(.*\[debug\]\: Test log.*)"}; + regex pattern{R"(.*\[info\]\: Test log.*)"}; EXPECT_TRUE(regex_search(output, pattern)); } #endif