Skip to content

Commit 3991de7

Browse files
committed
Enforce C++ standard and visibility
1 parent 0eddf74 commit 3991de7

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

CMakeLists.txt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
# Versions < 2.8.8 do not support Object Libraries
2-
cmake_minimum_required(VERSION 3.1.0)
2+
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
33

44
# Add in our modules
55
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
66

7-
# Enforce the C++ standard
8-
set (CXX_STANDARD_REQUIRED true)
7+
# Enforce the C++ standard, and disable extensions
8+
set(CMAKE_CXX_STANDARD 11)
9+
set(CMAKE_CXX_EXTENSIONS OFF)
10+
11+
# CMake 3.1 doesn't know how to C++11 for clang.
12+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
13+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
14+
else()
15+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
16+
endif()
917

1018
# Include the required modules
1119
include(GenerateExportHeader)
1220
include(InstallRequiredSystemLibraries)
1321

22+
# If the user did not customize the install prefix,
23+
# set it to live under build so we don't inadverently pollute /usr/local
24+
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
25+
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE )
26+
endif()
27+
1428
# Ensure we have Package Config
1529
find_package(PkgConfig)
1630

@@ -32,10 +46,6 @@ if (NOT CMAKE_BUILD_TYPE)
3246
set(CMAKE_BUILD_TYPE "Release")
3347
endif()
3448

35-
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Werror -fPIC ${CMAKE_CXX_FLAGS}")
36-
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
37-
set(CMAKE_CXX_FLAGS_DEBUG "-ggdb3 -O0")
38-
3949
if(BUILD_UNIT_TESTS)
4050
enable_testing()
4151
endif()

src/bsoncxx/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,12 @@ add_library(bsoncxx SHARED
6565

6666
set_target_properties (bsoncxx PROPERTIES
6767
OUTPUT_NAME bsoncxx
68-
CXX_STANDARD 11
6968
VERSION ${BSONCXX_VERSION}
69+
DEFINE_SYMBOL BSONCXX_EXPORTS
70+
# uncomment when BSONCXX_API is applied as needed
71+
# CXX_VISIBILITY_PRESET hidden
72+
# VISIBILITY_INLINES_HIDDEN ON
73+
#
7074
# uncomment this line when we start promising a stable ABI
7175
# SOVERSION ${BSONCXX_ABI_VERSION}
7276
)

src/mongocxx/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ add_library(mongocxx SHARED ${mongocxx_sources})
4949

5050
set_target_properties (mongocxx PROPERTIES
5151
OUTPUT_NAME mongocxx
52-
CXX_STANDARD 11
5352
VERSION ${MONGOCXX_VERSION}
53+
DEFINE_SYMBOL MONGOCXX_EXPORTS
54+
CXX_VISIBILITY_PRESET hidden
55+
VISIBILITY_INLINES_HIDDEN ON
5456
# uncomment below line when we start promising a stable ABI
5557
# SOVERSION ${MONGOCXX_ABI_VERSION}
5658
)
@@ -62,7 +64,6 @@ if(BUILD_UNIT_TESTS)
6264

6365
set_target_properties (mongocxx-mocked PROPERTIES
6466
OUTPUT_NAME mongocxx-mocked
65-
CXX_STANDARD 11
6667
VERSION ${MONGOCXX_VERSION}
6768
SOVERSION ${MONGOCXX_ABI_VERSION}
6869
COMPILE_FLAGS "-DMONGOCXX_TESTING"

0 commit comments

Comments
 (0)