Skip to content

Commit

Permalink
(#12197) gsoap: add fPIC option + add test_v1_package + few improvements
Browse files Browse the repository at this point in the history
* add test_v1_package

* some improvements:

- conan >=1.46.0 is required
- use GNUInstallDirs in custom CMakeLists
- isolate source code under src folder
- move custom cmake files under cmake folder instead of src folder
- install imports directly under bin folder instead of moving it after installation
- add VirtualBuildEnv since there are tool_requires
- reorder methos by order of execution

* add shared & fPIC options

* no need for CMAKE_SOURCE_DIR

* explicit cpp_info.requires

due to conan-io/conan#11789
fixed by conan-io/conan#11790

* remove shared option

* winflexbison for msvc only

* check compiler from build profile
  • Loading branch information
SpaceIm authored Aug 23, 2022
1 parent fc25e74 commit 759a6e5
Show file tree
Hide file tree
Showing 9 changed files with 119 additions and 64 deletions.
12 changes: 7 additions & 5 deletions recipes/gsoap/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.0)
project(gSOAP)

include(GNUInstallDirs)

option(BUILD_TOOLS "Build soapcpp2 and wsdl2h" ON)
option(BUILD_GSOAP "Build gsoap library" ON)

Expand All @@ -13,15 +15,15 @@ endif()

# Tools
if(${BUILD_TOOLS})
include(${CMAKE_SOURCE_DIR}/src/soapcpp2.cmake)
include(${CMAKE_SOURCE_DIR}/src/wsdl2h.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/soapcpp2.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/wsdl2h.cmake)

