Skip to content

Commit ae177fd

Browse files
committed
Merge pull request open-source-parsers#263 from cdunn2001/static-shared
Use standard **cmake** variables, to support superprojects better. - `JSONCPP_LIB_BUILD_SHARED` -> `BUILD_SHARED_LIBS` - `JSONCPP_LIB_BUILD_STATIC` -> `BUILD_STATIC_LIBS`
2 parents 74143f3 + 3f63452 commit ae177fd

File tree

9 files changed

+23
-34
lines changed

9 files changed

+23
-34
lines changed

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ language: cpp
77
compiler:
88
- gcc
99
- clang
10-
script: cmake -DJSONCPP_WITH_CMAKE_PACKAGE=$CMAKE_PKG -DJSONCPP_LIB_BUILD_SHARED=$SHARED_LIB -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE=$VERBOSE_MAKE . && make && make jsoncpp_check
10+
script: cmake -DJSONCPP_WITH_CMAKE_PACKAGE=$CMAKE_PKG -DBUILD_SHARED_LIBS=$SHARED_LIB -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_VERBOSE_MAKEFILE=$VERBOSE_MAKE . && make && make jsoncpp_check
1111
env:
1212
matrix:
1313
- SHARED_LIB=ON STATIC_LIB=ON CMAKE_PKG=ON BUILD_TYPE=release VERBOSE_MAKE=false

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post
99
OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
1010
OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
1111
OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF)
12+
OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
13+
OPTION(BUILD_STATIC_LIBS "Build jsoncpp_lib static library." ON)
1214

1315
# Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
1416
IF(NOT WIN32)

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Steps for generating solution/makefiles using `cmake-gui`:
5858
* Make "source code" point to the source directory.
5959
* Make "where to build the binary" point to the directory to use for the build.
6060
* Click on the "Grouped" check box.
61-
* Review JsonCpp build options (tick `JSONCPP_LIB_BUILD_SHARED` to build as a
61+
* Review JsonCpp build options (tick `BUILD_SHARED_LIBS` to build as a
6262
dynamic library).
6363
* Click the configure button at the bottom, then the generate button.
6464
* The generated solution/makefiles can be found in the binary directory.
@@ -67,7 +67,7 @@ Alternatively, from the command-line on Unix in the source directory:
6767

6868
mkdir -p build/debug
6969
cd build/debug
70-
cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_STATIC=ON -DJSONCPP_LIB_BUILD_SHARED=OFF -G "Unix Makefiles" ../..
70+
cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_STATIC_LIBS=ON -DBUILD_SHARED_LIBS=OFF -G "Unix Makefiles" ../..
7171
make
7272

7373
Running `cmake -`" will display the list of available generators (passed using

dev.makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ dox:
1616
# Then 'git add -A' and 'git push' in jsoncpp-docs.
1717
build:
1818
mkdir -p build/debug
19-
cd build/debug; cmake -DCMAKE_BUILD_TYPE=debug -DJSONCPP_LIB_BUILD_SHARED=ON -G "Unix Makefiles" ../..
19+
cd build/debug; cmake -DCMAKE_BUILD_TYPE=debug -DBUILD_SHARED_LIBS=ON -G "Unix Makefiles" ../..
2020
make -C build/debug
2121

2222
# Currently, this depends on include/json/version.h generated

devtools/agent_vmw7.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
},
2020
{"name": "shared_dll",
2121
"variables": [
22-
["JSONCPP_LIB_BUILD_SHARED=true"],
23-
["JSONCPP_LIB_BUILD_SHARED=false"]
22+
["BUILD_SHARED_LIBS=true"],
23+
["BUILD_SHARED_LIBS=false"]
2424
]
2525
},
2626
{"name": "build_type",

devtools/agent_vmxp.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
},
1313
{"name": "shared_dll",
1414
"variables": [
15-
["JSONCPP_LIB_BUILD_SHARED=true"],
16-
["JSONCPP_LIB_BUILD_SHARED=false"]
15+
["BUILD_SHARED_LIBS=true"],
16+
["BUILD_SHARED_LIBS=false"]
1717
]
1818
},
1919
{"name": "build_type",

src/jsontestrunner/CMakeLists.txt

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
FIND_PACKAGE(PythonInterp 2.6)
22

3-
IF(JSONCPP_LIB_BUILD_SHARED)
4-
ADD_DEFINITIONS( -DJSON_DLL )
5-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
6-
73
ADD_EXECUTABLE(jsontestrunner_exe
84
main.cpp
95
)
106

11-
IF(JSONCPP_LIB_BUILD_SHARED)
7+
IF(BUILD_SHARED_LIBS)
8+
ADD_DEFINITIONS( -DJSON_DLL )
129
TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib)
13-
ELSE(JSONCPP_LIB_BUILD_SHARED)
10+
ELSE(BUILD_SHARED_LIBS)
1411
TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib_static)
15-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
12+
ENDIF(BUILD_SHARED_LIBS)
1613

