8000 Don't set CMAKE_CXX_FLAGS, use target properties instead by danvratil · Pull Request #267 · qcoro/qcoro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't set CMAKE_CXX_FLAGS, use target properties instead #267

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

Merged
merged 2 commits into from
Mar 16, 2025
Merged
Show file tree
Hide file tree
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
27 changes: 0 additions & 27 deletions CMakeLists.txt
8000
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,12 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_AUTOMOC ON)

if (MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 /WX")
# Disable warning C5054: "operator '&': deprecated between enumerations of different types" caused by QtWidgets/qsizepolicy.h
# Disable warning C4127: "conditional expression is constant" caused by QtCore/qiterable.h
if ("${QT_VERSION_MAJOR}" STREQUAL "6" AND "${Qt6_VERSION}" VERSION_GREATER_EQUAL "6.4.0" AND "${Qt6_VERSION}" VERSION_LESS "6.5.3")
# Disable warning C4702: "unreachable code" caused by QtTest/qtestcase.h - fixed in Qt 6.5.3
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /wd5054 /wd4127 /wd4702")
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Explicitly enable exceptions support for clang-cl (it's only enabled by CMake when targeting the Windows-MSVC platform,
# see https://github.com/danvratil/qcoro/issues/90 for details)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
endif()
else()
# Only enable strict warnings in debug mode
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -Wextra -Werror -pedantic -Wno-language-extension-token")

if (ANDROID)
include(DetectAndroidNDKVersion)
detectAndroidNDKVersion(NDK_VERSION)
Expand All @@ -153,22 +142,6 @@ if (QCORO_ENABLE_ASAN)
endif()
endif()

add_compile_definitions(
QT_NO_CAST_FROM_ASCII
QT_NO_CAST_TO_ASCII
QT_NO_URL_CAST_FROM_STRING
QT_NO_CAST_FROM_BYTEARRAY
QT_USE_STRINGBUILDER
QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
QT_NO_KEYWORDS
QT_NO_FOREACH
)
if (NOT WIN32)
# strict iterators on MSVC only work when Qt itself is also built with them,
# which is not usually the case. Otherwise there are linking issues.
add_compile_definitions(QT_STRICT_ITERATORS)
endif()

include(qcoro/QCoroMacros.cmake)
qcoro_enable_coroutines()

Expand Down
42 changes: 42 additions & 0 deletions cmake/AddQCoroLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@ include(GenerateExportHeader)
include(GenerateModuleConfigFile)
include(ECMGeneratePriFile)

function(set_target_defaults target_name)
set(DEFAULT_QT_DEFINITIONS QT_NO_CAST_FROM_ASCII QT_NO_CAST_TO_ASCII QT_NO_URL_CAST_FROM_STRING QT_NO_CAST_FROM_BYTEARRAY QT_USE_STRINGBUILDER QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_KEYWORDS QT_NO_FOREACH)

get_target_property(target_type ${target_name} TYPE)
if (target_type STREQUAL "INTERFACE_LIBRARY")
target_compile_definitions(
${target_name}
INTERFACE
${DEFAULT_QT_DEFINITIONS}
)
return()
endif()

target_compile_definitions(${target_name} PRIVATE ${DEFAULT_QT_DEFINITIONS})

if (NOT WIN32)
# strict iterators on MSVC only work when Qt itself is also built with them,
# which is not usually the case. Otherwise there are linking issues.
target_compile_definitions(${target_name} PRIVATE QT_STRICT_ITERATORS)
endif()

string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lowercase)
if ("${build_type_lowercase}" STREQUAL "debug")
if (MSVC)
target_compile_options(${target_name} PRIVATE /W4 /WX)
# Disable warning C5054: "operator '&': deprecated between enumerations of different types" caused by QtWidgets/qsizepolicy.h
# Disable warning C4127: "conditional expression is constant" caused by QtCore/qiterable.h
target_compile_options(${target_name} PRIVATE /wd5054 /wd4127)
if ("${QT_VERSION_MAJOR}" STREQUAL "6" AND "${Qt6_VERSION}" VERSION_GREATER_EQUAL "6.4.0" AND "${Qt6_VERSION}" VERSION_LESS "6.5.3")
# Disable warning C4702: "unreachable code" caused by QtTest/qtestcase.h - fixed in Qt 6.5.3
target_compile_options(${target_name} PRIVATE /wd4702)
endif()
else()
target_compile_options(${target_name} PRIVATE -Wall -Wextra -Werror -pedantic -Wno-language-extension-token)
endif()
endif()

endfunction()

function(add_qcoro_library)
function(prefix_libraries)
set(oneValueArgs PREFIX OUTPUT)
Expand Down Expand Up @@ -108,6 +147,8 @@ function(add_qcoro_library)
EXPORT_NAME ${LIB_NAME}
)