install(FILES ${CMAKE_SOURCE_DIR}/${GSOAP_PATH}/gsoap/typemap.dat DESTINATION res)
install(DIRECTORY ${CMAKE_SOURCE_DIR}/${GSOAP_PATH}/gsoap/import DESTINATION .
install(FILES ${GSOAP_PATH}/gsoap/typemap.dat DESTINATION res)
install(DIRECTORY ${GSOAP_PATH}/gsoap/import DESTINATION ${CMAKE_INSTALL_BINDIR}
FILES_MATCHING PATTERN "*.h")
endif()

# Libraries
if(${BUILD_GSOAP})
include(${CMAKE_SOURCE_DIR}/src/gsoap.cmake)
include(${PROJECT_SOURCE_DIR}/cmake/gsoap.cmake)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ set(SRCS_GSOAP_C
set_source_files_properties(${SRCS_GSOAP_C} PROPERTIES LANGUAGE C)
add_library(gsoap ${SRCS_GSOAP_C} ${GSOAP_PATH}/gsoap/stdsoap2.h)
set_target_properties(gsoap PROPERTIES
COMPILE_PDB_OUTPUT_DIRECTORY bin
PDB_OUTPUT_DIRECTORY bin
PUBLIC_HEADER ${GSOAP_PATH}/gsoap/stdsoap2.h
DEFINE_SYMBOL "SOAP_STD_EXPORTS"
LINKER_LANGUAGE C
)
install(TARGETS gsoap
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)


Expand All @@ -35,16 +34,15 @@ set(SRCS_GSOAP_CXX
set_source_files_properties(${SRCS_GSOAP_CXX} PROPERTIES LANGUAGE CXX)
add_library(gsoap++ ${SRCS_GSOAP_CXX} ${GSOAP_PATH}/gsoap/stdsoap2.h)
set_target_properties(gsoap++ PROPERTIES
COMPILE_PDB_OUTPUT_DIRECTORY bin
PDB_OUTPUT_DIRECTORY bin
PUBLIC_HEADER ${GSOAP_PATH}/gsoap/stdsoap2.h
DEFINE_SYMBOL "SOAP_STD_EXPORTS"
LINKER_LANGUAGE CXX
)
install(TARGETS gsoap++
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

# Add SSL if requested
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Generate project for soapcpp2 executable

set(STDCPP2_PATH ${CMAKE_SOURCE_DIR}/${GSOAP_PATH}/gsoap/src)
set(STDCPP2_PATH ${GSOAP_PATH}/gsoap/src)

set(SRC_CPP
${STDCPP2_PATH}/symbol2.c
Expand Down Expand Up @@ -62,4 +62,4 @@ endif()
target_include_directories(soapcpp2 PRIVATE ${STDCPP2_PATH})
set_source_files_properties(${SRC_CPP} PROPERTIES LANGUAGE C)
add_dependencies(soapcpp2 FLEXBISON_GENERATORS)
install(TARGETS soapcpp2 RUNTIME DESTINATION bin)
install(TARGETS soapcpp2 DESTINATION ${CMAKE_INSTALL_BINDIR})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# Generate project for wsdl2h

set(WSDL2H_PATH ${CMAKE_SOURCE_DIR}/${GSOAP_PATH}/gsoap/wsdl)
set(WSDL2H_PATH ${GSOAP_PATH}/gsoap/wsdl)

set(SRC_CPP
${WSDL2H_PATH}/wsdl2h.cpp
Expand Down Expand Up @@ -61,4 +61,4 @@ if(${WITH_OPENSSL})
target_link_libraries(wsdl2h OpenSSL::Crypto OpenSSL::SSL ZLIB::ZLIB)
endif()

install(TARGETS wsdl2h RUNTIME DESTINATION bin)
install(TARGETS wsdl2h DESTINATION ${CMAKE_INSTALL_BINDIR})
92 changes: 53 additions & 39 deletions recipes/gsoap/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from conan import ConanFile
from conan import tools
from conan.tools.build import cross_building
from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get
import os
import shutil

required_conan_version = ">=1.45.0"
required_conan_version = ">=1.46.0"


class GsoapConan(ConanFile):
name = "gsoap"
Expand All @@ -16,28 +18,57 @@ class GsoapConan(ConanFile):
topics = ("gsoap", "logging")
settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"with_openssl": [True, False],
"with_ipv6": [True, False],
"with_cookies": [True, False],
"with_c_locale": [True, False],
}
default_options = {
'with_openssl': True,
'with_ipv6': True,
'with_cookies': True,
'with_c_locale': True,
"fPIC": True,
"with_openssl": True,
"with_ipv6": True,
"with_cookies": True,
"with_c_locale": True,
}

exports_sources = "CMakeLists.txt", "cmake/*.cmake"
short_paths = True

def export_sources(self):
tools.files.copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
tools.files.copy(self, "*.cmake", os.path.join(self.recipe_folder, "src"), os.path.join(self.export_sources_folder, "src"))
for p in self.conan_data.get("patches", {}).get(self.version, []):
tools.files.copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)
@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def requirements(self):
if self.options.with_openssl:
self.requires("openssl/1.1.1q")
self.requires("zlib/1.2.12")

def build_requirements(self):
if cross_building(self, skip_x64_x86=True) and hasattr(self, "settings_build"):
self.tool_requires("gsoap/{}".format(self.version))

# TODO: use is_msvc with build profile when possible (see https://github.com/conan-io/conan/issues/11926)
if str(self._settings_build.compiler) in ["Visual Studio", "msvc"]:
self.tool_requires("winflexbison/2.5.24")
else:
self.tool_requires("bison/3.7.6")
self.tool_requires("flex/2.6.4")

def layout(self):
cmake_layout(self, src_folder="src")

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
toolchain = CMakeToolchain(self)
toolchain.variables["GSOAP_PATH"] = "."
toolchain.variables["GSOAP_PATH"] = self.source_folder.replace("\\", "/")
toolchain.variables["BUILD_TOOLS"] = True
toolchain.variables["WITH_OPENSSL"] = self.options.with_openssl
toolchain.variables["WITH_IPV6"] = self.options.with_ipv6
Expand All @@ -48,40 +79,19 @@ def generate(self):
deps = CMakeDeps(self)
deps.generate()

def layout(self):
cmake_layout(self)

def source(self):
tools.files.get(self,
**self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
ms = VirtualBuildEnv(self)
ms.generate()

def build(self):
cmake = CMake(self)
cmake.configure(build_script_folder=".")
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def build_requirements(self):
if tools.build.cross_building(self, skip_x64_x86=True) and hasattr(self, 'settings_build'):
self.tool_requires("gsoap/{}".format(self.version))

if self.settings.os == "Windows" or (hasattr(self, "settings_build") and self.settings_build.os == "Windows"):
self.tool_requires("winflexbison/2.5.24")
else:
self.tool_requires("bison/3.7.6")
self.tool_requires("flex/2.6.4")

def requirements(self):
if self.options.with_openssl:
self.requires("openssl/1.1.1q")
self.requires("zlib/1.2.12")

def package(self):
tools.files.copy(self, "GPLv2_license.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
tools.files.copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
copy(self, "GPLv2_license.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "LICENSE.txt", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
shutil.move(os.path.join(self.package_folder, 'import'), os.path.join(self.package_folder, 'bin', 'import'))

def package_info(self):
defines = []
Expand All @@ -100,3 +110,7 @@ def package_info(self):
if self.options.with_c_locale:
defines.append("WITH_C_LOCALE")
self.cpp_info.defines = defines

# TODO: remove this block if required_conan_version changed to 1.51.1 or higher
# (see https://github.com/conan-io/conan/pull/11790)
self.cpp_info.requires = ["openssl::openssl", "zlib::zlib"]
6 changes: 3 additions & 3 deletions recipes/gsoap/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.0)
project(test_package CXX)
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)

find_package(gsoap REQUIRED CONFIG)

Expand All @@ -9,4 +9,4 @@ add_executable(${PROJECT_NAME}
${CMAKE_BINARY_DIR}/soapcalcProxy.cpp
)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} gsoap::gsoap)
target_link_libraries(${PROJECT_NAME} PRIVATE gsoap::gsoap)
2 changes: 1 addition & 1 deletion recipes/gsoap/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def build(self):
# TODO: Add some test for the cross-building scenario

if not cross_building(self):
calc_wsdl = os.path.join(os.path.dirname(__file__), 'calc.wsdl')
calc_wsdl = os.path.join(self.source_folder, "calc.wsdl")
self.output.info("Generating code from WSDL '{}'".format(calc_wsdl))
self.run("wsdl2h -o calc.h {}".format(calc_wsdl), run_environment=True)
self.run("soapcpp2 -j -CL -I{} calc.h".format(os.path.join(self.deps_cpp_info["gsoap"].rootpath, 'bin', 'import')), run_environment=True)
Expand Down
15 changes: 15 additions & 0 deletions recipes/gsoap/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES CXX)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(gsoap REQUIRED CONFIG)

add_executable(${PROJECT_NAME}
../test_package/test_package.cpp
${CMAKE_BINARY_DIR}/soapC.cpp
${CMAKE_BINARY_DIR}/soapcalcProxy.cpp
)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_BINARY_DIR})
target_link_libraries(${PROJECT_NAME} PRIVATE gsoap::gsoap)
26 changes: 26 additions & 0 deletions recipes/gsoap/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# pylint: skip-file
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
# TODO: Add some test for the cross-building scenario

if not tools.cross_building(self):
calc_wsdl = os.path.join(self.source_folder, os.pardir, "test_package", "calc.wsdl")
self.output.info("Generating code from WSDL '{}'".format(calc_wsdl))
self.run("wsdl2h -o calc.h {}".format(calc_wsdl), run_environment=True)
self.run("soapcpp2 -j -CL -I{} calc.h".format(os.path.join(self.deps_cpp_info["gsoap"].rootpath, 'bin', 'import')), run_environment=True)

cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 759a6e5

Please sign in to comment.