diff --git a/CMakeLists.txt b/CMakeLists.txt index b50f0f3..4da11bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,9 +12,12 @@ set(OATPP_THIS_MODULE_DIRECTORIES oatpp-swagger) ## list of directories to insta ################################################################################################### -project(${OATPP_THIS_MODULE_NAME}) - -set(CMAKE_CXX_STANDARD 11) +project(${OATPP_THIS_MODULE_NAME} + VERSION ${OATPP_THIS_MODULE_VERSION} + LANGUAGES CXX + HOMEPAGE_URL "https://github.com/oatpp/oatpp-swagger" + DESCRIPTION "Swagger UI for oatpp services" +) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) option(OATPP_DIR_SRC "Path to oatpp module directory (sources)") @@ -22,58 +25,81 @@ option(OATPP_DIR_LIB "Path to directory with liboatpp (directory containing ex: option(OATPP_BUILD_TESTS "Build tests for this module" ON) option(OATPP_INSTALL "Install module binaries" ON) -message("OATPP_MODULE='${OATPP_THIS_MODULE_NAME}'") +set(OATPP_MODULES_LOCATION "INSTALLED" CACHE STRING "Location where to find oatpp modules. can be [INSTALLED|EXTERNAL|CUSTOM]") -##################################################################################################### -## if OATPP_BUILD_TESTS=ON and both options OATPP_DIR_SRC and OATPP_DIR_LIB are empty -## oatpp lib will be git-cloned. -## Otherwise options OATPP_DIR_SRC and OATPP_DIR_LIB are expected to point to valid directories -##################################################################################################### +################################################################################################### +## get oatpp main module in specified location -if(OATPP_BUILD_TESTS AND (NOT OATPP_DIR_SRC) AND (NOT OATPP_DIR_LIB)) +set(OATPP_MODULES_LOCATION_INSTALLED INSTALLED) +set(OATPP_MODULES_LOCATION_EXTERNAL EXTERNAL) +set(OATPP_MODULES_LOCATION_CUSTOM CUSTOM) + +if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_INSTALLED) + + message("Finding oatpp in location=INSTALLED") + + find_package(oatpp ${OATPP_THIS_MODULE_VERSION} REQUIRED) + + get_target_property(OATPP_INCLUDE oatpp::oatpp INTERFACE_INCLUDE_DIRECTORIES) + message("OATPP_INCLUDE=${OATPP_INCLUDE}") + + get_target_property(OATPP_TEST_INCLUDE oatpp::oatpp-test INTERFACE_INCLUDE_DIRECTORIES) + message("OATPP_TEST_INCLUDE=${OATPP_TEST_INCLUDE}") + +elseif(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL) + + message("Finding oatpp in location=EXTERNAL") include(ExternalProject) set(MODULE_WAIT_DEPS ON) - set(LIB_oatpp "lib_oatpp") - ExternalProject_Add(${LIB_oatpp} + set(LIB_OATPP_EXTERNAL "lib_oatpp_external") + ExternalProject_Add(${LIB_OATPP_EXTERNAL} GIT_REPOSITORY "https://github.com/oatpp/oatpp.git" GIT_TAG origin/new_module_structure - CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} -DOATPP_INSTALL=OFF -DOATPP_BUILD_TESTS=OFF - INSTALL_COMMAND cmake -E echo "SKIP INSTALL '${LIB_oatpp}'" + CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DOATPP_INSTALL=OFF -DOATPP_BUILD_TESTS=OFF + INSTALL_COMMAND cmake -E echo "SKIP INSTALL '${LIB_OATPP_EXTERNAL}'" ) - ExternalProject_Get_Property(${LIB_oatpp} BINARY_DIR) - set(OATPP_DIR_LIB ${BINARY_DIR}) + ExternalProject_Get_Property(${LIB_OATPP_EXTERNAL} BINARY_DIR) + set(OATPP_DIR_LIB ${BINARY_DIR}/src) - ExternalProject_Get_Property(${LIB_oatpp} SOURCE_DIR) - set(OATPP_DIR_SRC ${SOURCE_DIR}) + ExternalProject_Get_Property(${LIB_OATPP_EXTERNAL} SOURCE_DIR) + set(OATPP_DIR_SRC ${SOURCE_DIR}/src) + + message("OATPP_DIR_SRC --> '${OATPP_DIR_SRC}'") + message("OATPP_DIR_LIB --> '${OATPP_DIR_LIB}'") + +elseif(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_CUSTOM) + + message("Finding oatpp in location=CUSTOM") message("OATPP_DIR_SRC --> '${OATPP_DIR_SRC}'") message("OATPP_DIR_LIB --> '${OATPP_DIR_LIB}'") else() - - if(OATPP_DIR_SRC) - message("OATPP_DIR_SRC='${OATPP_DIR_SRC}'") - else() - message(FATAL_ERROR "'OATPP_DIR_SRC' parameter is required. It should point to main oatpp module directory.") - endif() - - if(BUILD_SHARED_LIBS) - if(OATPP_DIR_LIB) - message("OATPP_DIR_LIB='${OATPP_DIR_LIB}'") - else() - message(FATAL_ERROR "'OATPP_DIR_LIB' parameter is required. It should point to directory with liboatpp (directory containing ex: liboatpp.so or liboatpp.dynlib).") - endif() - endif() - + message("FATAL_ERROR Unknown location to find oatpp '${OATPP_MODULES_LOCATION}'") endif() +################################################################################################### +## get dependencies + +message("\n############################################################################") +message("## ${OATPP_THIS_MODULE_NAME} module. Resolving dependencies...\n") + +## TODO find dependecies here (if some) + +message("\n############################################################################\n") + +################################################################################################### +## define targets + +include(cmake/module-utils.cmake) + add_subdirectory("src") if(OATPP_BUILD_TESTS) enable_testing() add_subdirectory("test") -endif() \ No newline at end of file +endif() diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..3e2e16f --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,46 @@ +# Starter pipeline +# Start with a minimal pipeline that you can customize to build and deploy your code. +# Add steps that build, run tests, deploy, and more: +# https://aka.ms/yaml + +jobs: + - job: ubuntu_16_04 + displayName: 'Build - Ubuntu 16.04' + continueOnError: false + pool: + vmImage: 'Ubuntu 16.04' + workspace: + clean: all + steps: + - script: | + mkdir build + - task: CMake@1 + - script: | + cmake -DOATPP_MODULES_LOCATION=EXTERNAL .. + make + displayName: 'CMake' + workingDirectory: build + - script: | + make test ARGS="-V" + displayName: 'Test' + workingDirectory: build + - job: macOS + displayName: 'Build - macOS-10.13' + continueOnError: false + pool: + vmImage: 'macOS-10.13' + workspace: + clean: all + steps: + - script: | + mkdir build + - task: CMake@1 + - script: | + cmake -DOATPP_MODULES_LOCATION=EXTERNAL .. + make + displayName: 'CMake' + workingDirectory: build + - script: | + make test ARGS="-V" + displayName: 'Test' + workingDirectory: build \ No newline at end of file diff --git a/cmake/module-config.cmake.in b/cmake/module-config.cmake.in new file mode 100644 index 0000000..b7215f3 --- /dev/null +++ b/cmake/module-config.cmake.in @@ -0,0 +1,9 @@ +@PACKAGE_INIT@ + +if(NOT TARGET oatpp::oatpp) + include("${CMAKE_CURRENT_LIST_DIR}/@OATPP_MODULE_NAME@Targets.cmake") +endif() + +set_and_check(@OATPP_MODULE_NAME@_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/oatpp-@OATPP_MODULE_VERSION@/@OATPP_MODULE_NAME@/") +set_and_check(@OATPP_MODULE_NAME@_LIBRARIES_DIRS "${PACKAGE_PREFIX_DIR}/lib/@OATPP_MODULE_NAME@-@OATPP_MODULE_VERSION@/") +set(@OATPP_MODULE_NAME@_LIBRARIES @OATPP_MODULE_LIBRARIES@) diff --git a/src/oatpp-module-install.cmake b/cmake/module-install.cmake similarity index 59% rename from src/oatpp-module-install.cmake rename to cmake/module-install.cmake index 1e2e344..09b28ff 100644 --- a/src/oatpp-module-install.cmake +++ b/cmake/module-install.cmake @@ -14,7 +14,7 @@ ## | |- Config.cmake ## | - ConfigVersion.cmake ## | -## |- oatpp-/ +## - oatpp-/ ## | ## |- lib1.a ## |- lib2.a @@ -34,7 +34,7 @@ message("OATPP_THIS_MODULE_DIRECTORIES=${OATPP_THIS_MODULE_DIRECTORIES}") message("\n############################################################################\n") ####################################################################################### -## Set cache variables to configure package.cmake.in template +## Set cache variables to configure module-config.cmake.in template ## via call to configure_package_config_file set(OATPP_MODULE_NAME ${OATPP_THIS_MODULE_NAME} CACHE STRING "oatpp module name") @@ -44,26 +44,35 @@ set(OATPP_MODULE_LIBRARIES CACHE INTERNAL "oatpp module libraries" ) +####################################################################################### +## calc directories to install (relative to this script) +## dirs should be in ( relative ../src/) + +foreach(CURR_DIR ${OATPP_THIS_MODULE_DIRECTORIES}) + list(APPEND OATPP_DIRS_TO_INSTALL ${CMAKE_CURRENT_LIST_DIR}/../src/${CURR_DIR}) +endforeach() + ####################################################################################### include(GNUInstallDirs) install(TARGETS ${OATPP_THIS_MODULE_TARGETS} EXPORT "${OATPP_MODULE_NAME}Targets" - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}/oatpp-${OATPP_MODULE_VERSION} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/oatpp-${OATPP_MODULE_VERSION} - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}/oatpp-${OATPP_MODULE_VERSION} + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}/oatpp-${OATPP_MODULE_VERSION}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}/oatpp-${OATPP_MODULE_VERSION}" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}/oatpp-${OATPP_MODULE_VERSION}" + INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/oatpp-${OATPP_MODULE_VERSION}/${OATPP_MODULE_NAME}" ) -install(DIRECTORY ${OATPP_THIS_MODULE_DIRECTORIES} - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/oatpp-${OATPP_MODULE_VERSION}/${OATPP_MODULE_NAME} +install(DIRECTORY ${OATPP_DIRS_TO_INSTALL} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/oatpp-${OATPP_MODULE_VERSION}/${OATPP_MODULE_NAME}" FILES_MATCHING PATTERN "*.hpp" ) install(EXPORT "${OATPP_MODULE_NAME}Targets" FILE "${OATPP_MODULE_NAME}Targets.cmake" NAMESPACE oatpp:: - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION} + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION}" ) include(CMakePackageConfigHelpers) @@ -73,15 +82,24 @@ write_basic_package_version_file("${OATPP_MODULE_NAME}ConfigVersion.cmake" COMPATIBILITY ExactVersion ## Use exact version matching. ) -## Take package.cmake.in file in this direcory as a template +## Take module-config.cmake.in file in this direcory as a template -configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/package.cmake.in - "${OATPP_MODULE_NAME}Config.cmake" - INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION}" - PATH_VARS OATPP_MODULE_NAME OATPP_MODULE_VERSION OATPP_MODULE_LIBRARIES +configure_package_config_file( + "${CMAKE_CURRENT_LIST_DIR}/module-config.cmake.in" + "${OATPP_MODULE_NAME}Config.cmake" + INSTALL_DESTINATION + "${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION}" + PATH_VARS + OATPP_MODULE_NAME + OATPP_MODULE_VERSION + OATPP_MODULE_LIBRARIES NO_CHECK_REQUIRED_COMPONENTS_MACRO ) -install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${OATPP_MODULE_NAME}Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/${OATPP_MODULE_NAME}ConfigVersion.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION}" +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/${OATPP_MODULE_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${OATPP_MODULE_NAME}ConfigVersion.cmake" + DESTINATION + "${CMAKE_INSTALL_LIBDIR}/cmake/${OATPP_MODULE_NAME}-${OATPP_MODULE_VERSION}" ) \ No newline at end of file diff --git a/cmake/module-utils.cmake b/cmake/module-utils.cmake new file mode 100644 index 0000000..23f6ee7 --- /dev/null +++ b/cmake/module-utils.cmake @@ -0,0 +1,25 @@ +macro(target_link_oatpp target) + + if(TARGET oatpp::oatpp) ## OATPP_MODULES_LOCATION == INSTALLED + + message("target_link_oatpp(${target}) to installed oatpp lib") + + target_link_libraries(${target} + PRIVATE oatpp::oatpp + PRIVATE oatpp::oatpp-test + ) + + else() + + message("target_link_oatpp(${target}) to found in provided path oatpp lib") + + target_include_directories(${target} PUBLIC $) + target_link_directories(${target} PRIVATE ${OATPP_DIR_LIB}) + target_link_libraries(${target} + PRIVATE oatpp + PRIVATE oatpp-test + ) + + endif() + +endmacro() diff --git a/lgtm.yml b/lgtm.yml new file mode 100644 index 0000000..5c2d8e2 --- /dev/null +++ b/lgtm.yml @@ -0,0 +1,15 @@ +path_classifiers: + generated: + - exclude: "src/*" # don't tag oatpp sources as generated + library: + - exclude: "src/*" # don't tag oatpp sources as library + template: + - exclude: "src/*" # don't tag oatpp sources as template + test: + - exclude: "src/*" # don't tag oatpp sources as test + - test # tag test folder only as test + docs: + - README.md + - LICENSE.txt +extraction: + cpp: \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 272d258..54f0eca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,28 +12,27 @@ add_library(${OATPP_THIS_MODULE_NAME} oatpp-swagger/oas3/Model.hpp ) -if(MODULE_WAIT_DEPS) - add_dependencies(${OATPP_THIS_MODULE_NAME} ${LIB_oatpp}) +set_target_properties(${OATPP_THIS_MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_EXTENSIONS OFF + CXX_STANDARD_REQUIRED ON +) + +if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL) + add_dependencies(${OATPP_THIS_MODULE_NAME} ${LIB_OATPP_EXTERNAL}) endif() +target_link_oatpp(${OATPP_THIS_MODULE_NAME}) + target_include_directories(${OATPP_THIS_MODULE_NAME} - PUBLIC $ PUBLIC $ - PUBLIC $ ) -target_link_directories(${OATPP_THIS_MODULE_NAME} - PRIVATE ${OATPP_DIR_LIB}/src -) - -target_link_libraries(${OATPP_THIS_MODULE_NAME} - PRIVATE oatpp - PRIVATE oatpp-test -) +## TODO link dependencies here (if some) ####################################################################################################### -## INSTALL TARGETS +## install targets if(OATPP_INSTALL) - include("oatpp-module-install.cmake") -endif() \ No newline at end of file + include("../cmake/module-install.cmake") +endif() diff --git a/src/package.cmake.in b/src/package.cmake.in deleted file mode 100644 index a84fc50..0000000 --- a/src/package.cmake.in +++ /dev/null @@ -1,10 +0,0 @@ -@PACKAGE_INIT@ - -set_and_check(@OATPP_MODULE_NAME@_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include/oatpp-@OATPP_MODULE_VERSION@/@OATPP_MODULE_NAME@/") -set_and_check(@OATPP_MODULE_NAME@_LIBRARIES_DIR "${PACKAGE_PREFIX_DIR}/lib/oatpp-@OATPP_MODULE_VERSION@/") - -foreach(CURR_LIB @OATPP_MODULE_LIBRARIES@) - unset(@OATPP_MODULE_NAME@_FOUND_LIB_${CURR_LIB} CACHE) - find_library(@OATPP_MODULE_NAME@_FOUND_LIB_${CURR_LIB} ${CURR_LIB} PATHS ${@OATPP_MODULE_NAME@_LIBRARIES_DIR}) - list(APPEND @OATPP_MODULE_NAME@_LIBRARIES ${@OATPP_MODULE_NAME@_FOUND_LIB_${CURR_LIB}}) -endforeach() \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8e61b7a..3de44b3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,6 +1,6 @@ add_executable(module-tests oatpp-swagger/tests.cpp - ) +) set_target_properties(module-tests PROPERTIES CXX_STANDARD 11 @@ -12,20 +12,18 @@ target_include_directories(module-tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ) -if(MODULE_WAIT_DEPS) - add_dependencies(module-tests ${LIB_oatpp}) +if(OATPP_MODULES_LOCATION STREQUAL OATPP_MODULES_LOCATION_EXTERNAL) + add_dependencies(module-tests ${LIB_OATPP_EXTERNAL}) endif() add_dependencies(module-tests ${OATPP_THIS_MODULE_NAME}) -target_link_directories(module-tests - PRIVATE ${OATPP_DIR_LIB}/src -) +target_link_oatpp(module-tests) target_link_libraries(module-tests - PRIVATE oatpp - PRIVATE oatpp-test PRIVATE ${OATPP_THIS_MODULE_NAME} ) +## TODO link dependencies here (if some) + add_test(module-tests module-tests) \ No newline at end of file diff --git a/utility/install-deps/install-my-dependency.sh b/utility/install-deps/install-my-dependency.sh new file mode 100755 index 0000000..54764ee --- /dev/null +++ b/utility/install-deps/install-my-dependency.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "steps to install some my dependency" diff --git a/utility/module-uninstall.sh b/utility/module-uninstall.sh new file mode 100755 index 0000000..83bf1f4 --- /dev/null +++ b/utility/module-uninstall.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +MODULE_NAME="oatpp-swagger" +MODULE_VERSION="0.19.1" + +echo "remove include folder: '/usr/local/include/oatpp-$MODULE_VERSION/$MODULE_NAME'" +rm -rf "/usr/local/include/oatpp-$MODULE_VERSION/$MODULE_NAME" + +echo "remove cmake package: '/usr/local/lib/cmake/$MODULE_NAME-$MODULE_VERSION'" +rm -rf "/usr/local/lib/cmake/$MODULE_NAME-$MODULE_VERSION" + +MODULE_LIB_PATH="/usr/local/lib/oatpp-$MODULE_VERSION" + +echo "remove '$MODULE_LIB_PATH/lib$MODULE_NAME.dylib'" +rm "$MODULE_LIB_PATH/lib$MODULE_NAME.dylib" + +echo "remove '$MODULE_LIB_PATH/lib$MODULE_NAME.so'" +rm "$MODULE_LIB_PATH/lib$MODULE_NAME.so" + +echo "remove '$MODULE_LIB_PATH/lib$MODULE_NAME.a'" +rm "$MODULE_LIB_PATH/lib$MODULE_NAME.a"