better module structure + CI scripts

This commit is contained in:
lganzzzo 2019-01-27 00:48:59 +02:00
parent 5e2aa9e8be
commit b95a62548d
11 changed files with 232 additions and 82 deletions

View File

@ -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()
endif()

46
azure-pipelines.yml Normal file
View File

@ -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

View File

@ -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@)

View File

@ -14,7 +14,7 @@
## | |- <module-name>Config.cmake
## | - <module-name>ConfigVersion.cmake
## |
## |- oatpp-<version>/
## - oatpp-<version>/
## |
## |- 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/<dirs>)
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}"
)

25
cmake/module-utils.cmake Normal file
View File

@ -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 $<BUILD_INTERFACE:${OATPP_DIR_SRC}>)
target_link_directories(${target} PRIVATE ${OATPP_DIR_LIB})
target_link_libraries(${target}
PRIVATE oatpp
PRIVATE oatpp-test
)
endif()
endmacro()

15
lgtm.yml Normal file
View File

@ -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:

View File

@ -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 $<BUILD_INTERFACE:${OATPP_DIR_SRC}/src>
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
PUBLIC $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
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()
include("../cmake/module-install.cmake")
endif()

View File

@ -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()

View File

@ -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)

View File

@ -0,0 +1,3 @@
#!/bin/sh
echo "steps to install some my dependency"

21
utility/module-uninstall.sh Executable file
View File

@ -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"