MantisBT - CMake
View Issue Details
0015358CMakeCMakepublic2015-01-18 14:092015-09-29 09:13
Alexey Chernov 
Brad King 
normaltextalways
closedfixed 
CMake 3.1 
CMake 3.2 
0015358: Clarify try_compile and try_run documentation
try_compile command apparently ignores INCLUDE_DIRECTORIES argument for unknown reason. As documentation (http://www.cmake.org/cmake/help/v3.1/command/try_compile.html [^]) reads:
"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." But unfortunately parameter of INCLUDE_DIRECTORIES argument won't be transferred to CMakeLists.txt.

It also be true for other arguments mentioned in that paragraph.
1. Write try_compile() command with INCLUDE_DIRECTORIES, e.g.:
try_compile(
    COMPILE_RESULT
    ${CMAKE_BINARY_DIR}
    test.cpp
    INCLUDE_DIRECTORIES ${CMAKE_SOURCE_DIR}/include
    OUTPUT_VARIABLE COMPILE_LOG
)
2. Notice that INCLUDE_DIRECTORIES parameter isn't transferred neither to temporary CMakeLists.txt in CMakeFiles/CMakeTmp (with --debug-trycompile enabled) nor to compiler command line arguments.
No tags attached.
Issue History
2015-01-18 14:09Alexey ChernovNew Issue
2015-01-19 10:14Brad KingNote Added: 0037736
2015-01-19 10:25Alexey ChernovNote Added: 0037738
2015-01-19 10:28Brad KingNote Added: 0037739
2015-01-19 10:33Alexey ChernovNote Added: 0037740
2015-02-04 16:08Brad KingNote Added: 0037916
2015-02-04 16:09Brad KingAssigned To => Brad King
2015-02-04 16:09Brad KingSeveritymajor => text
2015-02-04 16:09Brad KingStatusnew => resolved
2015-02-04 16:09Brad KingResolutionopen => fixed
2015-02-04 16:09Brad KingFixed in Version => CMake 3.2
2015-02-04 16:09Brad KingSummarytry_compile ignores INCLUDE_DIRECTORIES argument => Clarify try_compile and try_run documentation
2015-07-08 08:57Robert MaynardNote Added: 0039037
2015-07-08 08:57Robert MaynardStatusresolved => closed

Notes
(0037736)
Brad King   
2015-01-19 10:14   
There is no such INCLUDE_DIRECTORIES option listed in the signature. The "extra flags" is referring to the CMAKE_FLAGS argument, to which you can give "-DINCLUDE_DIRECTORIES=/dir/a/include;/dir/b/include" to get custom include directories.

The documentation needs to be revised and clarified.
(0037738)
Alexey Chernov   
2015-01-19 10:25   
Thanks for clarification of this.
So, is it right that all these three options (INCLUDE_DIRECTORIES, LINK_DIRECTORIES and LINK_LIBRARIES) are meant to be used with CMAKE_FLAGS, but LINK_LIBRARIES can be also used separately as try_compile() argument?

Generally yes, I agree that it's apparently documentation issue and not a bug.
(0037739)
Brad King   
2015-01-19 10:28   
Re 0015358:0037738: Originally all three of those were meant only for use with -D but then the LINK_LIBRARIES option was added as an explicit argument in order to cleanly perform translation of imported targets. If LINK_LIBRARIES is an argument then it no longer works as a -D flag. The documentation is out of date on that I think.
(0037740)
Alexey Chernov   
2015-01-19 10:33   
Thanks again for detailed information. Now it's completely clear for me.
(0037916)
Brad King   
2015-02-04 16:08   
I've revised the documentation:

 Help: Revise try_compile and try_run documentation
 http://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=219797e4 [^]
(0039037)
Robert Maynard   
2015-07-08 08:57   
Closing resolved issues that have not been updated in more than 4 months.