[CMake] OS X Framework testing

E. Wing ewmailing at gmail.com
Wed Dec 28 20:00:31 EST 2005


Okay, I think I hit some problems/corner cases. I'm trying to port my
FindSDL_sound.cmake script. I have a TRY_COMPILE I need to do, and in
preparing the thing to try compile, I get problems.

This is the block of code:

   FILE(WRITE ${PROJECT_BINARY_DIR}/CMakeTmp/CMakeLists.txt
     "PROJECT(DetermineSoundLibs)
        INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR} ${SDL_SOUND_INCLUDE_DIR})
        ADD_EXECUTABLE(DetermineSoundLibs DetermineSoundLibs.c)
        TARGET_LINK_LIBRARIES(DetermineSoundLibs
\"${SDL_SOUND_LIBRARY} ${SDL_LIBRARY}\")"
     )

   TRY_COMPILE(
     MY_RESULT
     ${PROJECT_BINARY_DIR}/CMakeTmp
     ${PROJECT_BINARY_DIR}/CMakeTmp
     DetermineSoundLibs
     OUTPUT_VARIABLE MY_OUTPUT
     )

Currently, my:
 SDL_SOUND_LIBRARIES is  /Library/Frameworks/SDL_sound.framework
 SDL_LIBRARY is /Library/Frameworks/SDL.framework;-framework Cocoa



The problem seems to be in the TARGET_LINK_LIBRARIES. When this piece
runs, the MY_OUTPUT looks like:

 CMakeFiles/DetermineSoundLibs.dir/build.make:90: warning: overriding
commands for target
 `DetermineSoundLibs'
 CMakeFiles/DetermineSoundLibs.dir/build.make:88: warning: ignoring
old commands for target
 `DetermineSoundLibs'
 Scanning dependencies of target DetermineSoundLibs
 CMakeFiles/DetermineSoundLibs.dir/build.make:90: warning: overriding
commands for target
 `DetermineSoundLibs'
 CMakeFiles/DetermineSoundLibs.dir/build.make:88: warning: ignoring
old commands for target
 `DetermineSoundLibs'
 make[2]: *** No rule to make target `/Library/Frameworks/SDL_sound.framework
 /Library/Frameworks/SDL.framework', needed by `DetermineSoundLibs'.  Stop.
 make[1]: *** [CMakeFiles/DetermineSoundLibs.dir/all] Error 2
 make: *** [all] Error 2

I dug into the build.make file and found this:
DetermineSoundLibs: CMakeFiles/DetermineSoundLibs.dir/DetermineSoundLibs.o
DetermineSoundLibs: /Library/Frameworks/SDL_sound.framework\
/Library/Frameworks/SDL.framework;-frame
work\ Cocoa
DetermineSoundLibs: CMakeFiles/DetermineSoundLibs.dir/build.make
        @echo "Linking C executable DetermineSoundLibs"
        $(CMAKE_COMMAND) -E remove -f DetermineSoundLibs
        /usr/bin/gcc    -fPIC $(DetermineSoundLibs_OBJECTS)
$(DetermineSoundLibs_EXTERNAL_OBJECTS)  -
o DetermineSoundLibs  -L/Library/Frameworks/SDL_sound.framework\
/Library/Frameworks/SDL.framework;-framework\ Cocoa
SDL.framework;-framework Cocoa

I looks like it got confused on my SDL_LIBRARY and didn't apply -F/-framework.


I also tried removing the quotes in TARGET_LINK_LIBRARIES which
produced this error instead:
 Scanning dependencies of target DetermineSoundLibs
 Building C object CMakeFiles/DetermineSoundLibs.dir/DetermineSoundLibs.o
 Linking C executable DetermineSoundLibs
 /usr/bin/ld: can't locate framework for: -framework -lCocoa
 collect2: ld returned 1 exit status
 make[2]: *** [DetermineSoundLibs] Error 1
 make[1]: *** [CMakeFiles/DetermineSoundLibs.dir/all] Error 2
 make: *** [all] Error 2


So I think part of the problem is that the the SDL_LIBRARY is a list
with the -framework Cocoa appended on. This was explicitly appended on
to the variable and did not use the FIND_LIBRARY mechansim. This is
kind of direct invocation of -framework is done in some of the
existing Find*.cmake modules.

I'm thinking that TARGET_LINK_LIBRARIES (and probably
INCLUDE_DIRECTORIES) needs to be able to split the string/list and
invoke the correct actions on each piece.

On a semi-related note, I noticed the FindOpenGL.cmake module is
causing me problems now. It seems the FindX11.cmake script it invokes
explicitly sets -lSM -lICE.  OS X has these, but they are located in
/usr/X11/lib, and for whatever reason my OS X doesn't seem to have
those in the default search path so an explicit -L will be needed. It
turns out that the thing that invokes FindX11 in the OpenGL script
should not generally be invoked for OS X, so the problem can be
side-stepped in this case. But both of these should be fixed at some
point. But I'm wondering as a general CMake guideline if direct
invocations of libraries (e.g. -framework Cocoa, -lICE) should
discouraged and removed from the CMake module base.

Thanks,
Eric


More information about the CMake mailing list