[CMake] Figuring out dependencies for a library in order to build

William A. Hoffman billlist at nycap.rr.com
Tue Jul 19 10:24:43 EDT 2005


>
>I'm having trouble getting this to work. Can you clarify:
>INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and LINK_LIBRARIES, are they
>additional parameters to TRY_COMPILE, or does TRY_COMPILE respect
>these values set elsewhere? (Either way, I can't get it to work.)





INCLUDE_DIRECTORIES, LINK_DIRECTORIES, and LINK_LIBRARIES are variables that
can be set in the CMAKE_FLAGS section.   TRY_COMPILE creates a CMakeList.txt
file on the fly, and in that file it looks like this:  

ADD_DEFINITIONS( <expanded COMPILE_DEFINITIONS from calling cmake>
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES})
LINK_DIRECTORIES(${LINK_DIRECTORIES})
ADD_EXECUTABLE(cmTryCompileExec sources)
TARGET_LINK_LIBRARIES(cmTryCompileExec ${LINK_LIBRARIES})

So, you want something like this:

TRY_COMPILE( 
        MY_RESULT
        ${CMAKE_BINARY_DIR}
        ${PROJECT_SOURCE_DIR}/test_sdlsound.c
        COMPILE_DEFINITIONS "-I/Library/Frameworks/SDL.framework/Headers"
"-I/Library/Frameworks/SDL_sound.framework/Headers" "-framework
SDL.framework" "-framework SDL_sound"
       CMAKE_FLAGS -DINCLUDE_DIRECTORIES:STRING=...
                   -DLINK_DIRECTORIES:STRING=...
                   -DLINK_LIBRARIES:STRING=...
        OUTPUT_VARIABLE MY_OUTPUT
)


To help in debugging things if you run cmake --debug-trycompile it will leave
the temporary files in CMakeTmp.  Also CMakeError.log and CMakeOutput.log are
good places to look at what is going on.


-Bill



More information about the CMake mailing list