Skip to content

Commit 6a1716e

Browse files
Opt in to the default CMake install path (#994)
CXX-2703 Allow user to opt in to the default CMake install path by setting -DUSE_DEFAULT_INSTALL_PATH=ON --------- Co-authored-by: Kevin Albertson <[email protected]>
1 parent 92523bb commit 6a1716e

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,12 @@ To build static libraries only, set both BUILD_SHARED_LIBS and BUILD_SHARED_AND_
130130
endif()
131131

132132

133-
# If the user did not customize the install prefix,
134-
# set it to live under build so we don't inadvertently pollute /usr/local
135-
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
133+
option(USE_DEFAULT_INSTALL_PATH "Override the CMake default installation path" OFF)
134+
if(NOT CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND USE_DEFAULT_INSTALL_PATH)
135+
message(FATAL_ERROR "You cannot set both CMAKE_INSTALL_PREFIX and USE_DEFAULT_INSTALL_PATH")
136+
endif()
137+
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND NOT USE_DEFAULT_INSTALL_PATH)
138+
message(WARNING "the CMake default install path is being overridden to the build directory. This behavior will not be the default in a future release. Build with -DUSE_DEFAULT_INSTALL_PATH=ON to opt into what will be the default behavior in a future release. Setting install path to: ${CMAKE_BINARY_DIR}/install")
136139
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
137140
endif()
138141

docs/content/mongocxx-v3/installation/linux.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ from source. To configure `mongocxx` for installation into `/usr/local` as well,
9999
```
100100
cmake .. \
101101
-DCMAKE_BUILD_TYPE=Release \
102-
-DCMAKE_INSTALL_PREFIX=/usr/local
102+
-DUSE_DEFAULT_INSTALL_PATH=ON
103103
```
104104

105105
These options can be freely mixed with a C++17 polyfill option. For instance, this is how a user
@@ -108,7 +108,7 @@ would run the command above with the Boost polyfill option:
108108
cmake .. \
109109
-DCMAKE_BUILD_TYPE=Release \
110110
-DBSONCXX_POLY_USE_BOOST=1 \
111-
-DCMAKE_INSTALL_PREFIX=/usr/local
111+
-DUSE_DEFAULT_INSTALL_PATH=ON
112112
```
113113

114114
### Step 5: Build and install the driver

docs/content/mongocxx-v3/installation/macos.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ from source. To configure `mongocxx` for installation into `/usr/local` as well,
9999
```
100100
cmake .. \
101101
-DCMAKE_BUILD_TYPE=Release \
102-
-DCMAKE_INSTALL_PREFIX=/usr/local
102+
-DUSE_DEFAULT_INSTALL_PATH=ON
103103
```
104104

105105
These options can be freely mixed with a C++17 polyfill option. For instance, this is how a user
@@ -108,7 +108,7 @@ would run the command above with the Boost polyfill option:
108108
cmake .. \
109109
-DCMAKE_BUILD_TYPE=Release \
110110
-DBSONCXX_POLY_USE_BOOST=1 \
111-
-DCMAKE_INSTALL_PREFIX=/usr/local
111+
-DUSE_DEFAULT_INSTALL_PATH=ON
112112
```
113113

114114
### Step 5: Build and install the driver

0 commit comments

Comments
 (0)