set_target_defaults(${target_name})

if (NOT LIB_INTERFACE)
set_target_properties(
${target_name}
Expand All @@ -117,6 +158,7 @@ function(add_qcoro_library)
SOVERSION ${qcoro_SOVERSION}
)
target_code_coverage(${target_name} AUTO)

else()
target_code_coverage(${target_name} AUTO INTERFACE)
endif()
Expand Down
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ endif()
add_subdirectory(iodevice)
add_subdirectory(timer)
add_subdirectory(chained)
add_subdirectory(background-task)
add_subdirectory(background-task)

4 changes: 3 additions & 1 deletion examples/background-task/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ target_link_libraries(background-task-example
PRIVATE
QCoro${QT_VERSION_MAJOR}Core
Qt${QT_VERSION_MAJOR}::Core
)
)
set_target_defaults(background-task-example)

3 changes: 3 additions & 0 deletions examples/basics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
add_executable(await-sync-string await-sync-string.cpp)
target_link_libraries(await-sync-string QCoro${QT_VERSION_MAJOR}::Coro)
set_target_defaults(await-sync-string)

add_executable(await-async-string await-async-string.cpp)
target_link_libraries(await-async-string QCoro${QT_VERSION_MAJOR}::Coro Qt${QT_VERSION_MAJOR}::Core)
set_target_defaults(await-async-string)

2 changes: 2 additions & 0 deletions examples/chained/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ target_link_libraries(chained-example
QCoro${QT_VERSION_MAJOR}Core
Qt${QT_VERSION_MAJOR}::Core
)
set_target_defaults(chained-example)

2 changes: 2 additions & 0 deletions examples/dbus/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
add_subdirectory(common)
add_subdirectory(regular-blocking)
add_subdirectory(coroutine)


4 changes: 4 additions & 0 deletions examples/dbus/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ target_link_libraries(dbusserver
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
)
set_target_defaults(dbusserver)

#-----------------------------------------------------#

Expand All @@ -26,3 +27,6 @@ target_link_libraries(examples-dbus-common
PRIVATE
Qt${QT_VERSION_MAJOR}::DBus
)
set_target_defaults(examples-dbus-common)


2 changes: 2 additions & 0 deletions examples/dbus/coroutine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ target_link_libraries(dbustest-coro
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
)
set_target_defaults(dbustest-coro)

2 changes: 2 additions & 0 deletions examples/dbus/regular-blocking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ target_link_libraries(dbustest
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
)
set_target_defaults(dbustest)

2 changes: 2 additions & 0 deletions examples/future/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ target_link_libraries(future-example
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Concurrent
)
set_target_defaults(future-example)

2 changes: 2 additions & 0 deletions examples/iodevice/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ target_link_libraries(iodevice-example
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::Network
)
set_target_defaults(iodevice-example)

3 changes: 3 additions & 0 deletions examples/network/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ target_link_libraries(network-example
Qt${QT_VERSION_MAJOR}::Widgets
Qt${QT_VERSION_MAJOR}::Network
)
set_target_defaults(network-example)


2 changes: 2 additions & 0 deletions examples/timer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ target_link_libraries(timer-example
QCoro${QT_VERSION_MAJOR}Core
Qt${QT_VERSION_MAJOR}::Core
)
set_target_defaults(timer-example)

1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function(qcoro_add_test _name)
${TEST_LINK_LIBRARIES}
Threads::Threads
)
set_target_defaults(test-${_name})
if (NOT TEST_SKIP_ADD_TEST)
add_test(NAME test-${_name} COMMAND test-${_name})
_enable_supressions(${_name})
Expand Down
Loading
0