[CMake] Problems to use TRY_COMPILE
Bill Hoffman
bill.hoffman at kitware.com
Fri Apr 4 08:13:16 EDT 2008
Vitor Vasconcelos Araujo Silva wrote:
>
> >> TRY_COMPILE(RESULT ${PROJECT_BINARY_DIR}
> >>
> >> ${PROJECT_SOURCE_DIR}/teste.cpp
> >> CMAKE_FLAGS
> >> COMPILE_DEFINITIONS -I${QT_INCLUDE_DIR}
> >> -I${QT_QTCORE_INCLUDE_DIR}
> >> -l${QT_QTCORE_LIBRARY}
> >> OUTPUT_VARIABLE MY_OUT
> >> )
> >>
> > You are missing LINK_LIBRARIES from Qt. I don't see where you are
> > passing a link parameter in??
> >
> > -Bill
>
> And, after the TRY_COMPILE block I finish my CMakeLists defining the
> which libraries I want to link to my application.
>
> TARGET_LINK_LIBRARIES ( ${QT_EXECUTABLE_NAME}
> ${QT_QTCORE_LIBRARY}
> ${QT_QTGUI_LIBRARY}
> )
>
> Thanks in advance,
>
See the docs for try_compile:
http://www.cmake.org/HTML/cmake-2.6.html#command_try_compile
....
Some extra flags that can be included are, INCLUDE_DIRECTORIES,
LINK_DIRECTORIES, and LINK_LIBRARIES. COMPILE_DEFINITIONS are
-Ddefinition that will be passed to the compile line. try_compile
creates a CMakeList.txt file on the fly that 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})
....
You have this:
TRY_COMPILE(RESULT ${PROJECT_BINARY_DIR}
> >>
> >> ${PROJECT_SOURCE_DIR}/teste.cpp
> >> CMAKE_FLAGS
> >> COMPILE_DEFINITIONS -I${QT_INCLUDE_DIR}
> >> -I${QT_QTCORE_INCLUDE_DIR}
> >> -l${QT_QTCORE_LIBRARY}
> >> OUTPUT_VARIABLE MY_OUT
> >> )
You need to add:
LINK_LIBRARIES ${QT_QTCORE_LIBRARY}
${QT_QTGUI_LIBRARY}
To the TRY_COMPILE call that you have.
-Bill
More information about the CMake
mailing list