Skip to content

Commit

Permalink
Better CMake variable expansion usage in if.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 28a5d6bbab13a9eacf9b1b8f0ac8eeff1be21556
  • Loading branch information
levlam committed Apr 4, 2019
1 parent 078417d commit e785ac6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 18 deletions.
2 changes: 1 addition & 1 deletion CMake/AddCXXCompilerFlag.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function(add_required_cxx_compiler_flag FLAG)
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}")
check_cxx_compiler_flag("${MAIN_FLAG}" ${MANGLED_FLAG})
set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
if (${MANGLED_FLAG})
if (MANGLED_FLAG)
set(VARIANT ${ARGV1})
if (ARGV1)
string(TOUPPER "_${VARIANT}" VARIANT)
Expand Down
16 changes: 8 additions & 8 deletions CMake/iOS.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ endif (NOT DEFINED IOS_PLATFORM)
set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")

# Check the platform selection and setup for developer root
if (${IOS_PLATFORM} STREQUAL "OS")
if (IOS_PLATFORM STREQUAL "OS")
set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
set (XCODE_IOS_PLATFORM iphoneos)

# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")

set (APPLE_IOS True)
elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
set (SIMULATOR_FLAG true)
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
set (XCODE_IOS_PLATFORM iphonesimulator)
Expand All @@ -76,15 +76,15 @@ elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")

set (APPLE_IOS True)
elseif (${IOS_PLATFORM} STREQUAL "WATCHOS")
elseif (IOS_PLATFORM STREQUAL "WATCHOS")
set (IOS_PLATFORM_LOCATION "WatchOS.platform")
set (XCODE_IOS_PLATFORM watchos)

# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-watchos")

set (APPLE_WATCH True)
elseif (${IOS_PLATFORM} STREQUAL "WATCHSIMULATOR")
elseif (IOS_PLATFORM STREQUAL "WATCHSIMULATOR")
set (SIMULATOR_FLAG true)
set (IOS_PLATFORM_LOCATION "WatchSimulator.platform")
set (XCODE_IOS_PLATFORM watchsimulator)
Expand All @@ -93,15 +93,15 @@ elseif (${IOS_PLATFORM} STREQUAL "WATCHSIMULATOR")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-watchsimulator")

set (APPLE_WATCH True)
elseif (${IOS_PLATFORM} STREQUAL "TVOS")
elseif (IOS_PLATFORM STREQUAL "TVOS")
set (IOS_PLATFORM_LOCATION "AppleTvOS.platform")
set (XCODE_IOS_PLATFORM tvos)

# This causes the installers to properly locate the output libraries
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-appletvos")

set (APPLE_TV True)
elseif (${IOS_PLATFORM} STREQUAL "TVSIMULATOR")
elseif (IOS_PLATFORM STREQUAL "TVSIMULATOR")
set (SIMULATOR_FLAG true)
set (IOS_PLATFORM_LOCATION "AppleTvSimulator.platform")
set (XCODE_IOS_PLATFORM tvsimulator)
Expand All @@ -110,7 +110,7 @@ elseif (${IOS_PLATFORM} STREQUAL "TVSIMULATOR")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-tvsimulator")

set (APPLE_TV True)
else (${IOS_PLATFORM} STREQUAL "OS")
else (IOS_PLATFORM STREQUAL "OS")
message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS, SIMULATOR, or WATCHOS.")
endif ()

Expand Down Expand Up @@ -168,7 +168,7 @@ set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer"
if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
if (EXISTS ${XCODE_POST_43_ROOT})
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
elseif(EXISTS ${XCODE_PRE_43_ROOT})
elseif (EXISTS ${XCODE_PRE_43_ROOT})
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
endif (EXISTS ${XCODE_POST_43_ROOT})
endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
Expand Down
15 changes: 10 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)

project(TDLib VERSION 1.3.6 LANGUAGES CXX C)

if (POLICY CMP0054)
# do not expand quoted arguments
cmake_policy(SET CMP0054 NEW)
endif()

# Prevent in-source build
get_filename_component(TD_REAL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
get_filename_component(TD_REAL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" REALPATH)
Expand Down Expand Up @@ -105,11 +110,11 @@ if (OPENSSL_FOUND)
message(STATUS "Found OpenSSL: ${OPENSSL_INCLUDE_DIR} ${OPENSSL_LIBRARIES}")
endif()

if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(GCC 1)
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CLANG 1)
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Intel)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(INTEL 1)
elseif (NOT MSVC)
message(FATAL_ERROR "Compiler isn't supported")
Expand Down Expand Up @@ -669,7 +674,7 @@ if (MEMPROF)
target_compile_definitions(memprof PRIVATE -DUSE_MEMPROF_SAFE=1)
elseif (MEMPROF STREQUAL "FAST")
target_compile_definitions(memprof PRIVATE -DUSE_MEMPROF_FAST=1)
elseif (NOT ${MEMPROF})
elseif (NOT MEMPROF)
message(FATAL_ERROR "Unsupported MEMPROF value \"${MEMPROF}\"")
endif()
endif()
Expand Down Expand Up @@ -729,7 +734,7 @@ if (TD_ENABLE_DOTNET)
endif()

target_compile_options(tddotnet PRIVATE "/doc")
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
if (CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
set_target_properties(tddotnet PROPERTIES VS_WINRT_COMPONENT "true")
target_compile_options(tddotnet PUBLIC "/ZW")
else()
Expand Down
11 changes: 8 additions & 3 deletions example/java/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)

project(TdJavaExample VERSION 1.0 LANGUAGES CXX)

if (POLICY CMP0054)
# do not expand quoted arguments
cmake_policy(SET CMP0054 NEW)
endif()

find_package(Td REQUIRED)

if (NOT JNI_FOUND)
Expand Down Expand Up @@ -58,11 +63,11 @@ target_include_directories(tdjni PRIVATE ${JAVA_INCLUDE_PATH} ${JAVA_INCLUDE_PAT
target_link_libraries(tdjni PRIVATE Td::TdStatic ${JAVA_JVM_LIBRARY})
target_compile_definitions(tdjni PRIVATE PACKAGE_NAME="${TD_API_JAVA_PACKAGE}")

if (${CMAKE_CXX_COMPILER_ID} STREQUAL GNU)
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(GCC 1)
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CLANG 1)
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL Intel)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
set(INTEL 1)
elseif (NOT MSVC)
message(FATAL_ERROR "Compiler isn't supported")
Expand Down
2 changes: 1 addition & 1 deletion sqlite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (NOT WIN32)
target_compile_definitions(tdsqlite PRIVATE -DHAVE_USLEEP -DNDEBUG=1)
endif()

if ("${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore")
if (CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
target_compile_definitions(tdsqlite PRIVATE -DSQLITE_OS_WINRT=1)
endif()

Expand Down

0 comments on commit e785ac6

Please sign in to comment.