Skip to content

Commit

Permalink
flatcc: add macOS workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Dec 25, 2023
1 parent 5df2d51 commit 215ee43
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
23 changes: 20 additions & 3 deletions recipes/flatcc/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os

from conan import ConanFile
from conan import ConanFile, conan_version
from conan.tools.apple import is_apple_os
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
from conan.tools.cmake import cmake_layout, CMake, CMakeToolchain
from conan.tools.env import VirtualRunEnv
from conan.tools.files import mkdir


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

def requirements(self):
Expand All @@ -20,13 +22,28 @@ def build_requirements(self):
def layout(self):
cmake_layout(self)

@property
def _macos_workaround(self):
return conan_version.major == 1 and self.options["flatcc"].shared and is_apple_os(self)

def generate(self):
VirtualRunEnv(self).generate(scope="build")
VirtualRunEnv(self).generate(scope="run")
tc = CMakeToolchain(self)
tc.variables["MACOS_SIP_WORKAROUND"] = self._macos_workaround
tc.generate()


def build(self):
cmake = CMake(self)
if self._macos_workaround:
# Because of MacOS System Integrity Protection it is currently not possible to run the flatcc
# executable from cmake if it is linked shared. As a temporary work-around run flatcc here in
# the build function.
gen_dir = os.path.join(self.build_folder, "generated")
mkdir(self, gen_dir)
fbs_file = os.path.join(self.source_folder, os.pardir, "test_package", "monster.fbs")
self.run(f"flatcc -a -o {gen_dir} {fbs_file}")
cmake.configure()
cmake.build()

Expand Down
9 changes: 5 additions & 4 deletions recipes/flatcc/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def build(self):
with tools.environment_append(env_build.vars):
cmake = CMake(self)
if tools.os_info.is_macos and self.options["flatcc"].shared:
# Because of MacOS System Integraty Protection it is currently not possible to run the flatcc
# Because of MacOS System Integrity Protection it is currently not possible to run the flatcc
# executable from cmake if it is linked shared. As a temporary work-around run flatcc here in
# the build function.
tools.mkdir(os.path.join(self.build_folder, "generated"))
self.run("flatcc -a -o " + os.path.join(self.build_folder, "generated") + " " + os.path.join(self.source_folder, "monster.fbs"), run_environment=True)
cmake.definitions["MACOS_SIP_WORKAROUND"] = True
gen_dir = os.path.join(self.build_folder, "generated")
tools.mkdir(gen_dir)
fbs_file = os.path.join(self.source_folder, "monster.fbs")
self.run(f"flatcc -a -o {gen_dir} {fbs_file}", run_environment=True)
cmake.configure()
cmake.build()

Expand Down

0 comments on commit 215ee43

Please sign in to comment.