Skip to content

Commit c195f66

Browse files
authored
Install locally by default to avoid naively overwriting /usr/local (#52)
Use `-DCMAKE_INSTALL_PREFIX=...` to set a non-local install destination. Signed-off-by: Larry Gritz <[email protected]>
1 parent a09708a commit c195f66

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.10)
22
project(pystring LANGUAGES CXX VERSION 1.1.4)
33

44
option (BUILD_SHARED_LIBS "Build shared libraries (set to OFF to build static libs)" ON)
55

6+
# If the user hasn't configured cmake with an explicit
7+
# -DCMAKE_INSTALL_PREFIX=..., then set it to safely install into ./dist, to
8+
# help prevent the user from accidentally writing over /usr/local or whatever.
9+
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
10+
AND PROJECT_IS_TOP_LEVEL)
11+
set (CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/dist" CACHE PATH
12+
"Installation location" FORCE)
13+
endif()
14+
message (STATUS "Installation path will be ${CMAKE_INSTALL_PREFIX}")
15+
616
add_library(pystring
717
pystring.cpp
818
pystring.h

0 commit comments

Comments
 (0)