Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

how can i check if directory exist and add a compile definition in cmake

I have this if-statement from a Makefile

ifneq ($(shell test -e /usr/include/linux/signalfd.h && echo 1),)
CFLAGS += -DUSE_SIGNALFD
endif

trying to translate it to cmake but not sure what is the best way. I know that I would have to add a target_compile_definitions(tgtd PRIVATE -DUSE_SIGNALF)

not sure how to work with CHECK_LIBRARY_EXISTS


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just check include file...

include(CheckIncludeFile)
check_include_file("linux/signalfd.h" has_signalfd)
if(has_signalfd)
   target_compile_definitions(tgtd PRIVATE USE_SIGNALF)  # NO -D !
endif()

You may check if file exists with if(EXISTS ..., but note that that does not mean that the file will be available to #include, ex. in case of cross compiling.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...