Skip to content

Commit d9ffdc4

Browse files
committed
Configure Travis CI, to extend more compile environments.
Revert commit 9e5d57c to support string tpye VERSION. Add cmake compilation switch to choose language stanard.
1 parent d2c2052 commit d9ffdc4

File tree

6 files changed

+225
-41
lines changed

6 files changed

+225
-41
lines changed

.travis.yml

+135-21
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ sudo: false
99
addons:
1010
homebrew:
1111
packages:
12-
- clang-format
13-
- meson
14-
- ninja
12+
- clang-format
13+
- meson
14+
- ninja
1515
update: false # do not update homebrew by default
1616
apt:
1717
sources:
18-
- ubuntu-toolchain-r-test
19-
- llvm-toolchain-xenial-8
18+
- ubuntu-toolchain-r-test
19+
- llvm-toolchain-xenial-8
2020
packages:
21-
- clang-format-8
22-
- clang-8
23-
- valgrind
21+
- clang-format-8
22+
- clang-8
23+
- valgrind
2424
matrix:
2525
allow_failures:
2626
- os: osx
@@ -30,27 +30,74 @@ matrix:
3030
osx_image: xcode11
3131
compiler: clang
3232
env:
33-
CXX="clang++"
34-
CC="clang"
35-
LIB_TYPE=static
36-
BUILD_TYPE=release
33+
CXX="clang++"
34+
CC="clang"
35+
LIB_TYPE=static
36+
BUILD_TYPE=release
37+
LANGUAGE_STANDARD="11"
3738
script: ./.travis_scripts/meson_builder.sh
3839
- name: Linux xenial clang meson static release testing
3940
os: linux
4041
dist: xenial
4142
compiler: clang
4243
env:
43-
CXX="clang++"
44-
CC="clang"
45-
LIB_TYPE=static
46-
BUILD_TYPE=release
44+
CXX="clang++"
45+
CC="clang"
46+
LIB_TYPE=static
47+
BUILD_TYPE=release
48+
LANGUAGE_STANDARD="11"
4749
# before_install and install steps only needed for linux meson builds
4850
before_install:
49-
- source ./.travis_scripts/travis.before_install.${TRAVIS_OS_NAME}.sh
51+
- source ./.travis_scripts/travis.before_install.${TRAVIS_OS_NAME}.sh
5052
install:
51-
- source ./.travis_scripts/travis.install.${TRAVIS_OS_NAME}.sh
53+
- source ./.travis_scripts/travis.install.${TRAVIS_OS_NAME}.sh
5254
script: ./.travis_scripts/meson_builder.sh
53-
- name: Linux xenial gcc cmake coverage
55+
- name: Linux xenial gcc-4.6 meson static release with C++03 testing
56+
os: linux
57+
dist: xenial
58+
compiler: gcc
59+
addons:
60+
apt:
61+
sources:
62+
- ubuntu-toolchain-r-test
63+
packages:
64+
- g++-4.6
65+
env:
66+
CC=gcc-4.6
67+
CXX=g++-4.6
68+
LIB_TYPE=static
69+
BUILD_TYPE=release
70+
LANGUAGE_STANDARD="03"
71+
# before_install and install steps only needed for linux meson builds
72+
before_install:
73+
- source ./.travis_scripts/travis.before_install.${TRAVIS_OS_NAME}.sh
74+
install:
75+
- source ./.travis_scripts/travis.install.${TRAVIS_OS_NAME}.sh
76+
script: ./.travis_scripts/meson_builder.sh
77+
- name: Linux xenial gcc-4.6 meson static release with C++98 testing
78+
os: linux
79+
dist: xenial
80+
compiler: gcc
81+
addons:
82+
apt:
83+
sources:
84+
- ubuntu-toolchain-r-test
85+
packages:
86+
- g++-4.6
87+
env:
88+
CC=gcc-4.6
89+
CXX=g++-4.6
90+
LIB_TYPE=static
91+
BUILD_TYPE=release
92+
LANGUAGE_STANDARD="98"
93+
# before_install and install steps only needed for linux meson builds
94+
before_install:
95+
- source ./.travis_scripts/travis.before_install.${TRAVIS_OS_NAME}.sh
96+
install:
97+
- source ./.travis_scripts/travis.install.${TRAVIS_OS_NAME}.sh
98+
script: ./.travis_scripts/meson_builder.sh
99+
100+
- name: Linux xenial gcc-5.4 cmake-3.12 coverage
54101
os: linux
55102
dist: xenial
56103
compiler: gcc
@@ -62,10 +109,77 @@ matrix:
62109
BUILD_TYPE=Debug
63110
LIB_TYPE=shared
64111
DESTDIR=/tmp/cmake_json_cpp
112+
LANGUAGE_STANDARD="11"
65113
before_install:
66-
- pip install --user cpp-coveralls
114+
- pip install --user cpp-coveralls
67115
script: ./.travis_scripts/cmake_builder.sh
68116
after_success:
69-
- coveralls --include src/lib_json --include include
117+
- coveralls --include src/lib_json --include include
118+
- name: Linux xenial gcc-4.6 cmake-3.12 with C++98 testing
119+
os: linux
120+
dist: xenial
121+
compiler: gcc
122+
addons:
123+
apt:
124+
sources:
125+
- ubuntu-toolchain-r-test
126+
packages:
127+
- g++-4.6
128+
- valgrind
129+
env:
130+
CC=gcc-4.6
131+
CXX=g++-4.6
132+
DO_MemCheck=ON
133+
BUILD_TOOL="Unix Makefiles"
134+
LIB_TYPE=static
135+
BUILD_TYPE=release
136+
DESTDIR=/tmp/cmake_json_cpp
137+
LANGUAGE_STANDARD="98"
138+
before_install:
139+
- sudo apt-get update
140+
- sudo apt-get install python3
141+
script: ./.travis_scripts/cmake_builder.sh
142+
- name: Linux xenial gcc-5.4 cmake-3.12 with C++98 testing
143+
os: linux
144+
dist: xenial
145+
compiler: gcc
146+
env:
147+
CC=gcc
148+
CXX=g++
149+
DO_MemCheck=ON
150+
BUILD_TOOL="Unix Makefiles"
151+
LIB_TYPE=static
152+
BUILD_TYPE=release
153+
DESTDIR=/tmp/cmake_json_cpp
154+
LANGUAGE_STANDARD="98"
155+
script: ./.travis_scripts/cmake_builder.sh
156+
- name: Linux xenial clang cmake-3.12 with C++11 testing
157+
os: linux
158+
dist: xenial
159+
compiler: clang
160+
env:
161+
CC=clang
162+
CXX=clang++
163+
DO_MemCheck=ON
164+
BUILD_TOOL="Unix Makefiles"
165+
LIB_TYPE=static
166+
BUILD_TYPE=release
167+
DESTDIR=/tmp/cmake_json_cpp
168+
LANGUAGE_STANDARD="11"
169+
script: ./.travis_scripts/cmake_builder.sh
170+
- name: Linux xenial clang cmake-3.12 with C++98 testing
171+
os: linux
172+
dist: xenial
173+
compiler: gcc
174+
env:
175+
CC=clang
176+
CXX=clang++
177+
DO_MemCheck=ON
178+
BUILD_TOOL="Unix Makefiles"
179+
LIB_TYPE=static
180+
BUILD_TYPE=release
181+
DESTDIR=/tmp/cmake_json_cpp
182+
LANGUAGE_STANDARD="98"
183+
script: ./.travis_scripts/cmake_builder.sh
70184
notifications:
71185
email: false

