Skip to content

Commit

Permalink
Try to use Homebrew's Bison and Flex in macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
MasWag committed Jun 8, 2021
1 parent fd1556b commit 2a18c0d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,35 @@ else()
MONAA_VERSION="${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
endif()

find_package(BISON REQUIRED)
# Mostly taken from the following but
# https://stackoverflow.com/questions/53877344/cannot-configure-cmake-to-look-for-homebrew-installed-version-of-bison
# On macOS, search Homebrew for keg-only versions of Bison and Flex. Xcode does
# not provide new enough versions for us to use.
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
execute_process(
COMMAND brew --prefix bison
RESULT_VARIABLE BREW_BISON
OUTPUT_VARIABLE BREW_BISON_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
set(CMAKE_FIND_ROOT_PATH "${BREW_BISON_PREFIX};${CMAKE_FIND_ROOT_PATH}")
endif()

execute_process(
COMMAND brew --prefix flex
RESULT_VARIABLE BREW_FLEX
OUTPUT_VARIABLE BREW_FLEX_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_FLEX EQUAL 0 AND EXISTS "${BREW_FLEX_PREFIX}")
message(STATUS "Found Flex keg installed by Homebrew at ${BREW_FLEX_PREFIX}")
set(CMAKE_FIND_ROOT_PATH "${BREW_FLEX_PREFIX};${CMAKE_FIND_ROOT_PATH}")
endif()
endif()

find_package(BISON 3.0 REQUIRED)
find_package(FLEX REQUIRED)
find_package(Boost REQUIRED COMPONENTS
program_options unit_test_framework iostreams graph)
Expand All @@ -27,6 +55,8 @@ find_package(Eigen3 REQUIRED)
include_directories(
monaa/
libmonaa/
${BISON_INCLUDE_DIRS}
${FLEX_INCLUDE_DIRS}
${PROJECT_BINARY_DIR}
${Boost_INCLUDE_DIRS}
${EIGEN3_INCLUDE_DIRS})
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ MONAA is tested on Arch Linux, Ubuntu (18.04 and 20.04), and macOS 10.15 Catalin
* Boost (>= 1.59)
* Eigen
* CMake
* Bison
* Bison (>= 3.0)
* Flex

### Instructions
Expand Down

0 comments on commit 2a18c0d

Please sign in to comment.