[CMake] OS X and getline ?

Michael Jackson mike.jackson at bluequartz.net
Mon Apr 25 09:49:38 EDT 2011


For the CMake side of things you can actually check for the function during the initial cmake checks:

INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
CHECK_FUNCTION_EXISTS(getline  HAS_GETLINE)

This will perform the check and put the result into the variable "HAS_GETLINE". The easiest (but least maintainable way) is to then do:

if (HAS_GETLINE)
  ADD_DEFINITION(-DHAS_GETLINE)
endif()

Then in your source code you do:

#ifdef HAS_GETLINE

#else

#endif

When you get comfortable with that then what you _really_ do is to create a header template file for CMake to fill in. So create a file ProjectConfig.h.in and put this into it.

#cmakedefine HAS_GETLINE @HAS_GETLINE@

Then in your CMakeLists.txt file you would do this:

configure_file ( ProjectConfig.h.in ${PROJECT_BINARY_DIR}/ProjectConfig.h @only immediate)

Then in your source file simply include the generated header file:

#include "ProjectConfig.h"

All of this addresses how to detect the fact that OS X does not have getline. You are responsible for finding a substitution. Maybe this will help:

http://doubletalkin.blogspot.com/2008/08/fgetln-replacement-for-getline-in-bsd.html


___________________________________________________________
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       mike.jackson at bluequartz.net 
BlueQuartz Software               Dayton, Ohio

On Apr 24, 2011, at 8:20 PM, AJ ONeal wrote:

> What's the preferred solution to the OS X getline problem (meaning that it doesn't exist in OS X's libc) when using CMake?
> ("Don't use getline" isn't an option)
> 
> 
> I'd like to have an explanation of the solution and see an example which employs it.
> 
> 
> This is my first time I've tried to compile my Linux code on OS X, so I don't know anything about how to specify the "do this with os xyz and do this with os abc" options.
> 
> AJ ONeal
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list