Closed
Description
The main reason why I still stick to CMake is its builtin modules which provide compiler detection/package search/etc. It is unnecessary to reinvent the wheels, so I was wondering is it possible to provide (at least kind of) .cmake
support and wrap these modules into xmake
utilities?
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
waruqi commentedon May 10, 2017
xmake also provide these features, so I don't intend to wrap them.
ghost commentedon May 10, 2017
Compiler detection of xmake is perfect
"Package search" is working on the way. You could have a look branch
repo
Thanks for caring 😃
htfy96 commentedon May 10, 2017
Thanks for reply. I'm just a little bit worried that there might be a lot more to do than you think. Take C++ as an example, we may need:
Supporting
.cmake
may reduce some kind of work, I guess.ghost commentedon May 10, 2017
I'd like to have a quick look into it this week
waruqi commentedon May 11, 2017
@htfy96 You can use
option
to detecttypes
,includes
,funcs
,links
,cflags
,ldflags
and etc ..for example:
It will detect
wchat_t
, "setjmp.h",libpthread.a
andsigsetjmp
.The
demo
target will define-DENABLE_TEST
and link-lpthread
if all tests are passedwaruqi commentedon May 11, 2017
And you can add
add_cxflags("-fsanitize=address", "-ftrapv")
directly.If compiler does not support these flags, It will ignore it automatically.
waruqi commentedon May 11, 2017
xmake will detect msvc on windows by default automatically. If you want to use other compiler, you can set it manually. for example:
And it will detect clang, gcc, .. on linux/macos.
htfy96 commentedon May 11, 2017
@waruqi
IIUC, according to your example
xmake
currently has no plan for builtin feature detection based on compiler version, instead, it provides basic utilities likeadd_cxxfuncs
to allow custom detection. The main drawbacks of the absence of builtinhas_variadic_template
/support_cxx_11
include:add_cfuns(sigsetjmp((void*)0, 0)
and requires heavy templates and domain knowledgeActually I'm more willing to see something like
enable_sanitize_address
which adds proper flags for every compiler supporting this feature. Hard-coded/compiler-dependent flags are not encouraged from my perspective, and I want to completely eliminate these in my build scripts.I'm referring to Clang/C2 frontend of MSVC. Take a look into CMake's patch set, and you'll find that checking
_MSC_VER
is not enough.waruqi commentedon May 11, 2017
@htfy96 Yes, xmake currently has no plan for builtin feature detection based on compiler version.
This is only configured and detected once
This is not a problem, the detection rules can be improved more flexibly.
xmake takes the gcc flags as the standard and will map to other compiler flags smartly.
So these flags (
-fsanitize=addres
,-fomit-frame-pointer
) are nothard-coded/compiler-dependent
, you can see #71About
enable_sanitize_address
, why not do the testing directly in the code?htfy96 commentedon May 11, 2017
@waruqi
Thanks for detailed reply. One more question, how can I switch flags based on whether a code snippet can compile without error? For example, I want to detect constexpr support:
This doesn't seem to work. Older compilers do not support
__has_feature
ghost commentedon May 11, 2017
Now for flags adding, xmake uses gcc flags mapping
Advantage:
Disadvantage:
-coverage
is not mapped. And compilers are difficult so some flags cannot be implemented on some compilerI agree with generic flags like what you said as a second choice
ghost commentedon May 11, 2017
A good problem @htfy96
Seems that not supported yet, right? @waruqi
htfy96 commentedon May 11, 2017
And consider this case: user specified
-fsanitize=address
inxmake.lua
, but actually the machine is running an older version of C2 on MSVC(e.g. Clang/C2 in MSVC14 Update 1) which has notsanitize
support. How do you deal with such kind of issue?The initiative of this issue is that compatibility/detection is extremely difficult. Manual checking could be very time-consuming and complicated. It is difficult to implement your own compiler database like
CMake
from scratch as well, since if you want to supportN
compilers, each of which hasK
versions, and you haveP
features to check, the database will soon balloons toN * K * P
. Therefore, the best choice in this case is to adapt existing CMake databases.waruqi commentedon May 11, 2017
@htfy96
add_cxxfuncs
andadd_cfuncs
only used to detect if the function interface exists. I will addadd_cxxsnippets()
to detect other feature support in the future, for example:waruqi commentedon May 11, 2017
If has not sanitize support,
add_cxflags("-fsanitize=addres")
will be ignored automatically when building project38 remaining items