.travis_scripts/cmake_builder.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ cmake --version
6666
echo ${CXX}
6767
${CXX} --version
6868
_COMPILER_NAME=`basename ${CXX}`
69-
if [ "${BUILD_TYPE}" == "shared" ]; then
69+
if [ "${BUILD_TYPE}" = "shared" ]; then
7070
_CMAKE_BUILD_SHARED_LIBS=ON
7171
else
7272
_CMAKE_BUILD_SHARED_LIBS=OFF
@@ -98,6 +98,14 @@ else
9898
export _BUILD_EXE=make
9999
fi
100100

101+
# Language standard
102+
# Set default to ON
103+
if [ "${LANGUAGE_STANDARD}" = "98" ]; then
104+
_BUILD_WITH_CXX_11=OFF
105+
else
106+
_BUILD_WITH_CXX_11=ON
107+
fi
108+
101109
_BUILD_DIR_NAME="build-cmake_${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}_${_BUILD_EXE}"
102110
mkdir -p ${_BUILD_DIR_NAME}
103111
cd "${_BUILD_DIR_NAME}"
@@ -112,6 +120,7 @@ cd "${_BUILD_DIR_NAME}"
112120
-DCMAKE_BUILD_TYPE:STRING=${BUILD_TYPE} \
113121
-DBUILD_SHARED_LIBS:BOOL=${_CMAKE_BUILD_SHARED_LIBS} \
114122
-DCMAKE_INSTALL_PREFIX:PATH=${DESTDIR} \
123+
-DBUILD_WITH_CXX_11=${_BUILD_WITH_CXX_11} \
115124
../
116125

