-
Notifications
You must be signed in to change notification settings - Fork 191
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
right now it's not possible to add boost properly using CPM #501
Comments
Thank you!
|
@US3RN2ME You are welcome. Though, your code won't work for local boost because there it's assumed that all header-only libs are under Boost::boost , not Boost::specific_header-only_lib . That's why there's a lot of mess in my code: I don't know how to properly add |
a problem with the solution found. Assume we have two projects and both use Boost of the same version: One use only one stuff and second another stuff from boost. First project tries CPM...Package( second_project ) . We got a problem : Boost from first project is added, but only what first project needs, and when in second project CPMAddPackage( boost ) happens, it does nothing, because it thinks that the boost is added, but we know that yes, maybe it's added, but only different stuff from it we need. Possible solutions:
|
at first glance I see a problem I cannot solve: IDK how to remove result of add_subdirectory and then add_subdirectory again. After some time googling, I cannot found a solution. I assume, the idea of registering options and merging options and then re-add_subdirectory is not possible because of the bottleneck of cmake itself. If someone can tell me how to do that, I can add modification and write smth that will work using re add_subdirectory or make CMake reconfigure from cmake code with new options. boost-specific solutions: |
for anyone who want to use you need to add an OPTION: CPMAddPackage(
NAME Boost
URL
"https://github.com/boostorg/boost/releases/download/boost-${TRY_BOOST_VERSION}/boost-${TRY_BOOST_VERSION}.tar.xz"
OPTIONS "BOOST_ENABLE_MPI ON"
) Ref: upstream cmake file: https://github.com/boostorg/mpi/blob/347595c77379ac5cbfc6e4474fe315398fef355e/CMakeLists.txt#L63 |
Do you know Why you should NOT use Boost git repo with CPM.cmake It works, but you can't easily install any boost library! See too https://discourse.cmake.org/t/fetchcontent-with-boost/6596 |
@Gerodote Q: Assume we have two projects and both use Boost of the same version: One use only one stuff and second another stuff from boost. This is no Problem, because every library linked is build from boost: cmake_minimum_required(VERSION 3.14...3.28 FATAL_ERROR)
project(CPMExampleBoost)
# ---- Create binary ----
add_executable(CPMExampleBoost main.cpp)
target_compile_features(CPMExampleBoost PRIVATE cxx_std_17)
# ---- Dependencies ----
include(../../cmake/CPM.cmake)
include(FetchContent)
option(BUILD_SHARED_LIBS "yes/no" YES)
CPMAddPackage(
NAME Boost
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
URL_MD5 893b5203b862eb9bbd08553e24ff146a
EXCLUDE_FROM_ALL ON
SYSTEM ON
)
add_library(scoped_lock scoped_lock.cpp scoped_lock.hpp)
target_link_libraries(scoped_lock PUBLIC Boost::core)
install(FILES scoped_lock.hpp TYPE INCLUDE)
install(TARGETS scoped_lock boost_core)
target_link_libraries(CPMExampleBoost PRIVATE Boost::asio)
install(TARGETS CPMExampleBoost boost_asio)
set(CPACK_GENERATOR TBZ2)
include(CPack) The real problem is that no headers and not all libs are installed without a warning from cmake!
|
P.S.: it is possible to build project with |
Is this the same issue? # Download CPM.cmake
file(
DOWNLOAD https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.38.3/CPM.cmake ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
EXPECTED_HASH SHA256=cc155ce02e7945e7b8967ddfaff0b050e958a723ef7aad3766d368940cb15494
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
# Boost libraries
CPMAddPackage(
NAME Boost
VERSION 1.84.0
URL https://github.com/boostorg/boost/releases/download/boost-1.84.0/boost-1.84.0.tar.xz
URL_HASH SHA256=2e64e5d79a738d0fa6fb546c6e5c2bd28f88d268a2a080546f74e5ff98f29d0e
OPTIONS
"BOOST_ENABLE_CMAKE ON"
# This doesn't work: boost thinks this is one library called "system container".
"BOOST_INCLUDE_LIBRARIES system container"
) And the relevant output from cmake:
Or should I check for/write a new issue? |
No, it is an CPM.cmake Interface Problem "BOOST_INCLUDE_LIBRARIES system\;container" it must be a quotend list!But you don't need to set this options |
I don't need to set this option, but I want to! The following line works for me:
Multiple escapes are required. This is the ONLY thing that worked for me, but it works well. CPM does a nice job. :-) I wrote #531 to add multiple escapes to the boost example. |
I've done next to understand is it possible to make an option in cmake and have installable boost and not rewrite their cmake script:
So, please check if this actually works. Here's the repo with working example: link to my repo with working example The CMake script:
The patch:
|
You build an excecutable and linked it against the shared boost libs, right? |
It seems I've built a lib with static boost libs. I don't get now how to use packageProject with executable ( why it should be ? ) |
With shared libs you get errors like this: CMake Error: install(EXPORT "tftpdTargets" ...) includes target "boost_asio" which requires target "boost_align" that is not in any export set. To test installed version: cd test; cmake -D TEST_INSTALLED_VESION=1 .... |
not gonna lie, but the solution that closes the issue, still has the problem with installing smth with boost. I mean there's no shared libs, if BUILD_SHARED_LIBS=ON was given to boost. Currently, I have no idea how to solve by not rewriting current boost's cmake. We need further investigation in this. even more, the shared libs in installed stuff links to nowhere, so Though building something with boost worked correctly, and with proposed "solution" works too. without patching boost's cmake it's impossible to use TheLartians's packageProject script because of inexistence |
Maybe I can find some time to look at this next week. It would be nice if this was simple. |
@Gerodote I think what you may want to do in YOUR project is to install the Boost libraries YOU depend on. See here for a very basic example. Modifying Boost's CMake files to install only the libraries that you need seems like too much work, and I can't imagine the Boost maintainers would take that pull request seriously (but maybe?). They are already overworked as it is. If your project depends on multiple sub-projects that also depend on Boost, I think this works fine as long as you analyze what they use and make sure your CPM tells boost what to build. But there is always a possibility you will need to add patches to them. If your project is complicated is very probable. (You will, of course, want to provide these patches back to the maintainers if it makes sense.) |
I just don't understand one stuff: I see at cmake debugger that cmake goes through boost's script and "does" BUT NOTHING installs. And yeah, your idea to rewrite install script is good actually, but I genuinly have no idea why this happens. Also, I made a patch that correctly (including all dependencies) install Here's semi-working repo you can test it all by |
oh I got it boost puts its install rules not to How I got this:
Now we just need to figure out why this happens |
Check out magic_enum. I don't have a public project, but I was able to install magic_enum's files when I added it to a private as follows: CPMAddPackage(
NAME magic_enum
URL https://github.com/Neargye/magic_enum/archive/refs/tags/v0.9.5.tar.gz
URL_HASH SHA256=44ad80db5a72f5047e01d90e18315751d9ac90c0ab42cbea7a6f9ec66a4cd679
SYSTEM True
OPTIONS
MAGIC_ENUM_OPT_INSTALL True
) It's only the header files, but it works in the way you want. Plus it's just a cool library. :-) In boost, maybe the function to look at is |
I guess the problem was that somehow Right now it works ! The example at https://github.com/Gerodote/ModernCppStarterExampleBoostCmake Generally speaking, it requires one patch to boost's cmake:
and such lines:
@ClausKlein Can you check it please? I guess it now works. I checked it with "new environment" like a docker with a linux without boost. |
On the first view, it works But you install an partial and unusable boost library!
cmake -S test -B build-x86_64-Debug/test -G Ninja -D CMAKE_CXX_COMPILER_LAUNCHER=/usr/local/bin/ccache -D CMAKE_BUILD_TYPE=Debug -D CMAKE_PREFIX_PATH=/Users/clausklein/Workspace/cpp/stagedir -D BUILD_TESTING=YES -D BUILD_SHARED_LIBS=YES -D CMAKE_UNITY_BUILD=NO -D FMT_MODULE=NO -D CMAKE_CXX_STANDARD=23 -D TEST_INSTALLED_VERSION=1 -D CPM_USE_LOCAL_PACKAGES=YES
-- The CXX compiler identification is AppleClang 15.0.0.15000309
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/usr/bin/g++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- CPM: Using local package [email protected]
-- Found Git: /usr/local/bin/git (found version "2.44.0")
-- Found Python: /usr/local/Frameworks/Python.framework/Versions/3.12/bin/python3.12 (found version "3.12.2") found components: Interpreter
-- CPM: Adding package [email protected] (v1.7.3 at /Users/clausklein/.cache/CPM/format.cmake/17e103764947115e78d95ecc29c4bee54dc64e08)
-- Found Boost: /Users/clausklein/Workspace/cpp/stagedir/lib/cmake/Boost-1.84.0/BoostConfig.cmake (found suitable version "1.84.0", minimum required is "1.84.0")
CMake Error at CMakeLists.txt:22 (find_package):
Found package configuration file:
/Users/clausklein/Workspace/cpp/stagedir/lib/cmake/Greeter/GreeterConfig.cmake
but it set Greeter_FOUND to FALSE so package "Greeter" is considered to be
NOT FOUND. Reason given by package:
The following imported targets are referenced, but are missing: Boost::asio
Boost::thread
-- Configuring incomplete, errors occurred!
bash-5.2$ ``` |
I thought the idea is to install only needed boost libraries, Boost::boost and Boost::header, I guess, shouldn't exist. Aren't those targets exist only for full boost installed versions? Or you guess we should get install all header-only libs and some not header-only libs and get it installed as usually boost is with b2 ? I'm more concerned that it haven't found Boost::asio and Boost::thread. I should test more about that. |
it seems boost 1.85.0 from releases on github with suffix cmake is solved all of the problems. Showing an example how to use cmaked version. set(TRY_BOOST_VERSION "1.85.0")
set(BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED "thread")
set(BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED "asio")
set(BOOST_INCLUDE_LIBRARIES
"${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED};${BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED}"
)
# url for 1.85.0 + only
set(BOOST_URL
"https://github.com/boostorg/boost/releases/download/boost-${TRY_BOOST_VERSION}/boost-${TRY_BOOST_VERSION}-cmake.tar.xz"
)
CPMAddPackage(
NAME Boost
URL ${BOOST_URL}
OPTIONS "BOOST_SKIP_INSTALL_RULES OFF"
)
foreach(a_lib ${BOOST_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED})
target_link_libraries(${PROJECT_NAME} PUBLIC boost_${a_lib})
endforeach()
foreach(a_lib ${BOOST_NOT_HEADER_ONLY_COMPONENTS_THAT_YOU_NEED})
target_link_libraries(${PROJECT_NAME} PUBLIC Boost::${a_lib})
endforeach()
|
I was disappointed when I saw a not working example with boost. I also was disappointed by the idea of using boost-cmake .
After sometime reading CMake code of boost I finally got it. it was ridiculous to find out that CPM...package() cannot add "option" with multiple values.
Then, It was interesting to find, that boost cmake code is actually good.
here's the working example: ( look at last messages at the issue to see maybe more updated script )
The text was updated successfully, but these errors were encountered: