-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Feature/add cmake #420
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
Feature/add cmake #420
Conversation
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
…into feature/add_cmake
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) | |||
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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::) |
There was a problem hiding this comment.
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_Developmentinstall component. - Where is the include directory installed?
And some nitpicks:
write_basic_package_version_filewill pick up the version from theprojectcommand and the default output location of the file is already in the current build directory, they just add noise here.ConfigPackageLocationshould beasio_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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_) | |||
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use compile features.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_) | |||
There was a problem hiding this comment.
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_) | |||
There was a problem hiding this comment.
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_) | |||
There was a problem hiding this comment.
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) | |||
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this 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.
If you have time and interest, you may provide a patch for this patch. Or better, create a new one, And it must work on all OS and with most modern compilers. And please, merge it than. |
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