Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 97 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,111 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.15)
project(sdptransform VERSION 1.2.10 LANGUAGES CXX)

project(sdptransform VERSION 1.2.10)
#-----------------------------------------------------------------------------
# Options
#-----------------------------------------------------------------------------
option(SDPTRANSFORM_BUILD_TESTS "Build the test and readme-helper subdirs" ON)

# For CMake >= 3.1.
#-----------------------------------------------------------------------------
# C++ Standard
#-----------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# For CMake < 3.1.


# If old CMake or compilers:
add_compile_options(-std=c++14)

subdirs(test readme-helper)
#-----------------------------------------------------------------------------
# Optional subdirectories (test, readme-helper)
#-----------------------------------------------------------------------------
if(SDPTRANSFORM_BUILD_TESTS)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/readme-helper/CMakeLists.txt")
add_subdirectory(readme-helper)
endif()
endif()

#-----------------------------------------------------------------------------
# Library Sources/Headers
#-----------------------------------------------------------------------------
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")

set(SDPTRANSFORM_SOURCE
src/grammar.cpp
src/parser.cpp
src/writer.cpp
)

set(SDPTRANSFORM_HEADERS
include/sdptransform.hpp
include/json.hpp
)

include_directories(${sdptransform_SOURCE_DIR}/include)
#-----------------------------------------------------------------------------
# Build Library
#-----------------------------------------------------------------------------
add_library(sdptransform
${SDPTRANSFORM_SOURCE}
${SDPTRANSFORM_HEADERS}
)

set(
SOURCE_FILES
src/grammar.cpp
src/parser.cpp
src/writer.cpp
# If user toggles BUILD_SHARED_LIBS to ON, this library will be shared;
# if OFF (default), it’s static..
target_include_directories(sdptransform
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)

set(
HEADER_FILES
include/sdptransform.hpp
include/json.hpp
#-----------------------------------------------------------------------------
# Installation
#-----------------------------------------------------------------------------
# The library itself
install(TARGETS sdptransform
EXPORT sdptransform-targets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
# The headers
install(FILES ${SDPTRANSFORM_HEADERS} DESTINATION include/sdptransform)

add_library(sdptransform STATIC ${SOURCE_FILES} ${HEADER_FILES})
#-----------------------------------------------------------------------------
# CMake Config Files for find_package(sdptransform)
#-----------------------------------------------------------------------------
include(CMakePackageConfigHelpers)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/sdptransform-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

# A minimal sdptransform-config.cmake.
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/sdptransform-config.cmake" "
include(CMakeFindDependencyMacro)
# add any find_dependency(...) lines if needed
include(\"\${CMAKE_CURRENT_LIST_DIR}/sdptransform-targets.cmake\")
")

# Install config + version
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/sdptransform-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/sdptransform-config-version.cmake"
DESTINATION lib/cmake/sdptransform
)

# Export the library target
install(EXPORT sdptransform-targets
FILE sdptransform-targets.cmake
NAMESPACE sdptransform::
DESTINATION lib/cmake/sdptransform
)

install(TARGETS sdptransform DESTINATION lib)
install(FILES ${HEADER_FILES} DESTINATION include/sdptransform)
message(STATUS "sdptransform build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}")
message(STATUS "SDPTRANSFORM_BUILD_TESTS=${SDPTRANSFORM_BUILD_TESTS}")
75 changes: 75 additions & 0 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from conan import ConanFile
from conan.tools.scm import Git
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy
import os

class SdpTransformConan(ConanFile):
name = "sdptransform"
version = "1.2.10"
license = "MIT"
url = "https://github.com/zaki699/libsdptransform"
description = "A C/C++ parser for SDP, with JSON logic from sdptransform"
topics = ("webrtc", "sdp", "parser", "json")
settings = "os", "arch", "compiler", "build_type"

# We'll allow "shared" and "tests" as Conan options
options = {
"shared": [True, False],
"tests": [True, False],
}
default_options = {
"shared": False,
"tests": False,
}

exports_sources = "CMakeLists.txt", "src/*", "include/*"

# CMake package => a library
package_type = "library"

# For source():
scm = {
"type": "git",
"url": "https://github.com/zaki699/libsdptransform.git",
"revision": "main"
}

def layout(self):
cmake_layout(self)

def generate(self):
# Create a CMake toolchain
tc = CMakeToolchain(self)

# If user wants a shared library, set BUILD_SHARED_LIBS=ON
tc.variables["BUILD_SHARED_LIBS"] = "ON" if self.options.shared else "OFF"

# If user wants to build tests, set SDPTRANSFORM_BUILD_TESTS=ON
tc.variables["SDPTRANSFORM_BUILD_TESTS"] = "ON" if self.options.tests else "OFF"

# If your library needs something else, set them here
# e.g. tc.cache_variables["CMAKE_POSITION_INDEPENDENT_CODE"] = True if self.options.shared else ...

tc.generate()

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

def package(self):
# Run "cmake install"
cmake = CMake(self)
cmake.install()

# Copy the license file from the source if available
copy(self, "LICENSE", self.source_folder,
os.path.join(self.package_folder, "licenses"), keep_path=False)

def package_info(self):
# The library name is "sdptransform" as built by the CMakeLists
self.cpp_info.libs = ["sdptransform"]

self.cpp_info.set_property("cmake_file_name", "sdptransform")
self.cpp_info.set_property("cmake_target_name", "sdptransform::sdptransform")