117126
ctest -C ${BUILD_TYPE} -D ExperimentalStart -D ExperimentalConfigure -D ExperimentalBuild ${CTEST_TESTING_OPTION} -D ExperimentalSubmit

.travis_scripts/meson_builder.sh

+5-1
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ ninja --version
6464
_COMPILER_NAME=`basename ${CXX}`
6565
_BUILD_DIR_NAME="build-${BUILD_TYPE}_${LIB_TYPE}_${_COMPILER_NAME}"
6666

67+
# if LANGUAGE_STANDARD not set or null, set it to 11
68+
_CPP_STD=${LANGUAGE_STANDARD:="11"}
69+
6770
./.travis_scripts/run-clang-format.sh
6871
meson --fatal-meson-warnings --werror --buildtype ${BUILD_TYPE} --default-library ${LIB_TYPE} . "${_BUILD_DIR_NAME}"
69-
ninja -v -j 2 -C "${_BUILD_DIR_NAME}"
7072

7173
cd "${_BUILD_DIR_NAME}"
74+
meson configure -Dcpp_std="c++${_CPP_STD}"
75+
ninja -v -j 2 -C ./
7276
meson test --no-rebuild --print-errorlogs
7377

7478
if [ "${DESTDIR}" != "/usr/local" ]; then

CMakeLists.txt

+69-17
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ foreach(pold "") # Currently Empty
3737
endif()
3838
endforeach()
3939

