From e527cf8dc65f0a20d8c17b01754dcbc319b64826 Mon Sep 17 00:00:00 2001
From: Matt McCormick <matt.mccormick@kitware.com>
Date: Mon, 23 Sep 2013 22:29:05 +0000
Subject: [PATCH 1/2] Consistent CMake lower case commands.

This is the preferred style for modern CMakeLists.txt.
---
 CMakeLists.txt                    | 91 ++++++++++++++++++---------------------
 include/CMakeLists.txt            |  4 +-
 src/CMakeLists.txt                | 10 ++---
 src/jsontestrunner/CMakeLists.txt | 28 ++++++------
 src/lib_json/CMakeLists.txt       | 30 ++++++-------
 src/test_lib_json/CMakeLists.txt  | 23 +++++-----
 6 files changed, 90 insertions(+), 96 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2f88080..8689e94 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,77 +1,72 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(jsoncpp)
-ENABLE_TESTING()
+cmake_minimum_required(VERSION 2.6)
+project(jsoncpp)
+enable_testing()
 
-OPTION(JSONCPP_WITH_TESTS "Compile and run JsonCpp test executables" ON)
-OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
-OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
+option(JSONCPP_WITH_TESTS "Compile and run JsonCpp test executables" ON)
+option(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
+option(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
 
 # Ensures that CMAKE_BUILD_TYPE is visible in cmake-gui on Unix
-IF(NOT WIN32)
-    IF(NOT CMAKE_BUILD_TYPE)
-        SET(CMAKE_BUILD_TYPE Release CACHE STRING
+if(NOT WIN32)
+    if(NOT CMAKE_BUILD_TYPE)
+        set(CMAKE_BUILD_TYPE Release CACHE STRING
             "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel Coverage."
             FORCE)
-    ENDIF(NOT CMAKE_BUILD_TYPE)
-ENDIF(NOT WIN32) 
+    endif(NOT CMAKE_BUILD_TYPE)
+endif(NOT WIN32)
 
 # This ensures shared DLL are in the same dir as executable on Windows.
 # Put all executables / libraries are in a project global directory.
-SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
     CACHE PATH "Single directory for all static libraries.")
-SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
     CACHE PATH "Single directory for all dynamic libraries on Unix.")
-SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
     CACHE PATH "Single directory for all executable and dynamic libraries on Windows.")
-MARK_AS_ADVANCED( CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY )
-
-# Set variable named ${VAR_NAME} to value ${VALUE}
-FUNCTION(set_using_dynamic_name VAR_NAME VALUE)
-    SET( "${VAR_NAME}" "${VALUE}" PARENT_SCOPE)
-ENDFUNCTION(set_using_dynamic_name) 
+mark_as_advanced( CMAKE_RUNTIME_OUTPUT_DIRECTORY CMAKE_LIBRARY_OUTPUT_DIRECTORY CMAKE_ARCHIVE_OUTPUT_DIRECTORY )
 
 # Extract major, minor, patch and qualifier from version text
 # Parse a version string "X.Y.Z[-qualifier]" and outputs
 # version parts in ${OUPUT_PREFIX}_MAJOR, _MINOR, _PATCH, _QUALIFIER.
 # If parse succed then ${OUPUT_PREFIX}_FOUND is TRUE.
