From 7254a7c5259aabf9893c8f7289afa2cc8d7933bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 19 Jun 2018 14:23:48 +0300 Subject: [PATCH] Make maxutils a standalone library The only way to cleanly separate the maxutils library from the MaxScale CMake project is to make it a standalone CMake project. With the help of ExternalProject, it should be relatively easy to use. --- CMakeLists.txt | 6 ++++-- cmake/BuildMaxUtils.cmake | 9 +++++++++ maxutils/CMakeLists.txt | 3 +++ maxutils/maxbase/CMakeLists.txt | 5 ++--- maxutils/maxbase/include/maxbase/CMakeLists.txt | 10 ++++++++++ maxutils/maxbase/src/CMakeLists.txt | 3 +++ server/core/CMakeLists.txt | 1 + server/modules/filter/throttlefilter/CMakeLists.txt | 2 +- 8 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 cmake/BuildMaxUtils.cmake create mode 100644 maxutils/maxbase/include/maxbase/CMakeLists.txt create mode 100644 maxutils/maxbase/src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index fd3ea78c4..4669b0211 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,10 @@ include_directories(BEFORE ${MARIADB_CONNECTOR_INCLUDE_DIR}) include(cmake/BuildJansson.cmake) include(cmake/BuildMicroHttpd.cmake) +# Build the MaxUtils libraries +include(cmake/BuildMaxUtils.cmake) +include_directories(${MAXUTILS_INCLUDE_DIR}) + include_directories(${JANSSON_INCLUDE_DIR}) if(NOT OPENSSL_FOUND) @@ -166,7 +170,6 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS} -DSS_DEBUG -D set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wno-deprecated-declarations -Wno-uninitialized -std=c++11") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -ggdb -Wno-deprecated-declarations -Wno-uninitialized -std=c++11") -include_directories(maxutils/maxbase/include) include_directories(include) include_directories(server/inih) include_directories(server/modules/include) @@ -178,7 +181,6 @@ if (BUILD_CDC) add_subdirectory(avro) endif() -add_subdirectory(maxutils) add_subdirectory(plugins) add_subdirectory(query_classifier) add_subdirectory(server) diff --git a/cmake/BuildMaxUtils.cmake b/cmake/BuildMaxUtils.cmake new file mode 100644 index 000000000..a6f13a452 --- /dev/null +++ b/cmake/BuildMaxUtils.cmake @@ -0,0 +1,9 @@ +# Build the maxutils library + +ExternalProject_Add(maxutils + SOURCE_DIR ${CMAKE_SOURCE_DIR}/maxutils + BINARY_DIR ${CMAKE_BINARY_DIR}/maxutils + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/maxutils/install) + +set(MAXUTILS_INCLUDE_DIR ${CMAKE_BINARY_DIR}/maxutils/install/include CACHE INTERNAL "") +set(MAXUTILS_LIBRARIES ${CMAKE_BINARY_DIR}/maxutils/install/lib/libmaxbase.a CACHE INTERNAL "") diff --git a/maxutils/CMakeLists.txt b/maxutils/CMakeLists.txt index 911b44033..8bebbee18 100644 --- a/maxutils/CMakeLists.txt +++ b/maxutils/CMakeLists.txt @@ -1 +1,4 @@ +project(maxutils) +cmake_minimum_required(VERSION 2.8) +set(CMAKE_CXX_FLAGS "-fPIC -std=c++11 -ggdb -Wall -Werror -Wno-unused-function") add_subdirectory(maxbase) diff --git a/maxutils/maxbase/CMakeLists.txt b/maxutils/maxbase/CMakeLists.txt index d8c8f1485..22461cd58 100644 --- a/maxutils/maxbase/CMakeLists.txt +++ b/maxutils/maxbase/CMakeLists.txt @@ -1,4 +1,3 @@ include_directories(include) -add_library(maxbase SHARED src/eventcount.cc src/stopwatch.cc) -set_target_properties(maxbase PROPERTIES VERSION "1.0.0") -install_module(maxbase core) +add_subdirectory(include/maxbase) +add_subdirectory(src) diff --git a/maxutils/maxbase/include/maxbase/CMakeLists.txt b/maxutils/maxbase/include/maxbase/CMakeLists.txt new file mode 100644 index 000000000..8aca3ce7a --- /dev/null +++ b/maxutils/maxbase/include/maxbase/CMakeLists.txt @@ -0,0 +1,10 @@ +set(TYPES "*.h" "*.hh") +foreach(type ${TYPES}) + file(GLOB HEADERS ${type}) + foreach(var ${HEADERS}) + get_filename_component(header ${var} NAME) + install(FILES ${header} DESTINATION include/maxbase) + endforeach() +endforeach() + + diff --git a/maxutils/maxbase/src/CMakeLists.txt b/maxutils/maxbase/src/CMakeLists.txt new file mode 100644 index 000000000..18dc1cbca --- /dev/null +++ b/maxutils/maxbase/src/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(maxbase STATIC eventcount.cc stopwatch.cc) +set_target_properties(maxbase PROPERTIES VERSION "1.0.0" LINK_FLAGS -Wl,-z,defs) +install(TARGETS maxbase DESTINATION lib) diff --git a/server/core/CMakeLists.txt b/server/core/CMakeLists.txt index cdfa8c06d..8f73757c7 100644 --- a/server/core/CMakeLists.txt +++ b/server/core/CMakeLists.txt @@ -66,6 +66,7 @@ endif() target_link_libraries(maxscale-common ${MARIADB_CONNECTOR_LIBRARIES} + ${MAXUTILS_LIBRARIES} ${LZMA_LINK_FLAGS} ${PCRE2_LIBRARIES} ${JANSSON_LIBRARIES} diff --git a/server/modules/filter/throttlefilter/CMakeLists.txt b/server/modules/filter/throttlefilter/CMakeLists.txt index 84461e917..70cd5870e 100644 --- a/server/modules/filter/throttlefilter/CMakeLists.txt +++ b/server/modules/filter/throttlefilter/CMakeLists.txt @@ -1,4 +1,4 @@ add_library(throttlefilter SHARED throttlefilter.cc throttlesession.cc) -target_link_libraries(throttlefilter maxbase maxscale-common mysqlcommon) +target_link_libraries(throttlefilter maxscale-common mysqlcommon) set_target_properties(throttlefilter PROPERTIES VERSION "1.0.0") install_module(throttlefilter core)