]> granicus.if.org Git - graphviz/commitdiff
CMake: only pass 'YY_NO_UNISTD_H' to Flex when unistd.h is not found
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 16 Oct 2021 21:19:41 +0000 (14:19 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 19 Oct 2021 23:58:26 +0000 (16:58 -0700)
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

index 212c62f0560b3e511a56d402809376aaac03b110..83b49e3e9feb9c02530d0048667aeeaab97d1a58 100644 (file)
@@ -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