-MACRO(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
-    SET(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?")
-    IF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
-        STRING(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT})
+macro(jsoncpp_parse_version VERSION_TEXT OUPUT_PREFIX)
+    set(VERSION_REGEX "[0-9]+\\.[0-9]+\\.[0-9]+(-[a-zA-Z0-9_]+)?")
+    if( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
+        string(REGEX MATCHALL "[0-9]+|-([A-Za-z0-9_]+)" VERSION_PARTS ${VERSION_TEXT})
         list(APPEND VERSION_PARTS "") # empty qualifier to handle no qualifier case
-        LIST(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR)
-        LIST(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR)
-        LIST(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH)
-        LIST(GET VERSION_PARTS 3 ${OUPUT_PREFIX}_QUALIFIER)
-        set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" TRUE ) 
-    ELSE( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
-        set_using_dynamic_name( "${OUPUT_PREFIX}_FOUND" FALSE ) 
-    ENDIF( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
-ENDMACRO(jsoncpp_parse_version)
+        list(GET VERSION_PARTS 0 ${OUPUT_PREFIX}_MAJOR)
+        list(GET VERSION_PARTS 1 ${OUPUT_PREFIX}_MINOR)
+        list(GET VERSION_PARTS 2 ${OUPUT_PREFIX}_PATCH)
+        list(GET VERSION_PARTS 3 ${OUPUT_PREFIX}_QUALIFIER)
+        set( ${OUPUT_PREFIX}_FOUND TRUE )
+    else( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
+        set( ${OUPUT_PREFIX}_FOUND FALSE )
+    endif( ${VERSION_TEXT} MATCHES ${VERSION_REGEX} )
+endmacro(jsoncpp_parse_version)
 
 # Read out version from "version" file
-FILE(STRINGS "version" JSONCPP_VERSION)
+file(STRINGS "version" JSONCPP_VERSION)
 
 jsoncpp_parse_version( ${JSONCPP_VERSION} JSONCPP_VERSION )
-IF(NOT JSONCPP_VERSION_FOUND)
-    MESSAGE(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z[-qualifier]")
-ENDIF(NOT JSONCPP_VERSION_FOUND)
+if(NOT JSONCPP_VERSION_FOUND)
+    message(FATAL_ERROR "Failed to parse version string properly. Expect X.Y.Z[-qualifier]")
+endif(NOT JSONCPP_VERSION_FOUND)
 
-MESSAGE(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}${JSONCPP_VERSION_QUALIFIER}")
+message(STATUS "JsonCpp Version: ${JSONCPP_VERSION_MAJOR}.${JSONCPP_VERSION_MINOR}.${JSONCPP_VERSION_PATCH}${JSONCPP_VERSION_QUALIFIER}")
 # File version.h is only regenerated on CMake configure step
-CONFIGURE_FILE( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
+configure_file( "${PROJECT_SOURCE_DIR}/src/lib_json/version.h.in"
                 "${PROJECT_SOURCE_DIR}/include/json/version.h" )
 
 macro(UseCompilationWarningAsError)
-	if ( MSVC )
+    if ( MSVC )
         # Only enabled in debug because some old versions of VS STL generate
         # warnings when compiled in release configuration.
-		set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
-	endif( MSVC )
-endmacro() 
+        set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
+    endif( MSVC )
+endmacro()
 
 # Include our configuration header
-INCLUDE_DIRECTORIES( ${CMAKE_SOURCE_DIR}/include )
+include_directories( ${CMAKE_SOURCE_DIR}/include )
 
 if ( MSVC )
     # Only enabled in debug because some old versions of VS STL generate
@@ -79,12 +74,12 @@ if ( MSVC )
     set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /W4 ")
 endif( MSVC )
 
-IF(JSONCPP_WITH_WARNING_AS_ERROR)
+if(JSONCPP_WITH_WARNING_AS_ERROR)
     UseCompilationWarningAsError()
-ENDIF(JSONCPP_WITH_WARNING_AS_ERROR)
+endif(JSONCPP_WITH_WARNING_AS_ERROR)
 
 # Build the different applications
-ADD_SUBDIRECTORY( src )
+add_subdirectory( src )
 
 #install the includes
-ADD_SUBDIRECTORY( include )
+add_subdirectory( include )
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index 7d832a0..01877ca 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -1,2 +1,2 @@
-FILE(GLOB INCLUDE_FILES "json/*.h")
-INSTALL(FILES ${INCLUDE_FILES} DESTINATION include/json)
+file(GLOB INCLUDE_FILES "json/*.h")
+install(FILES ${INCLUDE_FILES} DESTINATION include/json)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 608d3f7..45cc8a2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,5 @@
-ADD_SUBDIRECTORY(lib_json)
-IF(JSONCPP_WITH_TESTS)
-    ADD_SUBDIRECTORY(jsontestrunner)
-    ADD_SUBDIRECTORY(test_lib_json)
-ENDIF(JSONCPP_WITH_TESTS)
+add_subdirectory(lib_json)
+if(JSONCPP_WITH_TESTS)
+    add_subdirectory(jsontestrunner)
+    add_subdirectory(test_lib_json)
+endif(JSONCPP_WITH_TESTS)
diff --git a/src/jsontestrunner/CMakeLists.txt b/src/jsontestrunner/CMakeLists.txt
index 7ab2f00..9835e2d 100644
--- a/src/jsontestrunner/CMakeLists.txt
+++ b/src/jsontestrunner/CMakeLists.txt
@@ -1,23 +1,23 @@
-FIND_PACKAGE(PythonInterp 2.6 REQUIRED)
+find_package(PythonInterp 2.6 REQUIRED)
 
-IF(JSONCPP_LIB_BUILD_SHARED)
-  ADD_DEFINITIONS( -DJSON_DLL )
-ENDIF(JSONCPP_LIB_BUILD_SHARED)
+if(JSONCPP_LIB_BUILD_SHARED)
+    add_definitions( -DJSON_DLL )
+endif(JSONCPP_LIB_BUILD_SHARED)
 
-ADD_EXECUTABLE(jsontestrunner_exe
+add_executable(jsontestrunner_exe
                main.cpp
                )
-TARGET_LINK_LIBRARIES(jsontestrunner_exe jsoncpp_lib)
-SET_TARGET_PROPERTIES(jsontestrunner_exe PROPERTIES OUTPUT_NAME jsontestrunner_exe)
+target_link_libraries(jsontestrunner_exe jsoncpp_lib)
+set_target_properties(jsontestrunner_exe PROPERTIES OUTPUT_NAME jsontestrunner_exe)
 
-IF(PYTHONINTERP_FOUND)
+if(PYTHONINTERP_FOUND)
     # Run end to end parser/writer tests
-    GET_PROPERTY(JSONTESTRUNNER_EXE_PATH TARGET jsontestrunner_exe PROPERTY LOCATION)
-    SET(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../test)
-    SET(RUNJSONTESTS_PATH ${TEST_DIR}/runjsontests.py)
-    ADD_CUSTOM_TARGET(jsoncpp_readerwriter_tests ALL
+    get_property(JSONTESTRUNNER_EXE_PATH TARGET jsontestrunner_exe PROPERTY LOCATION)
+    set(TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../test)
+    set(RUNJSONTESTS_PATH ${TEST_DIR}/runjsontests.py)
+    add_custom_target(jsoncpp_readerwriter_tests ALL
                       "${PYTHON_EXECUTABLE}" -B "${RUNJSONTESTS_PATH}" "${JSONTESTRUNNER_EXE_PATH}" "${TEST_DIR}/data"
                       DEPENDS jsontestrunner_exe jsoncpp_test
                       )
-    ADD_CUSTOM_TARGET(jsoncpp_check DEPENDS jsoncpp_readerwriter_tests)
-ENDIF(PYTHONINTERP_FOUND)
+    add_custom_target(jsoncpp_check DEPENDS jsoncpp_readerwriter_tests)
+endif(PYTHONINTERP_FOUND)
diff --git a/src/lib_json/CMakeLists.txt b/src/lib_json/CMakeLists.txt
index 39aa0b3..790b695 100644
--- a/src/lib_json/CMakeLists.txt
+++ b/src/lib_json/CMakeLists.txt
@@ -1,15 +1,15 @@
-OPTION(JSONCPP_LIB_BUILD_SHARED "Build jsoncpp_lib as a shared library." OFF)
-IF(JSONCPP_LIB_BUILD_SHARED)
-  SET(JSONCPP_LIB_TYPE SHARED)
-  ADD_DEFINITIONS( -DJSON_DLL_BUILD )
-ELSE(JSONCPP_LIB_BUILD_SHARED)
-  SET(JSONCPP_LIB_TYPE STATIC)
-ENDIF(JSONCPP_LIB_BUILD_SHARED)
+option(JSONCPP_LIB_BUILD_SHARED "Build jsoncpp_lib as a shared library." OFF)
+if(JSONCPP_LIB_BUILD_SHARED)
+  set(JSONCPP_LIB_TYPE SHARED)
+  add_definitions( -DJSON_DLL_BUILD )
+else(JSONCPP_LIB_BUILD_SHARED)
+  set(JSONCPP_LIB_TYPE STATIC)
+endif(JSONCPP_LIB_BUILD_SHARED)
 
 
-SET( JSONCPP_INCLUDE_DIR ../../include )
+set( JSONCPP_INCLUDE_DIR ../../include )
 
-SET( PUBLIC_HEADERS
+set( PUBLIC_HEADERS
     ${JSONCPP_INCLUDE_DIR}/json/config.h
     ${JSONCPP_INCLUDE_DIR}/json/forwards.h
     ${JSONCPP_INCLUDE_DIR}/json/features.h
@@ -20,10 +20,10 @@ SET( PUBLIC_HEADERS
     ${JSONCPP_INCLUDE_DIR}/json/version.h
     )
 
-SOURCE_GROUP( "Public API" FILES ${PUBLIC_HEADERS} )
+source_group( "Public API" FILES ${PUBLIC_HEADERS} )
 
-ADD_LIBRARY( jsoncpp_lib ${JSONCPP_LIB_TYPE}
-             ${PUBLIC_HEADERS} 
+add_library( jsoncpp_lib ${JSONCPP_LIB_TYPE}
+             ${PUBLIC_HEADERS}
              json_tool.h
              json_reader.cpp
              json_batchallocator.h
@@ -32,11 +32,11 @@ ADD_LIBRARY( jsoncpp_lib ${JSONCPP_LIB_TYPE}
              json_writer.cpp
              version.h.in
              )
-SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp )
-SET_TARGET_PROPERTIES( jsoncpp_lib PROPERTIES VERSION ${JSON_CPP_VERSION} SOVERSION ${JSON_CPP_VERSION} )
+set_target_properties( jsoncpp_lib PROPERTIES OUTPUT_NAME jsoncpp )
+set_target_properties( jsoncpp_lib PROPERTIES VERSION ${JSON_CPP_VERSION} SOVERSION ${JSON_CPP_VERSION} )
 
 # Install instructions for this target
-INSTALL( TARGETS jsoncpp_lib
+install( TARGETS jsoncpp_lib
          RUNTIME DESTINATION bin
          LIBRARY DESTINATION lib
          ARCHIVE DESTINATION lib
diff --git a/src/test_lib_json/CMakeLists.txt b/src/test_lib_json/CMakeLists.txt
index 7fb5602..592e44b 100644
--- a/src/test_lib_json/CMakeLists.txt
+++ b/src/test_lib_json/CMakeLists.txt
@@ -1,22 +1,21 @@
+if(JSONCPP_LIB_BUILD_SHARED)
+    add_definitions( -DJSON_DLL )
+endif(JSONCPP_LIB_BUILD_SHARED)
 
-IF(JSONCPP_LIB_BUILD_SHARED)
-  ADD_DEFINITIONS( -DJSON_DLL )
-ENDIF(JSONCPP_LIB_BUILD_SHARED)
-
-ADD_EXECUTABLE( jsoncpp_test 
+add_executable( jsoncpp_test
                 jsontest.cpp
                 jsontest.h
                 main.cpp
                 )
 
-TARGET_LINK_LIBRARIES(jsoncpp_test jsoncpp_lib)
+target_link_libraries(jsoncpp_test jsoncpp_lib)
 
 # Run unit tests in post-build
 # (default cmake workflow hides away the test result into a file, resulting in poor dev workflow?!?)
-IF(JSONCPP_WITH_POST_BUILD_UNITTEST)
-    ADD_CUSTOM_COMMAND( TARGET jsoncpp_test
-				        POST_BUILD
-				        COMMAND jsoncpp_test)
-ENDIF(JSONCPP_WITH_POST_BUILD_UNITTEST)
+if(JSONCPP_WITH_POST_BUILD_UNITTEST)
+    add_custom_command( TARGET jsoncpp_test
+                        POST_BUILD
+                        COMMAND jsoncpp_test)
+endif(JSONCPP_WITH_POST_BUILD_UNITTEST)
 
-SET_TARGET_PROPERTIES(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test) 
+set_target_properties(jsoncpp_test PROPERTIES OUTPUT_NAME jsoncpp_test)
-- 
1.8.3.2

