Skip to content
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

Add CMake option to disable installing #239

Open
nickanthony-dgl opened this issue Jan 31, 2024 · 4 comments
Open

Add CMake option to disable installing #239

nickanthony-dgl opened this issue Jan 31, 2024 · 4 comments

Comments

@nickanthony-dgl
Copy link

It would be nice to have an option like "OPENXLSX_ENABLE_INSTALL" that allows projects using this as subroject to avoid having the headers and static libs installed.

@jurassicLizard
Copy link

jurassicLizard commented Feb 19, 2024

Can you explain further what you wish to achieve ? i happen to be building this without having to "install" anything anywhere. just use the add_subdirectory CMAKE directive to add the project and then link against it by using

#....blabla your code here
add_subdirectory(relative/path/to/OpenXLSX)
#.....blabla your code here
add_executable(your_exe ${YOUR_EXE_SOURCES})
target_link_libraries(your_exe PRIVATE OpenXLSX::OpenXLSX)

cmake magic will take care of the rest

or have i misunderstood what you wish to achieve ?

@nickanthony-dgl
Copy link
Author

I am doing the same as what you descirbe above with the addition of install(TARGETS your_exe). I want to be able to configure cmake so that when I run cmake --install it will install my targets (i.e. your_exe) but it won't also install extra things like OpenXLSX's targets.

So I am proposing that OpenXLSX adds something like option(OPENXLSX_ENABLE_INSTALL "Should headers and static lib be installed" ON). Then you use if(OPENXLSX_ENABLE_INSTALL) to guard any part of OpenXLSX CMake files that use the install() command. Then people using the library with add_subdirectory just need to set this option to OFF if they don't want to install OpenXLSXs targets.

Many libraries do the same thing. For example take a look at GTest's INSTALL_GTEST option https://github.com/google/googletest/blob/main/CMakeLists.txt

@jurassicLizard
Copy link

jurassicLizard commented Feb 19, 2024

Yeah, i can see many cases where that might be needed . If you are interested , i currently tested with a rather small, private project and it appears using the EXCLUDE_FROM_ALL might achieve exactly what you want by excluding OpenXLSXs own install targets and only linking against it (tested with CMAKE 3.16.3) .This is , In case the requested option was never integrated in the project.

add_subdirectory(relative/path/to/OpenXLSX EXCLUDE_FROM_ALL)

Source : https://cmake.cmake.narkive.com/WKIKLMMB/disabling-install-target-for-subdirectory

@nickanthony-dgl
Copy link
Author

I'll give that a try, thanks.

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

No branches or pull requests

2 participants