Skip to content

Fix Compiling with Clang for CMake #1272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,35 @@ endif()
# Only useful if building in-tree, versus using it from an installation.
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

# Might be missing some, but this list is somewhat comprehensive
target_compile_features(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
cxx_std_11
cxx_nullptr
cxx_lambdas
cxx_override
cxx_defaulted_functions
cxx_attribute_deprecated
cxx_auto_type
cxx_decltype
cxx_deleted_functions
cxx_range_for
cxx_sizeof_member
)
# Determines the C++ compiler executable name
macro (DETERMINE_CXX_COMPILER_EXECUTABLE_NAME out_Name)
set(_outStr )
string(REGEX MATCH "[^/\\]*$" _outStr ${CMAKE_CXX_COMPILER})
string(REGEX MATCH "[^\.]+" _outStr ${_outStr})
set(${out_Name} ${_outStr})
endmacro()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Can't you just do

if (NOT CMAKE_CXX_COMPILER MATCHES "clang_regex")
    target_compile_features(...)
endif()


# Determine the name of the C++ compiler executable
set(_CXX_EXECUTABLE_NAME )
DETERMINE_CXX_COMPILER_EXECUTABLE_NAME(_CXX_EXECUTABLE_NAME)

# Do not define the target compile features if using clang as clang doesn't provide them.
if (NOT _CXX_EXECUTABLE_NAME MATCHES "clang")
# Might be missing some, but this list is somewhat comprehensive
target_compile_features(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
cxx_std_11
cxx_nullptr
cxx_lambdas
cxx_override
cxx_defaulted_functions
cxx_attribute_deprecated
cxx_auto_type
cxx_decltype
cxx_deleted_functions
cxx_range_for
cxx_sizeof_member
)
Comment on lines +205 to +217
Copy link
Contributor

@Tachi107 Tachi107 May 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway I don't see why using target_compile_features() with the low-level compile features is needed; why isn't cxx_std_11 enough? And disabling the call when using Clang would introduce new issues, because CMake wouldn't know that C++11 is required.

In my opinion the low level compile features should be simply dropped. Even CMake's documentation recommends against their use: https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#low-level-individual-compile-features

cc @sum01

endif()

target_include_directories(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC}
$<BUILD_INTERFACE:${_httplib_build_includedir}>
Expand Down