From a8d4190342f9cedb240f5beeadf2086e2ec83795 Mon Sep 17 00:00:00 2001 From: Pascal Thomet Date: Fri, 2 Feb 2024 00:38:35 +0100 Subject: [PATCH] CMake: add option HELLOIMGUI_INSTALL --- CMakeLists.txt | 8 +++++++- hello_imgui_cmake/hello-imguiConfig.cmake | 1 - hello_imgui_cmake/hello_imgui_build_lib.cmake | 8 ++++---- .../hello_imgui_test_engine_cmake.cmake | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cab39257..73e2dc9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -195,6 +195,12 @@ option(HELLOIMGUI_BUILD_TESTS "Build tests" OFF) option(HELLOIMGUI_WITH_TEST_ENGINE "Provide ImGui Test engine" OFF) message(STATUS "HELLOIMGUI_WITH_TEST_ENGINE=${HELLOIMGUI_WITH_TEST_ENGINE}") +#------------------------------------------------------------------------------ +# Options / Install +# By default, hello_imgui install its targets only if it is the top level project +#------------------------------------------------------------------------------ +option(HELLOIMGUI_INSTALL "Install hello_imgui" ${PROJECT_IS_TOP_LEVEL}) + #------------------------------------------------------------------------------ # Instructions: how to enable Emscripten multithreading support #------------------------------------------------------------------------------ @@ -362,7 +368,7 @@ endif() # find_package(hello-imgui CONFIG REQUIRED) # hello_imgui_add_app(test test.cpp) # this will automatically link with hello_imgui #------------------------------------------------------------------------------ -if(PROJECT_IS_TOP_LEVEL) +if(HELLOIMGUI_INSTALL) # inspired from https://iamsorush.com/posts/cpp-cmake-config/ message(STATUS "HELLOIMGUI_INSTALLABLE_DEPENDENCIES=${HELLOIMGUI_INSTALLABLE_DEPENDENCIES}") install(TARGETS ${HELLOIMGUI_INSTALLABLE_DEPENDENCIES} diff --git a/hello_imgui_cmake/hello-imguiConfig.cmake b/hello_imgui_cmake/hello-imguiConfig.cmake index a6f39d4f..2b93540d 100644 --- a/hello_imgui_cmake/hello-imguiConfig.cmake +++ b/hello_imgui_cmake/hello-imguiConfig.cmake @@ -3,5 +3,4 @@ find_dependency(imgui CONFIG REQUIRED) find_dependency(glad CONFIG REQUIRED) include(${CMAKE_CURRENT_LIST_DIR}/hello_imgui_cmake/hello_imgui_add_app.cmake) -message(STATUS "including ${CMAKE_CURRENT_LIST_DIR}/hello_imgui_cmake/hello_imgui_add_app.cmake") include(${CMAKE_CURRENT_LIST_DIR}/hello-imgui-targets.cmake) diff --git a/hello_imgui_cmake/hello_imgui_build_lib.cmake b/hello_imgui_cmake/hello_imgui_build_lib.cmake index 69a1f7db..9f28fc56 100644 --- a/hello_imgui_cmake/hello_imgui_build_lib.cmake +++ b/hello_imgui_cmake/hello_imgui_build_lib.cmake @@ -92,7 +92,7 @@ function(him_build_imgui) endfunction() function(him_install_imgui) - if(PROJECT_IS_TOP_LEVEL) + if(HELLOIMGUI_INSTALL) if(NOT TARGET imgui) return() endif() @@ -433,7 +433,7 @@ function(him_add_stb_image) target_compile_definitions(stb_hello_imgui PRIVATE STB_IMAGE_WRITE_IMPLEMENTATION) endif() - if(PROJECT_IS_TOP_LEVEL AND NOT Stb_FOUND) + if(HELLOIMGUI_INSTALL AND NOT Stb_FOUND) file(GLOB stb_headers ${stb_dir}/*.h) install(FILES ${stb_headers} DESTINATION include) endif() @@ -636,7 +636,7 @@ function(_him_add_glad) target_link_libraries(${HELLOIMGUI_TARGET} PUBLIC glad) him_add_installable_dependency(glad) - if(PROJECT_IS_TOP_LEVEL) + if(HELLOIMGUI_INSTALL) install(TARGETS glad DESTINATION ./lib/) install(FILES ${glad_dir}/include/glad/glad.h DESTINATION include/glad) install(FILES ${glad_dir}/include/KHR/khrplatform.h DESTINATION include/KHR) @@ -938,7 +938,7 @@ endfunction() # Install: API = him_install ################################################################################################### function(him_install) - if (PROJECT_IS_TOP_LEVEL AND NOT IOS AND NOT ANDROID) + if (HELLOIMGUI_INSTALL AND NOT IOS AND NOT ANDROID) install(TARGETS ${HELLOIMGUI_TARGET} DESTINATION lib/) file(GLOB headers *.h) install(FILES ${headers} DESTINATION include/hello_imgui/) diff --git a/src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake b/src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake index 6d51aadb..7ce18a48 100644 --- a/src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake +++ b/src/hello_imgui_test_engine_integration/hello_imgui_test_engine_cmake.cmake @@ -49,7 +49,7 @@ function(_add_imgui_test_engine_lib) ) # install test_engine headers - if(PROJECT_IS_TOP_LEVEL) + if(HELLOIMGUI_INSTALL) file(GLOB te_headers ${te_source_folder}/*.h) install(FILES ${te_headers} DESTINATION include/imgui_test_engine) install(DIRECTORY ${te_source_folder}/thirdparty DESTINATION include)