Skip to content

Commit

Permalink
CMake modernization/cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wravery committed Dec 3, 2021
1 parent c614893 commit 733e100
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 33 deletions.
11 changes: 4 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.15")
# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows.
set(MSVC_MATCH_VCPKG_TRIPLET ON)
cmake_policy(SET CMP0091 NEW)
endif()
# Enable CMAKE_MSVC_RUNTIME_LIBRARY on Windows: https://cmake.org/cmake/help/latest/policy/CMP0091.html
cmake_policy(SET CMP0091 NEW)

# Default to the last updated version from version.txt.
file(TO_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.txt" VERSION_FILE)
Expand Down Expand Up @@ -43,7 +40,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries instead of static libs" OFF)
if(VCPKG_TARGET_TRIPLET)
message(STATUS "Using ${VCPKG_TARGET_TRIPLET} triplet with vcpkg")

if(MSVC AND MSVC_MATCH_VCPKG_TRIPLET)
if(MSVC)
# Match the MSVC runtime if we're using VCPKG with static libraries.
if(VCPKG_TARGET_TRIPLET MATCHES [[^.+-static$]])
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Expand Down
2 changes: 1 addition & 1 deletion cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Enable version checks in find_package
include(CMakePackageConfigHelpers)
Expand Down
4 changes: 3 additions & 1 deletion cmake/cppgraphqlgen-update-client-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ if(NOT FILE_NAMES)
message(FATAL_ERROR "Schema generation failed!")
endif()

# Remove stale files in the source directory
# Support if() IN_LIST operator: https://cmake.org/cmake/help/latest/policy/CMP0057.html
cmake_policy(SET CMP0057 NEW)

# Remove stale files in the source directory
file(GLOB OLD_FILES ${CLIENT_SOURCE_DIR}/*.h ${CLIENT_SOURCE_DIR}/*.cpp)
foreach(OLD_FILE ${OLD_FILES})
get_filename_component(OLD_FILE ${OLD_FILE} NAME)
Expand Down
4 changes: 3 additions & 1 deletion cmake/cppgraphqlgen-update-schema-files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ if(NOT FILE_NAMES)
message(FATAL_ERROR "Schema generation failed!")
endif()

# Remove stale files in the source directory
# Support if() IN_LIST operator: https://cmake.org/cmake/help/latest/policy/CMP0057.html
cmake_policy(SET CMP0057 NEW)

# Remove stale files in the source directory
file(GLOB OLD_FILES ${SCHEMA_SOURCE_DIR}/*.h ${SCHEMA_SOURCE_DIR}/*.cpp)
foreach(OLD_FILE ${OLD_FILES})
get_filename_component(OLD_FILE ${OLD_FILE} NAME)
Expand Down
2 changes: 1 addition & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

add_subdirectory(client)
add_subdirectory(learn)
Expand Down
2 changes: 1 addition & 1 deletion samples/client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

add_subdirectory(query)
add_subdirectory(mutate)
Expand Down
2 changes: 1 addition & 1 deletion samples/client/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/client/mutate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/client/query/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/client/subscribe/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/learn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

add_subdirectory(schema)
add_library(star_wars STATIC
Expand Down
2 changes: 1 addition & 1 deletion samples/learn/schema/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/today/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# separategraphql
add_subdirectory(separate)
Expand Down
2 changes: 1 addition & 1 deletion samples/today/separate/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/today/separate_nointrospection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/today/unified/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/today/unified_nointrospection/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
2 changes: 1 addition & 1 deletion samples/validation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

if(GRAPHQL_BUILD_TESTS)
add_subdirectory(schema)
Expand Down
2 changes: 1 addition & 1 deletion samples/validation/schema/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

# Normally this would be handled by find_package(cppgraphqlgen CONFIG).
include(${CMAKE_CURRENT_SOURCE_DIR}/../../../cmake/cppgraphqlgen-functions.cmake)
Expand Down
14 changes: 7 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

if(GRAPHQL_UPDATE_VERSION)
# internal/Version.h
Expand Down Expand Up @@ -74,7 +74,7 @@ function(check_coroutine_impl COROUTINE_HEADER COROUTINE_NAMESPACE OPTIONAL_FLAG
CXX_STANDARD 20)

if(NOT TEST_RESULT)
# Retry with each of the optional libraries.
# Retry with each of the optional flags.
foreach(OPTIONAL_FLAG IN LISTS OPTIONAL_FLAGS)
try_compile(TEST_RESULT
${CMAKE_CURRENT_BINARY_DIR}
Expand Down Expand Up @@ -347,9 +347,9 @@ add_library(graphqlservice
Validation.cpp)
add_library(cppgraphqlgen::graphqlservice ALIAS graphqlservice)
target_link_libraries(graphqlservice PUBLIC
graphqlpeg
graphqlresponse
Threads::Threads)
graphqlpeg
graphqlresponse
Threads::Threads)

if(GRAPHQL_UPDATE_SAMPLES)
# Even though this target doesn't build IntrospectionSchema.cpp, it still
Expand Down Expand Up @@ -396,8 +396,8 @@ endif()
add_library(graphqlclient GraphQLClient.cpp)
add_library(cppgraphqlgen::graphqlclient ALIAS graphqlclient)
target_link_libraries(graphqlclient PUBLIC
graphqlpeg
graphqlresponse)
graphqlpeg
graphqlresponse)

if(GRAPHQL_UPDATE_VERSION)
update_version_rc(graphqlclient)
Expand Down
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.8.2)
cmake_minimum_required(VERSION 3.15)

find_package(GTest MODULE REQUIRED)

Expand Down

0 comments on commit 733e100

Please sign in to comment.