[CMake] [EXTERNAL]: Policy to forbid linking with non-cmake-targets

Parag Chandra parag at ionicsecurity.com
Mon Dec 12 09:25:35 EST 2016


Not sure if there is a policy for what you want, but I’ve accomplished something similar via a macro that I use to link my libraries. It looks something like this:

macro (LinkOnlyIfLibraryIsTarget linkTarget)
	foreach (nextLibrary ${ARGN})
		if (TARGET ${nextLibrary})
			target_link_libraries (${linkTarget} ${nextLibrary})
		else
			message (FATAL_ERROR "${nextLibrary} was not defined as a CMake target")
		endif ()
	endforeach ()
endmacro()

So instead of calling target_link_libraries() directly, I invoke this macro with similar syntax:

LinkOnlyIfLibraryIsTarget(executableName library1 library2 library3)

Hope this helps.
 

Parag Chandra
Technical Lead, Mobile Team
Mobile: +1.919.824.1410

Ionic Security Inc.
1170 Peachtree St. NE STE 400, Atlanta, GA 30309
 

On 12/12/16, 7:10 AM, "CMake on behalf of Patrick Boettcher" <cmake-bounces at cmake.org on behalf of patrick.boettcher at posteo.de> wrote:

    Hi list,
    
    is there a policy which can be enabled to forbid calling 
    
      target_link_libraries(foo bar)
    
    where bar is _not_ a known cmake target?
    
    Right now, if 'bar' is not a cmake-target cmake tries to link with
    -lbar (on linux). Can I inhibit this behavior in any way?
    
    I'd prefer cmake telling me that this target is unknown rather than
    receiving a link error at the end of the build-process.
    
    Thanks,
    --
    Patrick.
    
    -- 
    
    Powered by www.kitware.com
    
    Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
    
    Kitware offers various services to support the CMake community. For more information on each offering, please visit:
    
    CMake Support: http://cmake.org/cmake/help/support.html
    CMake Consulting: http://cmake.org/cmake/help/consulting.html
    CMake Training Courses: http://cmake.org/cmake/help/training.html
    
    Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
    
    Follow this link to subscribe/unsubscribe:
    http://public.kitware.com/mailman/listinfo/cmake
    



More information about the CMake mailing list