Skip to content

Commit

Permalink
(conan-io#15419) flex: Using again official Flex macros
Browse files Browse the repository at this point in the history
* Reverted Conan creating Flex cmake config files

* Removed useless variable

* cross_compiling not working with legacy CMake

* wip

* dummy
  • Loading branch information
franramirez688 authored and StellaSmith committed Feb 2, 2023
1 parent b0807a6 commit fd1fcce
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 37 deletions.
10 changes: 0 additions & 10 deletions recipes/flex/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,12 @@ def package(self):
autotools.install()
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))

fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.libs = ["fl"]
self.cpp_info.system_libs = ["m"]

# generate both modules and config files
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "FLEX")
self.cpp_info.set_property("cmake_target_name", "FLEX::FLEX")
self.cpp_info.set_property("pkg_config_name", "flex")

self.cpp_info.names["cmake_find_package"] = "FLEX"
self.cpp_info.names["cmake_find_package_multi"] = "FLEX"

bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
Expand Down
6 changes: 4 additions & 2 deletions recipes/flex/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(FLEX REQUIRED)
flex_target(flex_scanner basic_nr.l ${PROJECT_BINARY_DIR}/basic_nr.cpp)

add_executable(${PROJECT_NAME} ${PROJECT_BINARY_DIR}/basic_nr.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE FLEX::FLEX)
add_executable(${PROJECT_NAME} basic_nr.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${FLEX_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${FLEX_LIBRARIES})
11 changes: 2 additions & 9 deletions recipes/flex/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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

def requirements(self):
Expand All @@ -36,16 +36,9 @@ def tested_reference_version():
assert_flex_version = "flex {}".format(expected_version)
assert(assert_flex_version in output_str)

def _create_cpp_file(self):
l_file = os.path.join(self.source_folder, "basic_nr.l")
output_file = os.path.join(self.build_folder, "basic_nr.cpp")
self.run(f"flex --outfile={output_file} --c++ {l_file}")
assert os.path.exists(output_file)

def build(self):
# Let's check flex version installed and create the basic_nr.cpp file
# Let's check flex version installed
self._assert_expected_version()
self._create_cpp_file()
cmake = CMake(self)
cmake.configure()
cmake.build()
Expand Down
7 changes: 4 additions & 3 deletions recipes/flex/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)


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

find_package(FLEX REQUIRED)
flex_target(flex_scanner basic_nr.l ${PROJECT_BINARY_DIR}/basic_nr.cpp)

add_executable(${PROJECT_NAME} ${PROJECT_BINARY_DIR}/basic_nr.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE FLEX::FLEX)
add_executable(${PROJECT_NAME} basic_nr.cpp)
target_include_directories(${PROJECT_NAME} PRIVATE ${FLEX_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PRIVATE ${FLEX_LIBRARIES})
21 changes: 8 additions & 13 deletions recipes/flex/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

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

def requirements(self):
Expand All @@ -24,26 +24,21 @@ def tested_reference_version():

output = StringIO()
self.run(f"flex --version", output, run_environment=False)
output_str = str(output.getvalue())
output_str = str(output.getvalue())
self.output.info("Installed version: {}".format(output_str))
expected_version = tested_reference_version()
self.output.info("Expected version: {}".format(expected_version))
assert_flex_version = "flex {}".format(expected_version)
assert(assert_flex_version in output_str)

def _create_cpp_file(self):
l_file = os.path.join(self.source_folder, "basic_nr.l")
output_file = os.path.join(self.build_folder, "basic_nr.cpp")
self.run(f"flex --outfile={output_file} --c++ {l_file}", run_environment=False)
assert os.path.exists(output_file)

def build(self):
# Let's check flex version installed and create the basic_nr.cpp file
# Let's check flex version installed
self._assert_expected_version()
self._create_cpp_file()
cmake = CMake(self)
cmake.configure()
cmake.build()
# FIXME: CMake legacy is not working as expected when cross-compiling
if not tools.cross_building(self, skip_x64_x86=True):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self, skip_x64_x86=True):
Expand Down

0 comments on commit fd1fcce

Please sign in to comment.