It's Time To Do CMake Right.
https://pabloariasal.github.io/2018/02/19/its-time-to-do-cmake-right/
Suggestions
1. Replace dependency/* with cmake external projects.
One disadvantage of using dependencies as git submodules is that in order to build restbed I must clone it (GIT_REPOSITORY, GIT_TAG)
ExternalProject_Add(external_restbed
PREFIX "${EXTERNAL_PROJECTS_PREFIX}"
GIT_REPOSITORY "https://github.com/Corvusoft/restbed.git"
GIT_TAG "0f8af8d8ed183a88e208adeb22da0080d5d74d1e"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-ssl_INCLUDE_DIR=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}
)
it is slower that downloading the archive of the desired version
ExternalProject_Add(external_restbed
PREFIX "${EXTERNAL_PROJECTS_PREFIX}"
URL "https://github.com/Corvusoft/restbed/archive/0f8af8d8ed183a88e208adeb22da0080d5d74d1e.zip"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-ssl_INCLUDE_DIR=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}
)
this will download the archive with empty dependency/* directories and the build will fail.
2. Make Findopenssl.cmake detect libraries in INSTALL_PREFIX not only in hardcoded paths.
Now I have to trick the script that it found openssl because I build and install openssl as external project
ExternalProject_Add(external_openssl
PREFIX "${EXTERNAL_PROJECTS_PREFIX}"
URL "https://github.com/openssl/openssl/archive/OpenSSL_1_1_0i.tar.gz"
CONFIGURE_COMMAND ../external_openssl/config no-shared no-unit-test no-zlib-dynamic --prefix=${EXTERNAL_PROJECTS_INSTALL_PREFIX}
BUILD_COMMAND make -j ${CPU_COUNT}
INSTALL_COMMAND make install_sw install_ssldirs
)
set_target_properties(external_openssl PROPERTIES EXCLUDE_FROM_ALL TRUE)
add_dependencies(external_all external_openssl)
ExternalProject_Add(external_restbed
PREFIX "${EXTERNAL_PROJECTS_PREFIX}"
GIT_REPOSITORY "https://github.com/arteniioleg/restbed.git"
GIT_TAG "36496715381601a0858ecab8f2735738378e938d"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DBUILD_SSL=ON
-Dssl_INCLUDE=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}
-Dssl_LIBRARY_STATIC=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ssl${CMAKE_STATIC_LIBRARY_SUFFIX}
-Dssl_LIBRARY_SHARED=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ssl${CMAKE_STATIC_LIBRARY_SUFFIX}
-Dcrypto_LIBRARY_STATIC=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}crypto${CMAKE_STATIC_LIBRARY_SUFFIX}
-Dcrypto_LIBRARY_SHARED=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}crypto${CMAKE_STATIC_LIBRARY_SUFFIX}
-DBUILD_TESTS=OFF
)
set_target_properties(external_restbed PROPERTIES EXCLUDE_FROM_ALL TRUE)
add_dependencies(external_restbed external_openssl)
add_dependencies(external_all external_restbed)
Or while we're at it, why not just use CMake's official FindOpenSSL instead of a self-hacked Findopenssl.cmake
#337
This is what I have to do to be able to use latest version as external project.
I download restbed as archive instead of git clone because it's much faster, also git clone does clone all git submodules located in dependecy/ (openssl clone is very slow).
# ... some variable initialization
add_custom_target(external_all)
set_target_properties(external_all PROPERTIES EXCLUDE_FROM_ALL TRUE)
ExternalProject_Add(external_openssl
PREFIX "${EXTERNAL_PROJECTS_PREFIX}"
EXCLUDE_FROM_ALL TRUE
URL "https://github.com/openssl/openssl/archive/OpenSSL_1_1_0i.tar.gz"
CONFIGURE_COMMAND ../external_openssl/config no-shared no-unit-test no-zlib-dynamic --prefix=${EXTERNAL_PROJECTS_INSTALL_PREFIX}
BUILD_COMMAND make -j ${CPU_COUNT}
INSTALL_COMMAND make install_sw install_ssldirs
)
add_dependencies(external_all external_openssl)
ExternalProject_Add(external_restbed
PREFIX "${EXTERNAL_PROJECTS_PREFIX}"
EXCLUDE_FROM_ALL TRUE
DEPENDS external_openssl
URL "https://github.com/Corvusoft/restbed/archive/a1e9c970cf0886ab9e115f776f7d3c5dab52b964.zip"
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${EXTERNAL_PROJECTS_INSTALL_PREFIX}
-DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
-DBUILD_SSL=ON
-Dasio_INCLUDE=${EXTERNAL_PROJECTS_PREFIX}/src/external_restbed/dependency/asio/asio/include
-Dssl_INCLUDE=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}
-Dssl_LIBRARY_STATIC=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ssl${CMAKE_STATIC_LIBRARY_SUFFIX}
-Dssl_LIBRARY_SHARED=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}ssl${CMAKE_STATIC_LIBRARY_SUFFIX}
-Dcrypto_LIBRARY_STATIC=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}crypto${CMAKE_STATIC_LIBRARY_SUFFIX}
-Dcrypto_LIBRARY_SHARED=${EXTERNAL_PROJECTS_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}crypto${CMAKE_STATIC_LIBRARY_SUFFIX}
PATCH_COMMAND echo "Disabling catch" && sed -i s/find_package\(\ catch/\#/ CMakeLists.txt
&& echo "Disabling tests" && sed -i s/add_subdirectory/\#/ CMakeLists.txt
&& echo "Downloading ASIO" && cd dependency
&& wget -q -O asio.tar.gz https://github.com/Corvusoft/asio-dependency/archive/b3d2ab7255fabe46a49b24a584c9fd797c8248e5.tar.gz
&& rm -rf asio && tar -xf asio.tar.gz && mv asio-dependency-b3d2ab7255fabe46a49b24a584c9fd797c8248e5 asio && rm asio.tar.gz
)
add_dependencies(external_all external_restbed)
target_link_libraries(${PROJECT_NAME} PRIVATE ${CMAKE_STATIC_LIBRARY_PREFIX}restbed${CMAKE_STATIC_LIBRARY_SUFFIX})
Is there anyone willing to put a PR together for this?
I was planning to do a modernization of restbed's CMake for inclusion in a project. By now, I think restbed will not be used in that project due to the license.
However I'm still open to do it aside from that project, since I did a lot of CMake modernization in the last few years and restbed looks not too difficult to do.
I already have a prototype, but it still needs a bit of love and discussion about some things. If you want, I could open a PR with that and continue discussing details there.
I also did my own version of CMake modernization here: https://github.com/namazso/restbed along with some changes like switching to boost::asio
however I dropped the dual licensing so this cannot be merged here. it might still be of help to other people wanting to fork restbed though
@namazso you can't simply drop the licensing terms of the product. Please restore the original LICENSE.AGPL and LICENSE.CPL agreements.
@ben-crowhurst yes you can when it is explicitly allowed, which you did, here: https://github.com/Corvusoft/restbed/blob/master/legal/LICENSE.AGPL#L342-L347
@namazso this relates to the AGPL not the terms for commercial entities using the product under the CPL. Please restore the CPL.
I received the software under the AGPL and am using it under the terms of the AGPL, so that is the license that applies to me: The license file explicitly says that you can use the softare under either the terms of the AGPL or the CPL, therefore the other does not apply when you choose one. The AGPL allows dropping any additional permissions, so that is what I did.
I am not using this software in any software not obeying the terms of AGPL. You also cannot retroactively revoke these licensing terms.
Contact your lawyer for any more legal assistance in interpreting the AGPL's terms.
@namazso your action has single-handedly pushed us in the direction of a more closed source and restricted solution for Restbed 5 :clap:
I am sorry you felt entitled to making money from free developers' additions. This is a voluntary thing and I simply did not intend to participate. That's all there is to it, no hard feelings against whatever corvusoft does. Good luck with your future developments.
"I am sorry you felt entitled to making money from free developers' additions..."
I'll just leave this here.

Indeed, low contribution rate is what pretty much everyone experiences. So I don't really see why it is such a big deal that you cannot utilize my additions. Not like they'd be of much use or be significant here either.
I would have had to drop the extra clause anyways because I use other GPL code in my upcoming software, which would be in contradiction with the extra permission clause. If I wasn't able to drop it, I couldn't/wouldn't use this software.
"... I don't really see why it is such a big deal that you cannot utilize my additions. Not like they'd be of much use or be significant here either."
You said this. Never was it stated your contribution would be ignored/rejected/not used.
This is pointless, have a great day and enjoy the code.