Improved Conan Recipe, fixing build with flags

This commit is contained in:
Michele Adduci
2022-02-19 20:52:14 +00:00
parent 8e2823d0d7
commit 678887ffeb
8 changed files with 87 additions and 62 deletions

View File

@@ -1,5 +1,14 @@
# openE57
## [1.6.2] -
## Changed
- Improved Conan recipe, including tools
- Minor improvements in CMake
## Removed
- Removed custom option to build with PIC on Unix, using CMAKE_POSITION_INDEPENDENT_CODE
## [1.6.1] - 2022-02-16
## Changed

View File

@@ -42,7 +42,7 @@ cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR)
# Enables the CMAKE_MSVC_RUNTIME_LIBRARY property on targets
cmake_policy(SET CMP0091 NEW)
project(openE57 VERSION 1.6.1 LANGUAGES C CXX DESCRIPTION "openE57 is a library for handling E57 files")
project(openE57 VERSION 1.6.2 LANGUAGES C CXX DESCRIPTION "openE57 is a library for handling E57 files")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
@@ -60,7 +60,6 @@ option(BUILD_TOOLS "Build opene57 tools" FALSE)
option(BUILD_TESTS "Build opene57 tests" FALSE)
option(BUILD_SHARED_LIBS "Build opene57 shared libraries" FALSE)
option(BUILD_WITH_MT "Build the project with /MT when using Visual Studio" FALSE)
option(BUILD_WITH_FPIC "Build the project with -fPIC on Unix" TRUE)
if(BUILD_SHARED_LIBS)
message(FATAL_ERROR "Shared Libraries are not supported due to missing exported symbols")
@@ -68,16 +67,22 @@ else(BUILD_SHARED_LIBS)
set(LIBRARY_TYPE STATIC)
endif()
# Make it aware of Conan
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
add_subdirectory(${CMAKE_SOURCE_DIR}/src)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src)
#
# Install Artifacts
#
install(FILES ${CMAKE_SOURCE_DIR}/CHANGELOG.md
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md
DESTINATION .)
set(CPACK_PACKAGE_VENDOR "Michele Adduci <adduci@tutanota.com>")

View File

