Skip to content

Commit 2a3ae0e

Browse files
authored
Merge pull request #932 from oleurodecision/cmake_clean
cmake cleanup
2 parents 2d211de + 85f5b1c commit 2a3ae0e

File tree

5 files changed

+22
-28
lines changed

5 files changed

+22
-28
lines changed

CMakeLists.txt

+11-17
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ project(JSONCPP
6666
VERSION 1.9.0 # <major>[.<minor>[.<patch>[.<tweak>]]]
6767
LANGUAGES CXX)
6868

69-
set( JSONCPP_VERSION ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH} )
7069
message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}")
7170
set( JSONCPP_SOVERSION 21 )
7271

@@ -88,12 +87,7 @@ include(GNUInstallDirs)
8887

8988
set(DEBUG_LIBNAME_SUFFIX "" CACHE STRING "Optional suffix to append to the library name for a debug build")
9089

91-
# Set variable named ${VAR_NAME} to value ${VALUE}
92-
function(set_using_dynamic_name VAR_NAME VALUE)
93-
set( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE)
94-
endfunction()
95-
96-
set( JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
90+
set(JSONCPP_USE_SECURE_MEMORY "0" CACHE STRING "-D...=1 to use memory-wiping allocator for STL" )
9791

9892
# File version.h is only regenerated on CMake configure step
9993
configure_file( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
@@ -107,11 +101,11 @@ macro(UseCompilationWarningAsError)
107101
if(MSVC)
108102
# Only enabled in debug because some old versions of VS STL generate
109103
# warnings when compiled in release configuration.
110-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
104+
add_compile_options($<$<CONFIG:Debug>:/WX>)
111105
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
112-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
106+
add_compile_options(-Werror)
113107
if(JSONCPP_WITH_STRICT_ISO)
114-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
108+
add_compile_options(-pedantic-errors)
115109
endif()
116110
endif()
117111
endmacro()
@@ -122,29 +116,29 @@ include_directories( ${jsoncpp_SOURCE_DIR}/include )
122116
if(MSVC)
123117
# Only enabled in debug because some old versions of VS STL generate
124118
# unreachable code warning when compiled in release configuration.
125-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
119+
add_compile_options($<$<CONFIG:Debug>:/W4>)
126120
endif()
127121

128122
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
129123
# using regular Clang or AppleClang
130-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare")
124+
add_compile_options(-Wall -Wconversion -Wshadow -Werror=conversion -Werror=sign-compare)
131125
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
132126
# using GCC
133-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra")
127+
add_compile_options(-Wall -Wconversion -Wshadow -Wextra)
134128
# not yet ready for -Wsign-conversion
135129

136130
if(JSONCPP_WITH_STRICT_ISO)
137-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
131+
add_compile_options(-pedantic)
138132
endif()
139133
if(JSONCPP_WITH_WARNING_AS_ERROR)
140-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=conversion")
134+
add_compile_options(-Werror=conversion)
141135
endif()
142136
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
143137
# using Intel compiler
144-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wconversion -Wshadow -Wextra -Werror=conversion")
138+
add_compile_options(-Wall -Wconversion -Wshadow -Wextra -Werror=conversion)
145139

146140
if(JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
147-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
141+
add_compile_options(-pedantic)
148142
endif()
149143
endif()
150144

src/jsontestrunner/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ add_executable(jsontestrunner_exe
55
)
66

77
if(BUILD_SHARED_LIBS)
8-
add_definitions( -DJSON_DLL )
8+
add_compile_definitions( JSON_DLL )
99
endif()
1010
target_link_libraries(jsontestrunner_exe jsoncpp_lib)
1111

src/lib_json/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ endif()
3434

3535
if(NOT (HAVE_CLOCALE AND HAVE_LCONV_SIZE AND HAVE_DECIMAL_POINT AND HAVE_LOCALECONV))
3636
message(WARNING "Locale functionality is not supported")
37-
add_definitions(-DJSONCPP_NO_LOCALE_SUPPORT)
37+
add_compile_definitions(JSONCPP_NO_LOCALE_SUPPORT)
3838
endif()
3939

4040
set( JSONCPP_INCLUDE_DIR ../../include )
@@ -68,7 +68,7 @@ else(JSONCPP_WITH_CMAKE_PACKAGE)
6868
endif()
6969

7070
if(BUILD_SHARED_LIBS)
71-
add_definitions( -DJSON_DLL_BUILD )
71+
add_compile_definitions( JSON_DLL_BUILD )
7272
endif()
7373

7474

src/lib_json/version.h.in

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// DO NOT EDIT. This file (and "version") is generated by CMake.
22
// Run CMake configure step to update it.
33
#ifndef JSON_VERSION_H_INCLUDED
4-
# define JSON_VERSION_H_INCLUDED
4+
#define JSON_VERSION_H_INCLUDED
55

6-
# define JSONCPP_VERSION_STRING "@JSONCPP_VERSION@"
7-
# define JSONCPP_VERSION_MAJOR @JSONCPP_VERSION_MAJOR@
8-
# define JSONCPP_VERSION_MINOR @JSONCPP_VERSION_MINOR@
9-
# define JSONCPP_VERSION_PATCH @JSONCPP_VERSION_PATCH@
10-
# define JSONCPP_VERSION_QUALIFIER
11-
# define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
6+
#define JSONCPP_VERSION_STRING "@JSONCPP_VERSION@"
7+
#define JSONCPP_VERSION_MAJOR @JSONCPP_VERSION_MAJOR@
8+
#define JSONCPP_VERSION_MINOR @JSONCPP_VERSION_MINOR@
9+
#define JSONCPP_VERSION_PATCH @JSONCPP_VERSION_PATCH@
10+
#define JSONCPP_VERSION_QUALIFIER
11+
#define JSONCPP_VERSION_HEXA ((JSONCPP_VERSION_MAJOR << 24) | (JSONCPP_VERSION_MINOR << 16) | (JSONCPP_VERSION_PATCH << 8))
1212

1313
#ifdef JSONCPP_USING_SECURE_MEMORY
1414
#undef JSONCPP_USING_SECURE_MEMORY

src/test_lib_json/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ add_executable( jsoncpp_test
88

99

1010
if(BUILD_SHARED_LIBS)
11-
add_definitions( -DJSON_DLL )
11+
add_compile_definitions( JSON_DLL )
1212
endif()
1313
target_link_libraries(jsoncpp_test jsoncpp_lib)
1414

0 commit comments

Comments
 (0)