diff --git a/.appveyor.yml b/.appveyor.yml index bdac45f..6a0ab65 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -5,4 +5,6 @@ environment: - CMAKE_GENERATOR: "Visual Studio 15 2017" build_script: - cmd: git submodule update --init --recursive - - cmd: .\.ci\common\script\appveyor.bat "%CMAKE_GENERATOR%" + - cmd: cmake -G "%CMAKE_GENERATOR%" + - cmd: cmake --build . -- /nologo /property:Configuration=Release + - cmd: ctest --output-on-failure -C Release -a diff --git a/.ci/common b/.ci/common index 30a13d9..11b310c 160000 --- a/.ci/common +++ b/.ci/common @@ -1 +1 @@ -Subproject commit 30a13d983baa92775306f99708762652e51dc500 +Subproject commit 11b310c115630cc1d1d9346b9e3900a47bc91725 diff --git a/CMakeLists.txt b/CMakeLists.txt index 9518e26..d96e517 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,8 +28,6 @@ if (("${MKMMDB_HAVE_MAXMINDDB_H}" STREQUAL "") OR endif() list(APPEND MKMMDB_LIBS "${LIBMAXMINDDB_LIBRARY}") -find_package(CURL REQUIRED) - # Compiler flags # -------------- @@ -39,11 +37,10 @@ MkSetCompilerFlags() # ------------------ set(MKMMDB_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} - ${CURL_INCLUDE_DIRS} ${CMAKE_REQUIRED_INCLUDES}) + ${CMAKE_REQUIRED_INCLUDES}) + +include_directories(${MKMMDB_INCLUDES}) -add_library(mkmmdb mkmmdb.cpp) -add_executable(mkmmdb-client mkmmdb-client.cpp) -target_include_directories(mkmmdb-client PUBLIC ${MKMMDB_INCLUDES}) if("${WIN32}" OR "${MINGW}") list(APPEND MKMMDB_LIBS "ws2_32") if ("${MINGW}") @@ -51,7 +48,11 @@ if("${WIN32}" OR "${MINGW}") endif() endif() list(APPEND MKMMDB_LIBS Threads::Threads) -target_link_libraries(mkmmdb-client "${MKMMDB_LIBS}" mkmmdb) +link_libraries("${MKMMDB_LIBS}") + +add_library(mkmmdb mkmmdb.cpp) +add_executable(mkmmdb-client mkmmdb-client.cpp) +target_link_libraries(mkmmdb-client mkmmdb) # Testing # ------- diff --git a/cmake/Modules b/cmake/Modules index 7041216..503b8ba 160000 --- a/cmake/Modules +++ b/cmake/Modules @@ -1 +1 @@ -Subproject commit 70412163c491e575bb7d33b2b729d7cb15cd016a +Subproject commit 503b8ba6ca1f118e71badfd66322701ae40b7f56 diff --git a/mkmmdb-client.cpp b/mkmmdb-client.cpp index 8679bdd..b3a8955 100644 --- a/mkmmdb-client.cpp +++ b/mkmmdb-client.cpp @@ -12,7 +12,7 @@ int main(int argc, char **argv) { } std::string ip = argv[1]; { - mkmmdb_uptr db{mkmmdb_open("country.mmdb")}; + mkmmdb_uptr db{mkmmdb_open_nonnull("country.mmdb")}; if (!mkmmdb_good(db.get())) { std::clog << "Cannot open country.mmdb" << std::endl; // FALLTHROUGH @@ -24,7 +24,7 @@ int main(int argc, char **argv) { std::clog << "CC: " << s << std::endl; } { - mkmmdb_uptr db{mkmmdb_open("asn.mmdb")}; + mkmmdb_uptr db{mkmmdb_open_nonnull("asn.mmdb")}; if (!mkmmdb_good(db.get())) { std::clog << "Cannot open asn.mmdb" << std::endl; // FALLTHROUGH diff --git a/mkmmdb.h b/mkmmdb.h index b9f0262..1fa638c 100644 --- a/mkmmdb.h +++ b/mkmmdb.h @@ -14,11 +14,11 @@ extern "C" { /// mkmmdb_t is a MMDB database. typedef struct mkmmdb mkmmdb_t; -/// mkmmdb_open opens a database pointing to @p path. It always returns a -/// valid pointer. Call mkmmdb_good to understand whether the database was -/// successfully openned or not. This function will call std::abort when +/// mkmmdb_open_nonnull opens a database pointing to @p path. It always returns +/// a valid pointer. Call mkmmdb_good to understand whether the database was +/// successfully openned or not. This function will call abort when /// the @p path argument is a null pointer. -mkmmdb_t *mkmmdb_open(const char *path); +mkmmdb_t *mkmmdb_open_nonnull(const char *path); /// mkmmdb_good returns true if the database has been successfully open /// and false otherwise. This function aborts if @p mmdb is null. @@ -28,24 +28,24 @@ int64_t mkmmdb_good(mkmmdb_t *mmdb); /// @p mmdb database, or the empty string on failure. The returned string /// will be valid until @p mmdb is valid _and_ you don't call other /// functions using the same @p mmdb instance. This function calls -/// std::abort if passed null parameters. +/// abort if passed null parameters. const char *mkmmdb_lookup_cc(mkmmdb_t *mmdb, const char *ip); /// mkmmdb_lookup_asn is like mkmmdb_lookup_cc but returns /// the ASN on success and zero on failure. Also this function -/// calls std::abort if passed null parameters. +/// calls abort if passed null parameters. int64_t mkmmdb_lookup_asn(mkmmdb_t *mmdb, const char *ip); /// mkmmdb_lookup_org is like mkmmdb_lookup_cc but returns /// the organization bound to @p ip on success, the empty string on /// failure. The returned string will be valid until @p mmdb is /// valid _and_ you don't call other lookup APIs using the -/// same @p mmdb instance. This function calls std::abort if +/// same @p mmdb instance. This function calls abort if /// passed a null @p mmdb or a null @p ip. const char *mkmmdb_lookup_org(mkmmdb_t *mmdb, const char *ip); /// mkmmdb_get_last_lookup_logs returns the logs of the last lookup -/// or an empty string. Calls std::abort if @p mmdb is null. +/// or an empty string. Calls abort if @p mmdb is null. const char *mkmmdb_get_last_lookup_logs(mkmmdb_t *mmdb); /// mkmmdb_close closes @p mmdb. Note that @p mmdb MAY be null. @@ -109,11 +109,11 @@ struct mkmmdb { #endif #ifndef MKMMDB_ABORT -// MKMMDB_ABORT allows to mock std::abort -#define MKMMDB_ABORT std::abort +// MKMMDB_ABORT allows to mock abort +#define MKMMDB_ABORT abort #endif -mkmmdb_t *mkmmdb_open(const char *path) { +mkmmdb_t *mkmmdb_open_nonnull(const char *path) { if (path == nullptr) { MKMMDB_ABORT(); }