From 7d611542ce8c14dc8249a1a71d67443fdb886131 Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Tue, 11 Nov 2025 11:34:37 -0800 Subject: [PATCH] Install locally by default to avoid naively overwriting /usr/local Use `-DCMAKE_INSTALL_PREFIX=...` to set a non-local install destination. Signed-off-by: Larry Gritz --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 595a262..506075b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,18 @@ -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.10) project(pystring LANGUAGES CXX VERSION 1.1.4) option (BUILD_SHARED_LIBS "Build shared libraries (set to OFF to build static libs)" ON) +# If the user hasn't configured cmake with an explicit +# -DCMAKE_INSTALL_PREFIX=..., then set it to safely install into ./dist, to +# help prevent the user from accidentally writing over /usr/local or whatever. +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT + AND PROJECT_IS_TOP_LEVEL) + set (CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/dist" CACHE PATH + "Installation location" FORCE) +endif() +message (STATUS "Installation path will be ${CMAKE_INSTALL_PREFIX}") + add_library(pystring pystring.cpp pystring.h