Skip to content

mikktspace: conan v2 support #14359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 1, 2022
Merged
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
20 changes: 9 additions & 11 deletions recipes/mikktspace/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
cmake_minimum_required(VERSION 3.4)
project(mikktspace)
project(mikktspace LANGUAGES C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_library(mikktspace ${MIKKTSPACE_SRC_DIR}/mikktspace.c)
target_include_directories(mikktspace PUBLIC ${MIKKTSPACE_SRC_DIR})
set_target_properties(mikktspace PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)

if(WIN32 AND BUILD_SHARED_LIBS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
endif()

add_library(mikktspace ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder/mikktspace.c)
target_include_directories(mikktspace PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder)
if(CMAKE_HOST_SYSTEM_NAME MATCHES "Linux")
include(CheckFunctionExists)
check_function_exists(pow HAVE_MATH_SYSTEM)
if(NOT HAVE_MATH_SYSTEM)
target_link_libraries(mikktspace PRIVATE m)
endif()

include(GNUInstallDirs)
install(TARGETS mikktspace
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder/mikktspace.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${MIKKTSPACE_SRC_DIR}/mikktspace.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
61 changes: 29 additions & 32 deletions recipes/mikktspace/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, save
import os
import glob
from conans import ConanFile, CMake, tools

required_conan_version = ">=1.53.0"


class MikkTSpaceConan(ConanFile):
Expand All @@ -9,67 +12,61 @@ class MikkTSpaceConan(ConanFile):
homepage = "https://github.com/mmikk/MikkTSpace"
url = "https://github.com/conan-io/conan-center-index"
license = "Zlib"
topics = ("conan", "tangent", "space", "normal")
topics = ("tangent", "space", "normal")

settings = "os", "arch", "compiler", "build_type"
options = {
"fPIC": [True, False],
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"shared": False
}

generators = "cmake"
exports_sources = ['CMakeLists.txt']

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = glob.glob('MikkTSpace-*/')[0]
os.rename(extracted_dir, self._source_subfolder)
exports_sources = "CMakeLists.txt"

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

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

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 _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
def generate(self):
tc = CMakeToolchain(self)
tc.variables["MIKKTSPACE_SRC_DIR"] = self.source_folder.replace("\\", "/")
tc.generate()

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

@property
def _extracted_license(self):
content_lines = open(os.path.join(self.source_folder, self._source_subfolder, "mikktspace.h")).readlines()
content_lines = open(os.path.join(self.source_folder, "mikktspace.h")).readlines()
license_content = []
for i in range(4, 21):
license_content.append(content_lines[i][4:-1])
return "\n".join(license_content)

def package(self):
tools.save(os.path.join(self.package_folder, "licenses", "LICENSE"), self._extracted_license)
cmake = self._configure_cmake()
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), self._extracted_license)
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["mikktspace"]
if self.settings.os == "Linux":
if not self.options.shared and self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]
10 changes: 4 additions & 6 deletions recipes/mikktspace/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package LANGUAGES C)

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

add_executable(${CMAKE_PROJECT_NAME} test_package.cpp)
target_link_libraries(${CMAKE_PROJECT_NAME} ${CONAN_LIBS})
find_package(mikktspace REQUIRED CONFIG)

add_executable(${CMAKE_PROJECT_NAME} test_package.c)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE mikktspace::mikktspace)
20 changes: 15 additions & 5 deletions recipes/mikktspace/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake_find_package", "cmake"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

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

def test(self):
if not tools.cross_building(self.settings):
self.run(os.path.join("bin", "test_package"), run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
#include <assert.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include <mikktspace.h>
#include <stdlib.h>

static int GetNumFaces(const SMikkTSpaceContext *pContext)
{
return 0;
return 0;
}

int main()
Expand Down
8 changes: 8 additions & 0 deletions recipes/mikktspace/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/mikktspace/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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):
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)