40-
# Build the library with C++11 standard support, independent from other including
41-
# software which may use a different CXX_STANDARD or CMAKE_CXX_STANDARD.
42-
set(CMAKE_CXX_STANDARD 11)
43-
set(CMAKE_CXX_EXTENSIONS OFF)
44-
set(CMAKE_CXX_STANDARD_REQUIRED ON)
45-
4640
# Ensure that CMAKE_BUILD_TYPE has a value specified for single configuration generators.
4741
if(NOT DEFINED CMAKE_BUILD_TYPE AND NOT DEFINED CMAKE_CONFIGURATION_TYPES)
4842
set(CMAKE_BUILD_TYPE Release CACHE STRING
@@ -59,19 +53,47 @@ if(CCACHE_EXECUTABLE)
5953
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" CACHE PATH "ccache" FORCE)
6054
endif()
6155

56+
# Note: project(VERSION XX) - the VERSION here is number, but VERSION in meson is string.
57+
# Thus, it is better to be consistent.
6258
project(JSONCPP
63-
# Note: version must be updated in three places when doing a release. This
64-
# annoying process ensures that amalgamate, CMake, and meson all report the
65-
# correct version.
66-
# 1. ./meson.build
67-
# 2. ./include/json/version.h
68-
# 3. ./CMakeLists.txt
69-
# IMPORTANT: also update the JSONCPP_SOVERSION!!
70-
VERSION 1.9.3 # <major>[.<minor>[.<patch>[.<tweak>]]]
7159
LANGUAGES CXX)
7260

61+
# Set variable named ${VAR_NAME} to value ${VALUE}
62+
function(set_using_dynamic_name VAR_NAME VALUE)
63+
set( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE)
64+
endfunction()
65+
66+
# Extract major, minor, patch from version text
67+
# Parse a version string "X.Y.Z" and outputs
68+
# version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH.
69+
# If parse succeeds then ${OUPUT_PREFIX}_FOUND is TRUE.
70+
macro(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
71+
set(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?")
72+
if( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
73+
string(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT})
74+
list(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR)
75+
list(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR)
76+
list(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH)
77+
set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE )
78+
else( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
79+
set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE )
80+
endif()
81+
endmacro()
82+
83+
# Note: version must be updated in three places when doing a release. This
84+
# annoying process ensures that amalgamate, CMake, and meson all report the
85+
# correct version.
86+
# 1. ./meson.build
87+
# 2. ./include/json/version.h
88+
# 3. ./CMakeLists.txt
89+
# IMPORTANT: also update the JSONCPP_SOVERSION!!
90+
set( JSONCPP_VERSION 00.11.0 )
91+
set( JSONCPP_SOVERSION 23 )
92+
jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
7393
message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
74-
set(JSONCPP_SOVERSION 23)
94+
#if(NOT JSONCPP_VERSION_FOUND)
95+
# message(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z")
96+
#endif(NOT JSONCPP_VERSION_FOUND)
7597

7698
option(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
7799
option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
@@ -81,6 +103,36 @@ option(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
81103
option(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" ON)
82104
option(JSONCPP_WITH_EXAMPLE "Compile JsonCpp example" OFF)
83105
option(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
106+
option(BUILD_WITH_CXX_11 "Build jsoncpp_lib with C++11 standard." ON)
107+
108+
## To compatible with C++0x and C++1x
109+
set(CMAKE_MINIMUN_CXX_STANDARD 98)
110+
if(CMAKE_COMPILER_IS_GNUCXX)
111+
set(CMAKE_CXX_COMPILER "/usr/bin/g++")
112+
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE CXX_VERSION)
113+
if(CXX_VERSION VERSION_GREATER 4.8.0)
114+
if(BUILD_WITH_CXX_11)
115+
set(CMAKE_CXX_STANDARD 11)
116+
message(STATUS "Compiled with C++11(or newer) standard!")
117+
else()
118+
set(CMAKE_CXX_STANDARD 98)
119+
message(STATUS "Compiled with C++0x standard!")
120+
endif()
121+
else()
122+
set(CMAKE_CXX_STANDARD 98)
123+
message(STATUS "Compiled with C++0x standard!")
124+
endif()
125+
endif()
126+
127+
if (NOT CMAKE_CXX_STANDARD)
128+
if (BUILD_WITH_CXX_11)
129+
set(CMAKE_CXX_STANDARD 11)
130+
message(STATUS "Compiled with C++1x standard!")
131+
else()
132+
set(CMAKE_CXX_STANDARD 98)
133+
message(STATUS "Compiled with C++0x standard!")
134+
endif()
135+
endif()
84136

85137
# Adhere to GNU filesystem layout conventions
86138
include(GNUInstallDirs)
@@ -127,7 +179,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
127179
# not yet ready for -Wsign-conversion
128180

129181
if(JSONCPP_WITH_STRICT_ISO)
130-
add_compile_options(-Wpedantic)
182+
add_compile_options(-Wall)
131183
endif()
132184
if(JSONCPP_WITH_WARNING_AS_ERROR)
133185
add_compile_options(-Werror=conversion)
@@ -160,7 +212,7 @@ if(JSONCPP_WITH_CMAKE_PACKAGE)
160212
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp
161213
FILE jsoncppConfig.cmake)
162214
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake"
163-
VERSION ${PROJECT_VERSION}
215+
VERSION ${JSONCPP_VERSION}
164216
COMPATIBILITY SameMajorVersion)
165217
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/jsoncppConfigVersion.cmake
166218
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/jsoncpp)

meson.build

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ project(
99
# 2. /include/json/version.h
1010
# 3. /CMakeLists.txt
1111
# IMPORTANT: also update the SOVERSION!!
12-
version : '1.9.3',
12+
version : '00.11.0',
1313
default_options : [
1414
'buildtype=release',
1515
'cpp_std=c++11',

src/lib_json/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ endif()
9090
# Specify compiler features required when compiling a given target.
9191
# See https://cmake.org/cmake/help/v3.1/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html#prop_gbl:CMAKE_CXX_KNOWN_FEATURES
9292
# for complete list of features available
93+
if(CMAKE_CXX_STANDARD EQUAL "11")
9394
target_compile_features(jsoncpp_lib PUBLIC
9495
cxx_std_11 # Compiler mode is aware of C++ 11.
9596
#MSVC 1900 cxx_alignas # Alignment control alignas, as defined in N2341.
@@ -136,6 +137,10 @@ target_compile_features(jsoncpp_lib PUBLIC
136137
cxx_variadic_macros # Variadic macros, as defined in N1653.
137138
cxx_variadic_templates # Variadic templates, as defined in N2242.
138139
)
140+
else()
141+
set(CMAKE_CXX_STANDARD 98)
142+
target_compile_features(jsoncpp_lib PUBLIC)
143+
endif()
139144

140145
install(TARGETS jsoncpp_lib ${INSTALL_EXPORT}
141146
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}

0 commit comments

Comments
 (0)