@@ -56,10 +56,12 @@ Available CMake Options are:
* BUILD_TOOLS
* BUILD_TESTS - actually unsupported (no tests yet available)
* BUILD_SHARED_LIBS - actually unsupported (missing exported symbols)
* BUILD_WITH_MT - activates/disables the `/MT[d]` flag when using Visual Studio
* BUILD_WITH_FPIC - activates/disables the `-fPIC` flag on gcc/clang compilers on Linux/Mac
* BUILD_WITH_MT - instructs CMake to set the correct [`CMAKE_MSVC_RUNTIME_LIBRARY`](https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html?highlight=cmake_msvc_runtime_library) flag for Visual Studio
On Linux:
Building with Position indipendent code on Unix can be activated with the option [`CMAKE_POSITION_INDEPENDENT_CODE`](https://cmake.org/cmake/help/latest/variable/CMAKE_POSITION_INDEPENDENT_CODE.html?highlight=cmake_position_independent_code).
#### On Linux:
```shell
git clone https://github.com/madduci/openE57.git
@@ -70,13 +72,13 @@ cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build . --config Release --target install
```
On Windows:
#### On Windows:
```cmd
git clone https://github.com/madduci/openE57.git
cd open57
md build && cd build
conan create . --build=missing
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_WITH_MT=[TRUE|FALSE]
conan install .. --build=missing
cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_WITH_MT=ON
cmake --build . --config Release --target install
```

View File

@@ -5,25 +5,34 @@ import os
class Opene57Conan(ConanFile):
name = "opene57"
version = "1.6.1"
version = "1.6.2"
description = "A C++ library for reading and writing E57 files, " \
"fork of the original libE57 (http://libe57.org)"
topics = ("conan", "openE57", "e57")
url = "https://github.com/openE57/openE57"
topics = ("e57", "libe57", "3d", "astm")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/openE57/openE57"
license = ("MIT", "BSL-1.0")
exports_sources = [ "src/*", "LICENSE*", "CHANGELOG.md", "*.txt"]
generators = "cmake", "cmake_find_package"
short_paths = True
_cmake = None
settings = "os", "compiler", "arch", "build_type"
options = {"with_tools": [True, False],
"shared": [True, False],
"fPIC": [True, False]}
options = { "with_tools": [True, False],
"shared": [True, False],
"fPIC": [True, False]
}
default_options = {
'with_tools': False,
'shared': False,
'fPIC': True}
"with_tools": False,
"shared": False,
"fPIC": True
}
generators = "cmake", "cmake_find_package"
_cmake = None
@property
def _source_subfolder(self):
return "source_subfolder"
@property
def _build_subfolder(self):
return "build_subfolder"
@property
def _minimum_compilers_version(self):
@@ -34,18 +43,27 @@ class Opene57Conan(ConanFile):
"apple-clang": "10",
}
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def configure(self):
if self.options.shared:
del self.options.fPIC
self.options['xerces-c'].shared = self.options.shared
if self.settings.os == "Linux" or tools.is_apple_os(self.settings.os):
self.options['icu'].shared = self.options.shared
if self.options.with_tools:
self.options['boost'].shared = self.options.shared
self.options['boost'].multithreading = True
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def validate(self):
if self.options.shared:
raise ConanInvalidConfiguration("OpenE57 cannot be built as shared library yet")
if self.settings.compiler.get_safe("cppstd"):
tools.check_min_cppstd(self, 17)
@@ -54,28 +72,16 @@ class Opene57Conan(ConanFile):
self.output.warn("C++17 support required. Your compiler is unknown. Assuming it supports C++17.")
elif tools.Version(self.settings.compiler.version) < minimum_version:
raise ConanInvalidConfiguration("C++17 support required, which your compiler does not support.")
# Check stdlib ABI compatibility
compiler_name = str(self.settings.compiler)
if compiler_name == "gcc" and self.settings.compiler.libcxx != "libstdc++11":
raise ConanInvalidConfiguration('Using %s with GCC requires "compiler.libcxx=libstdc++11"' % self.name)
elif compiler_name == "clang" and self.settings.compiler.libcxx not in ["libstdc++11", "libc++"]:
raise ConanInvalidConfiguration('Using %s with Clang requires either "compiler.libcxx=libstdc++11"'
' or "compiler.libcxx=libc++"' % self.name)
def build_requirements(self):
if self.options.with_tools:
self.build_requires("boost/1.78.0")
self.options["boost"].multithreading = True
self.options["boost"].shared = self.options.shared
def requirements(self):
if self.settings.os == "Linux" or tools.is_apple_os(self.settings.os):
self.requires("icu/70.1")
self.options["icu"].shared = self.options.shared
self.requires("xerces-c/3.2.3")
self.options["xerces-c"].shared = self.options.shared
def _configure_cmake(self):
if self._cmake:
@@ -88,14 +94,22 @@ class Opene57Conan(ConanFile):
if self.settings.os == "Windows":
self._cmake.definitions["BUILD_WITH_MT"] = "MT" in str(msvc_runtime_flag(self))
else:
self._cmake.definitions["BUILD_WITH_FPIC"] = self.options.fPIC
self._cmake.configure()
self._cmake.definitions["CMAKE_POSITION_INDEPENDENT_CODE"] = self.options.get_safe("fPIC", True)
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
def build(self):
cmake = self._configure_cmake()
cmake.build()
def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
self.copy(pattern="LICENSE.libE57", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
os.remove(os.path.join(self.package_folder, "CHANGELOG.md"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.dll")
def package_info(self):
if self.options.with_tools:
bin_path = os.path.join(self.package_folder, "bin")
@@ -106,20 +120,10 @@ class Opene57Conan(ConanFile):
self.cpp_info.libs = [f"openE57{lib_suffix}", f"openE57las{lib_suffix}"]
self.cpp_info.defines.append(f"E57_REFIMPL_REVISION_ID={self.name}-{self.version}")
self.cpp_info.defines.append("NOMINMAX")
if self.options.shared == False:
self.cpp_info.defines.append("XERCES_STATIC_LIBRARY")
self.cpp_info.defines.append("XERCES_STATIC_LIBRARY")
self.cpp_info.set_property("cmake_target_name", "opene57")
self.cpp_info.set_property("cmake_target_name", "opene57")
# TODO: To remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "opene57"
self.cpp_info.names["cmake_find_package_multi"] = "opene57"
def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=".")
self.copy(pattern="LICENSE.libE57", dst="licenses", src=".")
cmake = self._configure_cmake()
cmake.install()
os.remove(os.path.join(self.package_folder, "CHANGELOG.md"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.dll")

View File

@@ -1,3 +1,7 @@
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "-d")
endif()
if(MSVC)
list(APPEND compiler_options
@@ -55,7 +59,8 @@ else(MSVC)
$<$<AND:$<NOT:$<CXX_COMPILER_ID:AppleClang>>,$<NOT:$<CXX_COMPILER_ID:Clang>>>:-fstack-clash-protection>
$<$<AND:$<NOT:$<CXX_COMPILER_ID:AppleClang>>,$<NOT:$<CXX_COMPILER_ID:Clang>>>:-fbounds-check>
-fstack-protector
$<$<BOOL:${BUILD_WITH_FPIC}>-fPIC>
)
message(STATUS "Selected CMAKE_POSITION_INDEPENDENT_CODE: ${CMAKE_POSITION_INDEPENDENT_CODE}")
endif()

View File

@@ -6,14 +6,14 @@ list(APPEND EXAMPLES
foreach(EXAMPLE ${EXAMPLES})
add_executable(${EXAMPLE} ${CMAKE_CURRENT_SOURCE_DIR}/${EXAMPLE}.cpp)
set_target_properties(${EXAMPLE} PROPERTIES
DEBUG_POSTFIX "-d"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
MSVC_RUNTIME_LIBRARY "${CMAKE_MSVC_RUNTIME_LIBRARY}")
target_compile_options(${EXAMPLE} PUBLIC ${compiler_options})
target_compile_definitions(${EXAMPLE} PUBLIC ${compiler_definitions})
target_link_options(${EXAMPLE} PUBLIC ${linker_flags})
target_include_directories(${EXAMPLE} PRIVATE
${CMAKE_SOURCE_DIR}/src/lib/include
${CMAKE_CURRENT_SOURCE_DIR}/../lib/include
${XML_INCLUDE_DIRS} )
target_link_libraries(${EXAMPLE}
PRIVATE

View File

@@ -17,7 +17,7 @@ add_library(
generate_export_header(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES
DEBUG_POSTFIX "-d"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
MSVC_RUNTIME_LIBRARY "${CMAKE_MSVC_RUNTIME_LIBRARY}")
target_compile_options(${PROJECT_NAME} PUBLIC ${compiler_options})
target_compile_definitions(${PROJECT_NAME} PUBLIC ${compiler_definitions})
@@ -40,7 +40,7 @@ add_library(${PROJECT_NAME}las ${LIBRARY_TYPE}
${CMAKE_CURRENT_SOURCE_DIR}/include/openE57/LAS/${PROJECT_NAME}las.h)
set_target_properties(${PROJECT_NAME}las PROPERTIES
DEBUG_POSTFIX "-d"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
MSVC_RUNTIME_LIBRARY "${CMAKE_MSVC_RUNTIME_LIBRARY}")
target_compile_options(${PROJECT_NAME}las PUBLIC ${compiler_options})
target_compile_definitions(${PROJECT_NAME}las PUBLIC ${compiler_definitions})

View File

@@ -43,7 +43,7 @@ foreach(TOOL ${TOOLS})
add_executable(${TOOL} ${CMAKE_CURRENT_SOURCE_DIR}/${TOOL}.cpp)
set_target_properties(${TOOL} PROPERTIES
DEBUG_POSTFIX "-d"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
MSVC_RUNTIME_LIBRARY "${CMAKE_MSVC_RUNTIME_LIBRARY}")
target_compile_options(${TOOL} PUBLIC ${compiler_options})
target_compile_definitions(${TOOL} PUBLIC ${compiler_definitions})
@@ -51,7 +51,7 @@ foreach(TOOL ${TOOLS})
target_include_directories(${TOOL}
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
${CMAKE_SOURCE_DIR}/src/lib/include
${CMAKE_CURRENT_SOURCE_DIR}/../lib/include
${XML_INCLUDE_DIRS}
${Boost_INCLUDE_DIR}
)
@@ -71,7 +71,7 @@ endforeach()
add_executable(las2e57 ${CMAKE_CURRENT_SOURCE_DIR}/las2e57.cpp)
set_target_properties(las2e57 PROPERTIES
DEBUG_POSTFIX "-d"
DEBUG_POSTFIX ${CMAKE_DEBUG_POSTFIX}
MSVC_RUNTIME_LIBRARY "${CMAKE_MSVC_RUNTIME_LIBRARY}")
target_compile_options(las2e57 PUBLIC ${compiler_options})
target_compile_definitions(las2e57 PUBLIC ${compiler_definitions})
@@ -80,7 +80,7 @@ target_link_options(las2e57 PUBLIC ${linker_flags})
target_include_directories(las2e57
PRIVATE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
${CMAKE_SOURCE_DIR}/src/lib/include
${CMAKE_CURRENT_SOURCE_DIR}/../lib/include
${XML_INCLUDE_DIRS}
${Boost_INCLUDE_DIR}
)