From 44661b312bb6488dbebf74107a8854a1481c86f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E8=AF=97=E6=B6=B5?= Date: Sun, 16 Jun 2024 17:17:58 +0800 Subject: [PATCH 1/4] Add option BACKWARD_INSTALL --- CMakeLists.txt | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e625f8a..bb615d1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,9 @@ cmake_minimum_required(VERSION 3.14) project(backward CXX) +# https://cmake.org/cmake/help/latest/variable/PROJECT_IS_TOP_LEVEL.html +string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} PROJECT_IS_TOP_LEVEL) + # Introduce variables: # * CMAKE_INSTALL_LIBDIR # * CMAKE_INSTALL_BINDIR @@ -35,13 +38,17 @@ include(BackwardConfig.cmake) # OPTIONS ############################################################################### +include(CMakeDependentOption) + option(BACKWARD_SHARED "Build backward as a shared library" OFF) +option if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND NOT DEFINED BACKWARD_TESTS) # If this is a top level CMake project, we most lixely want the tests set(BACKWARD_TESTS ON CACHE BOOL "Enable tests") else() set(BACKWARD_TESTS OFF CACHE BOOL "Enable tests") endif() +cmake_dependent_option(BACKWARD_INSTALL "Install backward." ${PROJECT_IS_TOP_LEVEL} "NOT BACKWARD_SHARED" ON) ############################################################################### # COMPILER FLAGS @@ -157,20 +164,22 @@ if(BACKWARD_TESTS) endforeach() endif() -install( - FILES "backward.hpp" - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} -) -install( - FILES "BackwardConfig.cmake" - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -) -# check if Backward is being used as a top-level project or included as a subproject -if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - # export the targets (note that exporting backward_object does not make sense) - install(TARGETS backward_interface backward EXPORT BackwardTargets) - # install a CMake file for the exported targets - install(EXPORT BackwardTargets - NAMESPACE Backward:: - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") +if(BACKWARD_INSTALL) + install( + FILES "backward.hpp" + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + install( + FILES "BackwardConfig.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" + ) + # check if Backward is being used as a top-level project or included as a subproject + if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) + # export the targets (note that exporting backward_object does not make sense) + install(TARGETS backward_interface backward EXPORT BackwardTargets) + # install a CMake file for the exported targets + install(EXPORT BackwardTargets + NAMESPACE Backward:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") + endif() endif() From a7e37f07f1434f946798ebe7109d25facbda1013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E8=AF=97=E6=B6=B5?= Date: Sun, 16 Jun 2024 17:22:17 +0800 Subject: [PATCH 2/4] Fix CMakeLists.txt --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb615d1..7464db3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,6 @@ include(BackwardConfig.cmake) include(CMakeDependentOption) option(BACKWARD_SHARED "Build backward as a shared library" OFF) -option if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND NOT DEFINED BACKWARD_TESTS) # If this is a top level CMake project, we most lixely want the tests set(BACKWARD_TESTS ON CACHE BOOL "Enable tests") From 734cdcdf22a2ed85e4653d8de90c77814ed254a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E8=AF=97=E6=B6=B5?= Date: Sat, 22 Jun 2024 18:27:23 +0800 Subject: [PATCH 3/4] Update CMakeLists.txt to not break current behavior --- CMakeLists.txt | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7464db3..a679019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,16 +38,9 @@ include(BackwardConfig.cmake) # OPTIONS ############################################################################### -include(CMakeDependentOption) - option(BACKWARD_SHARED "Build backward as a shared library" OFF) -if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR AND NOT DEFINED BACKWARD_TESTS) - # If this is a top level CMake project, we most lixely want the tests - set(BACKWARD_TESTS ON CACHE BOOL "Enable tests") -else() - set(BACKWARD_TESTS OFF CACHE BOOL "Enable tests") -endif() -cmake_dependent_option(BACKWARD_INSTALL "Install backward." ${PROJECT_IS_TOP_LEVEL} "NOT BACKWARD_SHARED" ON) +option(BACKWARD_INSTALL "Install backward." ON) +option(BACKWARD_TESTS "Enable tests" ${PROJECT_IS_TOP_LEVEL}) ############################################################################### # COMPILER FLAGS From 6146999f0e80922e64c4c1ef86340c793eed653c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E8=AF=97=E6=B6=B5?= Date: Sun, 23 Jun 2024 01:22:48 +0800 Subject: [PATCH 4/4] Fix CMake target export --- CMakeLists.txt | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a679019..7b743b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,13 +165,10 @@ if(BACKWARD_INSTALL) FILES "BackwardConfig.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) - # check if Backward is being used as a top-level project or included as a subproject - if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR) - # export the targets (note that exporting backward_object does not make sense) - install(TARGETS backward_interface backward EXPORT BackwardTargets) - # install a CMake file for the exported targets - install(EXPORT BackwardTargets - NAMESPACE Backward:: - DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") - endif() + # export the targets (note that exporting backward_object does not make sense) + install(TARGETS backward_interface backward EXPORT BackwardTargets) + # install a CMake file for the exported targets + install(EXPORT BackwardTargets + NAMESPACE Backward:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") endif()