1714
SET_TARGET_PROPERTIES(jsontestrunner_exe PROPERTIES OUTPUT_NAME jsontestrunner_exe)
1815

src/lib_json/CMakeLists.txt

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
OPTION(JSONCPP_LIB_BUILD_SHARED "Build jsoncpp_lib as a shared library." OFF)
2-
OPTION(JSONCPP_LIB_BUILD_STATIC "Build jsoncpp_lib static library." ON)
3-
4-
IF(BUILD_SHARED_LIBS)
5-
SET(JSONCPP_LIB_BUILD_SHARED ON)
6-
ENDIF(BUILD_SHARED_LIBS)
7-
81
if( CMAKE_COMPILER_IS_GNUCXX )
92
#Get compiler version.
103
execute_process( COMMAND ${CMAKE_CXX_COMPILER} -dumpversion
@@ -46,7 +39,7 @@ ELSE(JSONCPP_WITH_CMAKE_PACKAGE)
4639
SET(INSTALL_EXPORT)
4740
ENDIF(JSONCPP_WITH_CMAKE_PACKAGE)
4841

49-
IF(JSONCPP_LIB_BUILD_SHARED)
42+
IF(BUILD_SHARED_LIBS)
5043
ADD_DEFINITIONS( -DJSON_DLL_BUILD )
5144
ADD_LIBRARY(jsoncpp_lib SHARED ${PUBLIC_HEADERS} ${jsoncpp_sources})
5245
SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR})
@@ -65,7 +58,7 @@ IF(JSONCPP_LIB_BUILD_SHARED)
6558

6659
ENDIF()
6760

68-
IF(JSONCPP_LIB_BUILD_STATIC)
61+
IF(BUILD_STATIC_LIBS)
6962
ADD_LIBRARY(jsoncpp_lib_static STATIC ${PUBLIC_HEADERS} ${jsoncpp_sources})
7063
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES VERSION ${JSONCPP_VERSION} SOVERSION ${JSONCPP_VERSION_MAJOR})
7164
SET_TARGET_PROPERTIES( jsoncpp_lib_static PROPERTIES OUTPUT_NAME jsoncpp )

src/test_lib_json/CMakeLists.txt

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11
# vim: et ts=4 sts=4 sw=4 tw=0
22

3-
IF(JSONCPP_LIB_BUILD_SHARED)
4-
ADD_DEFINITIONS( -DJSON_DLL )
5-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
6-
73
ADD_EXECUTABLE( jsoncpp_test
84
jsontest.cpp
95
jsontest.h
106
main.cpp
117
)
128

139

14-
IF(JSONCPP_LIB_BUILD_SHARED)
10+
IF(BUILD_SHARED_LIBS)
11+
ADD_DEFINITIONS( -DJSON_DLL )
1512
TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib)
16-
ELSE(JSONCPP_LIB_BUILD_SHARED)
13+
ELSE(BUILD_SHARED_LIBS)
1714
TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib_static)
18-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
15+
ENDIF(BUILD_SHARED_LIBS)
1916

2017
# another way to solve issue #90
2118
#set_target_properties(jsoncpp_test PROPERTIES COMPILE_FLAGS -ffloat-store)
2219

2320
# Run unit tests in post-build
2421
# (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?)
2522
IF(JSONCPP_WITH_POST_BUILD_UNITTEST)
26-
IF(JSONCPP_LIB_BUILD_SHARED)
23+
IF(BUILD_SHARED_LIBS)
2724
# First, copy the shared lib, for Microsoft.
2825
# Then, run the test executable.
2926
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
3027
POST_BUILD
3128
COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:jsoncpp_lib> $<TARGET_FILE_DIR:jsoncpp_test>
3229
COMMAND $<TARGET_FILE:jsoncpp_test>)
33-
ELSE(JSONCPP_LIB_BUILD_SHARED)
30+
ELSE(BUILD_SHARED_LIBS)
3431
# Just run the test executable.
3532
ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
3633
POST_BUILD
3734
COMMAND $<TARGET_FILE:jsoncpp_test>)
38-
ENDIF(JSONCPP_LIB_BUILD_SHARED)
35+
ENDIF(BUILD_SHARED_LIBS)
3936
ENDIF(JSONCPP_WITH_POST_BUILD_UNITTEST)
4037

4138
SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test)

0 commit comments

Comments
 (0)