From 5358ba56ed67f689d9e110370033e17455269c13 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 16 Oct 2021 14:19:41 -0700 Subject: [PATCH] CMake: only pass 'YY_NO_UNISTD_H' to Flex when unistd.h is not found This macro tells Flex that #including unistd.h should be avoided. There is no need for this on almost any platform except Windows, hence why `YY_NO_UNISTD_H` is only mentioned elsewhere in the MS Build build system, not in the Autotools build system. In the CMake build system which is meant to be used across Windows and non-Windows platforms, we can do something more nuanced and depend on the existence check of unistd.h itself. --- lib/cgraph/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/cgraph/CMakeLists.txt b/lib/cgraph/CMakeLists.txt index 212c62f05..83b49e3e9 100644 --- a/lib/cgraph/CMakeLists.txt +++ b/lib/cgraph/CMakeLists.txt @@ -2,7 +2,10 @@ BISON_TARGET(Grammar ${CMAKE_CURRENT_SOURCE_DIR}/grammar.y ${CMAKE_CURRENT_BINAR FLEX_TARGET(Scan ${CMAKE_CURRENT_SOURCE_DIR}/scan.l ${CMAKE_CURRENT_BINARY_DIR}/scan.c) ADD_FLEX_BISON_DEPENDENCY(Scan Grammar) -add_definitions(-DEXPORT_CGRAPH -DEXPORT_AGXBUF -DEXPORT_CGHDR -DYY_NO_UNISTD_H) +add_definitions(-DEXPORT_CGRAPH -DEXPORT_AGXBUF -DEXPORT_CGHDR) +if(NOT HAVE_UNISTD_H) + add_definitions(-DYY_NO_UNISTD_H) +endif() add_library(cgraph SHARED # Header files -- 2.40.0