[CMake] Differentiate between Linux and FreeBSD

Pau Garcia i Quiles pgquiles at elpauer.org
Wed Apr 23 05:28:47 EDT 2008


Quoting Horacio Sanson <hsanson at gmail.com>:

Indeed.

If you place the PROJECT directive at the top of your CMakeLists.txt,  
or remove the PROJECT directive, it works fine. But if you place the  
PROJECT directive where you've put it, it complains.

Given that cmake --help PROJECT does not say anything about placing  
PROJECT at the top of the CMakeList.txt, this is either a bug with the  
CMake docs or a bug in the PROJECT command.

By the way, CMake 2.4.8 packages for Gutsy are available in my PPA:
http://launchpad.net/~pgquiles/+archive

> On Wed, Apr 23, 2008 at 5:39 PM, Pau Garcia i Quiles
> <pgquiles at elpauer.org> wrote:
>> Quoting Horacio Sanson <hsanson at gmail.com>:
>>
>>  Either you have not re-run CMake or your CMake is broken. Did you install
>> it from Ubuntu packages?
>>
>
> I have tried this in two separate systems with the same result:
>
> Hardy Heron (clean installation) with cmake 2.4-patch7 from Ubuntu   
> repositories
> FreeBSD 7.1 with cmake 2.4-patch 7 from FreeBSD ports.
>
> In both cases running cmake causes an error about
> CMAKE_FIND_LIBRARY_PREFIXES missing.
>
> my CMakeLists.txt file :
>
> #########################################
> EXEC_PROGRAM(uname OUTPUT_VARIABLE SYSTEM_NAME)
> SET(SYSTEM_NAME "${SYSTEM_NAME}" CACHE INTERNAL "")
>
> IF(SYSTEM_NAME STREQUAL "Linux")
>   MESSAGE("LINUX BOX")
>   LINK_LIBRARIES(sctp)
> ENDIF(SYSTEM_NAME STREQUAL "Linux")
>
> IF(SYSTEM_NAME STREQUAL "FreeBSD")
>   MESSAGE("FREEBSD BOX")
> ENDIF(SYSTEM_NAME STREQUAL "FreeBSD")
>
> FIND_LIBRARY(SCTP_LIBRARY sctp)
> IF(SCTP_LIBRARY)
>   MESSAGE("GOT SCTP LIBRARY")
> ENDIF(SCTP_LIBRARY)
>
> PROJECT(echo_demo)
> ADD_EXECUTABLE(echo_server echo_server.c)
> ADD_EXECUTABLE(echo_client echo_client.c)
> ##########################################
>
> regards,
> Horacio
>
> Most probably a bug in the Ubuntu package??  Will
>>
>> >
>> >
>> >
>> > On Wed, Apr 23, 2008 at 1:53 PM, Alan W. Irwin
>> > <irwin at beluga.phys.uvic.ca> wrote:
>> >
>> > > On 2008-04-22 21:48-0400 Amitha Perera wrote:
>> > >
>> > >
>> > > > Horacio Sanson wrote:
>> > > >
>> > > > > The problem is that in linux I have to add the sctp library (i.e.
>> > > > > -lsctp) if not compilation fails and in FreeBSD adding that library
>> > > > > would cause the compiler to complain.
>> > > > >
>> > > > > if there is a better way to do this I am eager to learn it.
>> > > > >
>> > > >
>> > > > Not necessarily "better", but if sctp exists on Linux, but not on
>> FreeBSD
>> > > (or more generally, if sctp should be linked against whenever it is
>> found),
>> > > an option is
>> > > >
>> > > > find_library( SCTP_LIBRARY sctp )
>> > > >
>> > > > target_link_libraries( your_exec ${SCTP_LIBRARY} )
>> > > >
>> > >
>> > >  Good idea, but I believe you would also need the following modification
>> to
>> > >  the above logic
>> > >
>> > >
>> > >  find_library( SCTP_LIBRARY sctp )
>> > >  if(SCTP_LIBRARY)
>> > >
>> > >  target_link_libraries( your_exec ${SCTP_LIBRARY} )
>> > >  endif(SCTP_LIBRARY)
>> > >
>> > >
>> > Running this CMake script gives me:
>> >
>> > CMake Error: Error required internal CMake variable not set, cmake may
>> > be not be built correctly.
>> > Missing variable is:
>> > CMAKE_FIND_LIBRARY_PREFIXES
>> >
>> > I have cmake from Kubuntu Hardy Heron installed.
>> >
>> > Horacio
>> >
>> > >  The reason for the extra logic is that if libsctp is not found then
>> > >  SCTP_LIBRARY with be set to "SCTP_LIBRARY-NOTFOUND" which would screw
>> up
>> > > "target_link_libraries" without the "if" protection.
>> > >
>> > >  Alan
>> > >  __________________________
>> > >  Alan W. Irwin
>> > >
>> > >  Astronomical research affiliation with Department of Physics and
>> Astronomy,
>> > >  University of Victoria (astrowww.phys.uvic.ca).
>> > >
>> > >  Programming affiliations with the FreeEOS equation-of-state
>> implementation
>> > >  for stellar interiors (freeeos.sf.net); PLplot scientific plotting
>> software
>> > >  package (plplot.org); the libLASi project (unifont.org/lasi); the Loads
>> of
>> > >  Linux Links project (loll.sf.net); and the Linux Brochure Project
>> > >  (lbproject.sf.net).
>> > >  __________________________
>> > >
>> > >  Linux-powered Science
>> > >  __________________________
>> > >
>> > >
>> >
>> > _______________________________________________
>> > CMake mailing list
>> > CMake at cmake.org
>> > http://www.cmake.org/mailman/listinfo/cmake
>> >
>> >
>>
>>
>>
>>  --
>>  Pau Garcia i Quiles
>>  http://www.elpauer.org
>>  (Due to my workload, I may need 10 days to answer)
>>
>>
>>  _______________________________________________
>>  CMake mailing list
>>  CMake at cmake.org
>>  http://www.cmake.org/mailman/listinfo/cmake
>>
>



-- 
Pau Garcia i Quiles
http://www.elpauer.org
(Due to my workload, I may need 10 days to answer)



More information about the CMake mailing list