Open pmatalon opened 2 months ago
If you want to change the default config values of a sub project set the options before call FetchContent_MakeAvailable() or
find_package()`! i.e.:
include(FetchContent)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/glfw-src"
GIT_TAG "master"
GIT_SHALLOW TRUE
)
set(GLFW_BUILD_WAYLAND ON)
set(GLFW_BUILD_X11 OFF)
FetchContent_MakeAvailable(glfw)
or
option(USE_BOOST "build with BOOST support" ON)
if(USE_BOOST)
option(Boost_DEBUG "find boost at verbose mode" OFF)
option(Boost_USE_STATIC_LIBS "use static libs only" OFF)
option(Boost_USE_MULTITHREADED "use -mt libs only" ON)
find_package(Boost 1.71 CONFIG REQUIRED COMPONENTS atomic chrono filesystem thread unit_test_framework)
if(Boost_FOUND)
add_definitions(-DBOOST_ALL_NO_LIB)
include_directories(include)
endif()
endif()
Thank you for your quick answer. I'll try to clarify my question.
The options are in my library project, which uses package_options
for the packaging. I configured the CMakeLists.txt so that If an option is activated, other dependencies are included, compilation options are defined, etc. Now, in a caller project, I want to be able to set those options in my library, thus triggering the linking of other dependencies, compile options for my library, etc. Unfortunately, it seems that my library's options are not exported, so the caller project cannot set them. When I use the ccmake
command on the caller project, I can see all available options: the options of all dependencies are present, except those of my library.
What do you mean with package_options
?
They are not at https://github.com/aminya/project_options?tab=readme-ov-file#readme
What do you mean with
package_options
?They are not at https://github.com/aminya/project_options?tab=readme-ov-file#readme
Sorry, I meant project_options
.
I have updated the text of the issue to include a more detailed CMakeLists.txt
and re-explain the problem.
An interface library
is anheader only
implementation.
Thefind_package(OpenMP)
and the resulting compile_defintions must be done by the user of your exported cmake package
!
You need something like this https://github.com/ClausKlein/boost-modules-bench/blob/develop/asio-module/AsioConfig.cmake.in
And this is not supported by project_options
.
I agree that the config can be done by the user, but the work that must be done if an option is activated may be complicated, and it would simplify the user's job if that work was done for him upon a simple option's activation.
Using only standard cmake
functions, you indeed need a Config.cmake.in
file to do that. project_options
does not support it, ok.
I have a header-only library project, and I am using
project_options
to package it, so that it can be used as a dependency for other projects. The library has numerous options, defined with the cmake functionsoption
orset
. What I want is to export those options, so that calling projects can configure them. Here is the skeleton of itsCMakeLists.txt
, with the optionsWITH_OPENMP
andCHECK_NAN
:Now, another project has
my_lib
as a dependency. Here is itsCMakeLists.txt
:The compilation of
caller_project
works fine with thisCMakeLists.txt
. My problem is that I can't setmy_lib
's options. I think the options are simply not exported, since I don't see them when I use theccmake
command. (On the other hand, ifmy_lib
's dependencies have options themselves, I can see them inccmake
.) I tried usingdynamic_project_options
with and withoutENABLE_CACHE
, but no luck... Thank you for your support.Upvote & Fund
@aminya is using Polar.sh so you can upvote and help fund this issue. The funding is received once the issue is completed & confirmed by you.
Thank you in advance for helping prioritize & fund our backlog!