Skip to content

Conversation

@ClausKlein
Copy link

@ClausKlein ClausKlein commented Aug 18, 2019

this fix #128

I added a .clang-tidy file too. It can be used with cmake while compiling
or as post compile check.

The default compile options are: clang++ -std=c++17 -Wpedantic -Werror

My last compile log is included, see build-with-clang-tidy.log

see too:
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines
https://www.kdab.com/clang-tidy-part-1-modernize-source-code-using-c11c14/
https://clang.llvm.org/extra/clang-tidy/index.html

ClausKlein and others added 30 commits April 2, 2018 19:56
The coanan package is created with cmake and tested with ctest
The coanan package is created with cmake and tested with ctest
100% tests passed, 0 tests failed out of 124

Total Test time (real) =  60.04 sec
With boost, we can't be pedantic!
prepare .clang-format config fille too
be pedantic by default
fix compile error with socks4 demo;
tidy the example CMakeLists.txt;
tidy the invocation demo too;
modernize cmake for ccache usage for project asio
install asio libray too and export it interface
too change default option: disable handler tracking
The coanan package is created with cmake and tested with ctest
100% tests passed, 0 tests failed out of 124

Total Test time (real) =  60.04 sec
With boost, we can't be pedantic!
prepare .clang-format config fille too
be pedantic by default
modernize cmake for ccache usage for project asio
fix compile error with socks4 demo;
tidy the example CMakeLists.txt;
tidy the invocation demo too;
install asio libray too and export it interface
too change default option: disable handler tracking
update revision version to 1.14.1
add new cpp17/coroutine example to cmake build
@@ -0,0 +1,240 @@
# Minimum supported CMake version
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)

Choose a reason for hiding this comment

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

FATAL_ERROR has been a no-op for the longest time. Please read the docs:
https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html

Copy link
Author

Choose a reason for hiding this comment

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

I will change it to 3.13...3.20

# ==========================================================

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS) # this set CONAN_TARGETS

Choose a reason for hiding this comment

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

Use the cmake_find_package* generators. This is intrusive and has no place in the project CML.

message(STATUS "use ccache")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" CACHE PATH "ccache" FORCE)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" CACHE PATH "ccache" FORCE)
endif()

Choose a reason for hiding this comment

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

Put this in a superbuild CML, not the project CML. ALternatively, just let people decide whether they want to pass this in from the CLI.

Copy link
Author

Choose a reason for hiding this comment

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

why waste time with compiling?

endif()
else()
unset(COMPILER_WARNINGS_ARE_ERRORS CACHE)
endif()

Choose a reason for hiding this comment

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

This has nothing to do in the project CML. Warnings are not a build nor a usage requirement. These should go in the test CML.

#
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)

Choose a reason for hiding this comment

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

Why are you forcing a build folder layout? This isn't portable.

Copy link
Author

Choose a reason for hiding this comment

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

this is absolute portable, it is the build tree, not the DESTDIR



set(CPPdefinitions)
set(EXTRA_LIBS)

Choose a reason for hiding this comment

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

Everything related to these variables should just go in the respective target_* commands, but wrapped in generator expressions.

#######################################################################
# use openssl if found
set(OPENSSL_ROOT_DIR "/usr" CACHE PATH "path to the openssl lib")
find_package(OpenSSL HINTS ${OPENSSL_ROOT_DIR} /opt/local)

Choose a reason for hiding this comment

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

Why the hint? You are also missing REQUIRED here.

Copy link
Author

Choose a reason for hiding this comment

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

NO, it is optional!
The HINT was for MACOSX with MacPorts

list(APPEND EXTRA_LIBS ${openSSL_LIBRARIES})
message(STATUS "HAVE_OPENSSL")
list(APPEND CPPdefinitions HAVE_OPENSSL)
include_directories(BEFORE ${openSSL_INCLUDE_DIR})

Choose a reason for hiding this comment

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

See above. Just use targets.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, this patch is very old.
I will modernise it!

On the other side, yeas passed without a review. What happens now?

if(CONAN_LIBS_OPENSSL)
list(APPEND CPPdefinitions HAVE_OPENSSL)
message(STATUS "have CONAN_LIBS_OPENSSL")
endif()

Choose a reason for hiding this comment

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

This is just unnecessary noise. The user already knows what's on his system. Why tell him?

set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/asio)

# Interface library
add_subdirectory(include)

Choose a reason for hiding this comment

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

Nitpick, but it's completely unnecessary to break things out like this. I shouldn't have to dive through a bunch of files just to see all the usage and build requirements.


if(ASIO_BUILD_EXAMPLES OR ASIO_BUILD_TESTS)
# enable ctest
enable_testing()

Choose a reason for hiding this comment

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

This is bad, create a separate project CML for tests.

DESTINATION ${ConfigPackageLocation})
install(EXPORT asio-targets
DESTINATION ${ConfigPackageLocation}
NAMESPACE asio::)

Choose a reason for hiding this comment

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

There are many things wrong with these install rules:

  • Drop configure_package_config_file, you just need a simple config file that you install directly.
  • You are missing install components. If a user vendors the library then it becomes impossible to tell this library's files apart from his. Since this is a header only library, everything can go in the asio_Development install component.
  • Where is the include directory installed?

And some nitpicks:

  • write_basic_package_version_file will pick up the version from the project command and the default output location of the file is already in the current build directory, they just add noise here.
  • ConfigPackageLocation should be asio_INSTALL_CMAKEDIR, which is a string cache variable marked as advanced. Makes it trivial to relocate the config files for package managers like vcpkg.

check_required_components(asio)

include(CMakeFindDependencyMacro)
find_dependency(OpenSSL QUIET)

Choose a reason for hiding this comment

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

This is wrong, you must find dependencies before you make the targets available. The purpose of find_dependency is to forward arguments from the calling find_package command as well. This file should just be:

include(CMakeFindDependencyMacro)
find_dependency(OpenSSL)

include("${CMAKE_CURRENT_LIST_DIR}/asioTargets.cmake")

See my other comment about htis file not requiring configuration.

add_subdirectory(cpp03)
else()
message(WARNING "examples/cpp03 needs boost!")
endif()

Choose a reason for hiding this comment

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

This check is unnecessary. Just include the find_package(Boost REQUIRED) call in the cpp03 subproject. If boost is really needed, then the absence of boost is a hard error, not a warning.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe, but asI said cpp03 is historic!

@@ -0,0 +1,152 @@
set(target_prefix asio_cpp03_)

Choose a reason for hiding this comment

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

This file is not a proper CML, it's missing cmake_minimum_required and project calls.

add_executable(${target_prefix}${target} ${${target}_SOURCES})
set_target_properties(${target_prefix}${target} PROPERTIES CXX_STANDARD 98
#FIXME CXX_STANDARD 03
#cmake error: CXX_STANDARD is set to invalid value '03'

Choose a reason for hiding this comment

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

Just use compile features.

Copy link
Author

Choose a reason for hiding this comment

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

yes

#include <asio/ip/udp.hpp>
#include <asio/signal_set.hpp>
#include <array>
#include <cstring> // strerror used

Choose a reason for hiding this comment

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

This PR is about adding CMake. This doesn't look like a CMake related change to me.

Copy link
Author

Choose a reason for hiding this comment

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

There was a time in history, it doesn't compile without this!

@@ -0,0 +1,43 @@
set(target_prefix asio_cpp14_)

Choose a reason for hiding this comment

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

See cpp03. This is not a proper CML.

@@ -0,0 +1,33 @@
set(target_prefix asio_cpp17_)

Choose a reason for hiding this comment

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

See cpp03. This is not a proper CML.

@@ -0,0 +1,160 @@
set(target_prefix asio_unit_)

Choose a reason for hiding this comment

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

See cpp03. This is not a proper CML.

@@ -0,0 +1,160 @@
set(target_prefix asio_unit_)

add_library(asio::standalone ALIAS standalone)

Choose a reason for hiding this comment

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

Why is this aliased here? This should be in the library's project CML, not deeply nested in an incomplete test CML.

@@ -0,0 +1,70 @@
from conans import ConanFile, CMake, tools

Choose a reason for hiding this comment

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

I am not sure about how conan works exactly, but I'm pretty sure this file should be on the CCI instead.


# NOTE: If header only is used, there is no need for a custom
# package_info() method!
def package_info(self):

Choose a reason for hiding this comment

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

This is not enough to provide the necessary info for cmake_find_package* generators.

Copy link
Author

Choose a reason for hiding this comment

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

Again, yeas ago, conan project started to support boost, I supported asio

Copy link

@friendlyanon friendlyanon left a comment

Choose a reason for hiding this comment

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

I have reviewed this PR and there are many things that must be improved.

If you want to learn and see how things should be done in CMake, then please take a look at my recent GitHub forks and PRs.

@ClausKlein
Copy link
Author

I have reviewed this PR and there are many things that must be improved.

If you want to learn and see how things should be done in CMake, then please take a look at my recent GitHub forks and PRs.

If you have time and interest, you may provide a patch for this patch.

Or better, create a new one, simply and clean, use only modern cmake!

And it must work on all OS and with most modern compilers.
c++17 and c++20 only, forget the remaining, forward to future!

And please, merge it than.

@ClausKlein ClausKlein marked this pull request as draft February 27, 2021 20:08
@ClausKlein
Copy link
Author

@ClausKlein ClausKlein closed this Mar 5, 2021
@ClausKlein
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants