Skip to content

Commit

Permalink
Use precompiled header from cmake 3.16.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Nov 17, 2019
1 parent 61723bd commit e5bd187
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 121 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.16)
cmake_policy(SET CMP0076 NEW)
cmake_policy(SET CMP0091 NEW)

Expand All @@ -12,7 +12,7 @@ project(Telegram
)

include(cmake/paths.cmake)
include(cmake/force_include.cmake)
include(cmake/options.cmake)
include(cmake/init_target.cmake)
include(cmake/generate_target.cmake)
include(cmake/nice_target_sources.cmake)
Expand Down
16 changes: 15 additions & 1 deletion Telegram/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
add_executable(Telegram WIN32 MACOSX_BUNDLE)
init_target(Telegram)

add_executable(Updater WIN32)
init_target(Updater)

add_subdirectory(lib_rpl)
add_subdirectory(lib_crl)
add_subdirectory(lib_base)
Expand Down Expand Up @@ -939,7 +942,7 @@ PRIVATE
)
nice_target_sources(Telegram ${res_loc} "${telegram_resources}")

force_include(Telegram stdafx.h)
target_precompile_headers(Telegram PRIVATE ${src_loc}/stdafx.h)

if (WIN32)
# message(${CMAKE_GENERATOR})
Expand Down Expand Up @@ -980,3 +983,14 @@ PRIVATE
AL_LIBTYPE_STATIC
AL_ALEXT_PROTOTYPES
)

add_dependencies(Telegram Updater)

set(updater_sources
PRIVATE
_other/updater.cpp
_other/updater.h
_other/updater_linux.cpp
_other/updater_osx.m
)
nice_target_sources(Updater ${src_loc} "${updater_sources}")
2 changes: 1 addition & 1 deletion Telegram/cmake/lib_export.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ PRIVATE
)
nice_target_sources(lib_export ${src_loc} "${lib_export_sources}")

force_include(lib_export export/export_pch.h)
target_precompile_headers(lib_export PRIVATE ${src_loc}/export/export_pch.h)

target_include_directories(lib_export
PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion Telegram/cmake/lib_mtproto.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PRIVATE
)
nice_target_sources(lib_mtproto ${src_loc} "${lib_mtproto_sources}")

force_include(lib_mtproto mtproto/mtp_pch.h)
target_precompile_headers(lib_mtproto PRIVATE ${src_loc}/mtproto/mtp_pch.h)

target_include_directories(lib_mtproto
PUBLIC
Expand Down
2 changes: 1 addition & 1 deletion Telegram/cmake/lib_tgvoip.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
add_library(lib_tgvoip OBJECT)
init_target_no_ranges(lib_tgvoip)
init_target(lib_tgvoip)

set(tgvoip_loc ${third_party_loc}/libtgvoip)

Expand Down
2 changes: 1 addition & 1 deletion Telegram/lib_base
Submodule lib_base updated 1 files
+1 −1 CMakeLists.txt
2 changes: 1 addition & 1 deletion Telegram/lib_crl
Submodule lib_crl updated 1 files
+0 −1 CMakeLists.txt
2 changes: 1 addition & 1 deletion Telegram/lib_spellcheck
Submodule lib_spellcheck updated 1 files
+1 −1 CMakeLists.txt
2 changes: 1 addition & 1 deletion Telegram/lib_storage
Submodule lib_storage updated 1 files
+1 −1 CMakeLists.txt
2 changes: 1 addition & 1 deletion Telegram/lib_ui
Submodule lib_ui updated 1 files
+1 −1 CMakeLists.txt
94 changes: 0 additions & 94 deletions cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,95 +1 @@
add_subdirectory(external)

add_library(with_ranges INTERFACE)

if (WIN32)
target_compile_options(with_ranges
INTERFACE
/experimental:preprocessor # need for range-v3 see https://github.com/ericniebler/range-v3#supported-compilers
/wd5105 # needed for `/experimental:preprocessor`, suppressing C5105 "macro expansion producing 'defined' has undefined behavior"
)
endif()

add_library(common_no_ranges INTERFACE)

target_compile_features(common_no_ranges
INTERFACE
cxx_std_17
)

target_compile_definitions(common_no_ranges
INTERFACE
UNICODE
)

if (WIN32)
target_compile_definitions(common_no_ranges
INTERFACE
WIN32
_WINDOWS
_UNICODE
UNICODE
_SCL_SECURE_NO_WARNINGS
_USING_V110_SDK71_
NOMINMAX
)
target_compile_options(common_no_ranges
INTERFACE
/permissive-
# /Qspectre
/W1
/WX
/MP # Enable multi process build.
/EHsc # Catch C++ exceptions only, extern C functions never throw a C++ exception.
/w14834 # [[nodiscard]]
/w15038 # wrong initialization order
/w14265 # class has virtual functions, but destructor is not virtual
/wd4068 # Disable "warning C4068: unknown pragma"
/wd5105 # needed for `/experimental:preprocessor`, suppressing C5105 "macro expansion producing 'defined' has undefined behavior"
/Zc:wchar_t- # don't tread wchar_t as builtin type
)
target_link_options(common_no_ranges
INTERFACE
/NODEFAULTLIB:LIBCMT
)
target_link_libraries(common_no_ranges
INTERFACE
winmm
imm32
ws2_32
kernel32
user32
gdi32
winspool
comdlg32
advapi32
shell32
ole32
oleaut32
uuid
odbc32
odbccp32
Shlwapi
Iphlpapi
Gdiplus
Strmiids
Netapi32
Userenv
Version
Dwmapi
Wtsapi32
UxTheme
DbgHelp
Rstrtmgr
Crypt32
)
else()
endif()

add_library(common INTERFACE)

target_link_libraries(common
INTERFACE
common_no_ranges
with_ranges
)
8 changes: 8 additions & 0 deletions cmake/external/ranges/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ target_include_directories(external_ranges SYSTEM
INTERFACE
${libs_loc}/range-v3/include
)

if (WIN32)
target_compile_options(external_ranges
INTERFACE
/experimental:preprocessor # need for range-v3 see https://github.com/ericniebler/range-v3#supported-compilers
/wd5105 # needed for `/experimental:preprocessor`, suppressing C5105 "macro expansion producing 'defined' has undefined behavior"
)
endif()
18 changes: 4 additions & 14 deletions cmake/init_target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@ function(init_target_folder target_name folder_name)
endif()
endfunction()

function(init_target_no_ranges target_name) # init_target(my_target folder_name)
function(init_target target_name) # init_target(my_target folder_name)
init_target_folder(${target_name} "${ARGV1}")
set_property(TARGET ${target_name} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
if (WIN32)
target_compile_options(${target_name}
INTERFACE
/W1
)
set_property(TARGET ${target_name} PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
target_link_libraries(${target_name} PUBLIC common_no_ranges)
endfunction()

function(init_target target_name) # init_target(my_target folder_name)
init_target_folder(${target_name} "${ARGV1}")
init_target_no_ranges(${target_name})
target_link_libraries(${target_name} PUBLIC common)
target_link_libraries(${target_name} PUBLIC common_options)
endfunction()

2 changes: 1 addition & 1 deletion cmake/nice_target_sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function(nice_target_sources target_name src_loc list)
if (${file} MATCHES "(^|/)win/" OR ${file} MATCHES "(^|/)winrc/" OR ${file} MATCHES "(^|/)windows/" OR ${file} MATCHES "[_\\/]win\\.")
list(APPEND not_mac_sources ${full_name})
list(APPEND not_linux_sources ${full_name})
elseif (${file} MATCHES "(^|/)mac/" OR ${file} MATCHES "(^|/)darwin/" OR ${file} MATCHES "[_\\/]mac\\.")
elseif (${file} MATCHES "(^|/)mac/" OR ${file} MATCHES "(^|/)darwin/" OR ${file} MATCHES "(^|/)osx/" OR ${file} MATCHES "[_\\/]mac\\." OR ${file} MATCHES "[_\\/]darwin\\." OR ${file} MATCHES "[_\\/]osx\\.")
list(APPEND not_win_sources ${full_name})
list(APPEND not_linux_sources ${full_name})
elseif (${file} MATCHES "(^|/)linux/" OR ${file} MATCHES "[_\\/]linux\\.")
Expand Down
16 changes: 16 additions & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
add_library(common_options INTERFACE)

target_compile_features(common_options
INTERFACE
cxx_std_17
)

target_compile_definitions(common_options
INTERFACE
UNICODE
)

if (WIN32)
include(cmake/options_win.cmake)
else()
endif()
61 changes: 61 additions & 0 deletions cmake/options_win.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
target_compile_definitions(common_options
INTERFACE
WIN32
_WINDOWS
_UNICODE
UNICODE
_SCL_SECURE_NO_WARNINGS
_USING_V110_SDK71_
NOMINMAX
)
target_compile_options(common_options
INTERFACE
/permissive-
# /Qspectre
/W1
/WX
/MP # Enable multi process build.
/EHsc # Catch C++ exceptions only, extern C functions never throw a C++ exception.
/w14834 # [[nodiscard]]
/w15038 # wrong initialization order
/w14265 # class has virtual functions, but destructor is not virtual
/wd4068 # Disable "warning C4068: unknown pragma"
/Zc:wchar_t- # don't tread wchar_t as builtin type
)

target_link_options(common_options
INTERFACE
/NODEFAULTLIB:LIBCMT
)

target_link_libraries(common_options
INTERFACE
winmm
imm32
ws2_32
kernel32
user32
gdi32
winspool
comdlg32
advapi32
shell32
ole32
oleaut32
uuid
odbc32
odbccp32
Shlwapi
Iphlpapi
Gdiplus
Strmiids
Netapi32
Userenv
Version
Dwmapi
Wtsapi32
UxTheme
DbgHelp
Rstrtmgr
Crypt32
)

0 comments on commit e5bd187

Please sign in to comment.