2019-11-23 20:27:39 +08:00
include ( CMakeParseArguments )
# copy resource `FILES` and `FOLDERS` to TARGET_FILE_DIR/Resources
2023-02-22 23:37:32 +08:00
function ( ax_sync_target_res ax_target )
2023-02-23 21:57:30 +08:00
set ( options SYM_LINK )
set ( oneValueArgs LINK_TO SYNC_TARGET_ID )
set ( multiValueArgs FOLDERS )
cmake_parse_arguments ( opt "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
if ( NOT DEFINED opt_SYNC_TARGET_ID )
set ( sync_target_name "SYNC_RESOURCE-${ax_target}" )
else ( )
set ( sync_target_name "SYNC_RESOURCE-${ax_target}-${opt_SYNC_TARGET_ID}" )
endif ( )
2019-11-23 20:27:39 +08:00
2023-02-23 21:57:30 +08:00
ax_def_sync_resource_target ( ${ ax_target } ${ sync_target_name } )
if ( NOT TARGET ${ sync_target_name } )
2022-08-11 15:41:10 +08:00
message ( WARNING "SyncResource targe for ${ax_target} is not defined" )
2019-11-23 20:27:39 +08:00
return ( )
endif ( )
# linking folders
foreach ( cc_folder ${ opt_FOLDERS } )
#get_filename_component(link_folder ${opt_LINK_TO} DIRECTORY)
get_filename_component ( link_folder_abs ${ opt_LINK_TO } ABSOLUTE )
2023-02-23 21:57:30 +08:00
add_custom_command ( TARGET ${ sync_target_name } POST_BUILD
2023-07-07 19:31:46 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E e c h o " S y n c i n g $ { c c _ f o l d e r } t o $ { l i n k _ f o l d e r _ a b s } "
2023-07-06 16:09:54 +08:00
C O M M A N D $ { P Y T H O N _ C O M M A N D } A R G S $ { _ A X _ R O O T } / c m a k e / s c r i p t s / s y n c _ f o l d e r . p y
2023-02-22 23:37:32 +08:00
- s $ { c c _ f o l d e r } - d $ { l i n k _ f o l d e r _ a b s } - l $ { o p t _ S Y M _ L I N K }
2019-11-23 20:27:39 +08:00
)
endforeach ( )
endfunction ( )
2022-08-11 15:41:10 +08:00
## create a virtual target SYNC_RESOURCE-${ax_target}
2019-11-23 20:27:39 +08:00
## Update resource files in Resources/ folder everytime when `Run/Debug` target.
2023-02-23 21:57:30 +08:00
function ( ax_def_sync_resource_target ax_target sync_target_name )
add_custom_target ( ${ sync_target_name } ALL
2023-02-22 23:37:32 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E e c h o " S y n c i n g r e s o u r c e s f o r $ { a x _ t a r g e t } . . . "
2019-11-23 20:27:39 +08:00
)
2023-02-23 21:57:30 +08:00
add_dependencies ( ${ ax_target } ${ sync_target_name } )
set_target_properties ( ${ sync_target_name } PROPERTIES
2019-11-23 20:27:39 +08:00
F O L D E R U t i l s
)
endfunction ( )
2023-02-22 23:37:32 +08:00
function ( ax_sync_lua_scripts ax_target src_dir dst_dir )
2022-08-11 15:41:10 +08:00
set ( luacompile_target COPY_LUA- ${ ax_target } )
2019-11-23 20:27:39 +08:00
if ( NOT TARGET ${ luacompile_target } )
add_custom_target ( ${ luacompile_target } ALL
2023-02-22 23:37:32 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E e c h o " S y n c i n g l u a s c r i p t s . . . "
2019-11-23 20:27:39 +08:00
)
2022-08-11 15:41:10 +08:00
add_dependencies ( ${ ax_target } ${ luacompile_target } )
2019-11-23 20:27:39 +08:00
set_target_properties ( ${ luacompile_target } PROPERTIES
F O L D E R U t i l s
)
endif ( )
if ( MSVC )
add_custom_command ( TARGET ${ luacompile_target } POST_BUILD
2023-07-06 16:09:54 +08:00
C O M M A N D $ { P Y T H O N _ C O M M A N D } A R G S $ { _ A X _ R O O T } / c m a k e / s c r i p t s / s y n c _ f o l d e r . p y
2021-05-24 19:18:15 +08:00
- s $ { s r c _ d i r } - d $ { d s t _ d i r } - m $ < C O N F I G >
2019-11-23 20:27:39 +08:00
)
else ( )
if ( "${CMAKE_BUILD_TYPE}" STREQUAL "" )
add_custom_command ( TARGET ${ luacompile_target } POST_BUILD
2023-07-06 16:09:54 +08:00
C O M M A N D $ { P Y T H O N _ C O M M A N D } A R G S $ { _ A X _ R O O T } / c m a k e / s c r i p t s / s y n c _ f o l d e r . p y
2019-11-23 20:27:39 +08:00
- s $ { s r c _ d i r } - d $ { d s t _ d i r }
)
else ( )
add_custom_command ( TARGET ${ luacompile_target } POST_BUILD
2023-07-06 16:09:54 +08:00
C O M M A N D $ { P Y T H O N _ C O M M A N D } A R G S $ { _ A X _ R O O T } / c m a k e / s c r i p t s / s y n c _ f o l d e r . p y
2021-05-24 19:18:15 +08:00
- s $ { s r c _ d i r } - d $ { d s t _ d i r } - m $ { C M A K E _ B U I L D _ T Y P E }
2019-11-23 20:27:39 +08:00
)
endif ( )
endif ( )
endfunction ( )
2022-08-11 15:41:10 +08:00
function ( ax_get_resource_path output ax_target )
get_target_property ( rt_output ${ ax_target } RUNTIME_OUTPUT_DIRECTORY )
2023-02-23 21:57:30 +08:00
set ( ${ output } "${rt_output}/${CMAKE_CFG_INTDIR}/Content" PARENT_SCOPE )
2019-11-23 20:27:39 +08:00
endfunction ( )
# mark `FILES` and files in `FOLDERS` as resource files, the destination is `RES_TO` folder
# save all marked files in `res_out`
2022-08-11 15:41:10 +08:00
function ( ax_mark_multi_resources res_out )
2019-11-23 20:27:39 +08:00
set ( oneValueArgs RES_TO )
set ( multiValueArgs FILES FOLDERS )
cmake_parse_arguments ( opt "" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
set ( tmp_file_list )
foreach ( cc_file ${ opt_FILES } )
get_filename_component ( cc_file_abs ${ cc_file } ABSOLUTE )
get_filename_component ( file_dir ${ cc_file_abs } DIRECTORY )
2022-08-11 15:41:10 +08:00
ax_mark_resources ( FILES ${ cc_file_abs } BASEDIR ${ file_dir } RESOURCEBASE ${ opt_RES_TO } )
2019-11-23 20:27:39 +08:00
endforeach ( )
list ( APPEND tmp_file_list ${ opt_FILES } )
foreach ( cc_folder ${ opt_FOLDERS } )
file ( GLOB_RECURSE folder_files "${cc_folder}/*" )
list ( APPEND tmp_file_list ${ folder_files } )
2022-08-11 15:41:10 +08:00
ax_mark_resources ( FILES ${ folder_files } BASEDIR ${ cc_folder } RESOURCEBASE ${ opt_RES_TO } )
2019-11-23 20:27:39 +08:00
endforeach ( )
set ( ${ res_out } ${ tmp_file_list } PARENT_SCOPE )
endfunction ( )
# get all linked libraries including transitive ones, recursive
2022-08-11 15:41:10 +08:00
function ( search_depend_libs_recursive ax_target all_depends_out )
2019-11-23 20:27:39 +08:00
set ( all_depends_inner )
2022-08-11 15:41:10 +08:00
set ( targets_prepare_search ${ ax_target } )
2019-11-23 20:27:39 +08:00
while ( true )
foreach ( tmp_target ${ targets_prepare_search } )
get_target_property ( target_type ${ tmp_target } TYPE )
if ( ${ target_type } STREQUAL "SHARED_LIBRARY" OR ${ target_type } STREQUAL "STATIC_LIBRARY" OR ${ target_type } STREQUAL "MODULE_LIBRARY" OR ${ target_type } STREQUAL "EXECUTABLE" )
get_target_property ( tmp_depend_libs ${ tmp_target } LINK_LIBRARIES )
list ( REMOVE_ITEM targets_prepare_search ${ tmp_target } )
list ( APPEND tmp_depend_libs ${ tmp_target } )
foreach ( depend_lib ${ tmp_depend_libs } )
if ( TARGET ${ depend_lib } )
list ( APPEND all_depends_inner ${ depend_lib } )
if ( NOT ( depend_lib STREQUAL tmp_target ) )
list ( APPEND targets_prepare_search ${ depend_lib } )
endif ( )
endif ( )
endforeach ( )
else ( )
list ( REMOVE_ITEM targets_prepare_search ${ tmp_target } )
endif ( )
endforeach ( )
list ( LENGTH targets_prepare_search targets_prepare_search_size )
if ( targets_prepare_search_size LESS 1 )
break ( )
endif ( )
endwhile ( true )
2021-05-05 14:04:06 +08:00
list ( REMOVE_DUPLICATES all_depends_inner )
2019-11-23 20:27:39 +08:00
set ( ${ all_depends_out } ${ all_depends_inner } PARENT_SCOPE )
endfunction ( )
2022-08-11 15:41:10 +08:00
# get `ax_target` depend all dlls, save the result in `all_depend_dlls_out`
function ( get_target_depends_ext_dlls ax_target all_depend_dlls_out )
2019-11-23 20:27:39 +08:00
set ( depend_libs )
set ( all_depend_ext_dlls )
2022-08-11 15:41:10 +08:00
search_depend_libs_recursive ( ${ ax_target } depend_libs )
2019-11-23 20:27:39 +08:00
foreach ( depend_lib ${ depend_libs } )
if ( TARGET ${ depend_lib } )
get_target_property ( target_type ${ depend_lib } TYPE )
if ( ${ target_type } STREQUAL "SHARED_LIBRARY" OR ${ target_type } STREQUAL "STATIC_LIBRARY" OR ${ target_type } STREQUAL "MODULE_LIBRARY" OR ${ target_type } STREQUAL "EXECUTABLE" )
get_target_property ( found_shared_lib ${ depend_lib } IMPORTED_IMPLIB )
if ( found_shared_lib )
get_target_property ( tmp_dlls ${ depend_lib } IMPORTED_LOCATION )
list ( APPEND all_depend_ext_dlls ${ tmp_dlls } )
endif ( )
endif ( )
endif ( )
endforeach ( )
2021-05-05 14:04:06 +08:00
list ( REMOVE_DUPLICATES all_depend_ext_dlls )
2019-11-23 20:27:39 +08:00
set ( ${ all_depend_dlls_out } ${ all_depend_ext_dlls } PARENT_SCOPE )
endfunction ( )
2020-10-17 16:32:16 +08:00
2022-08-11 15:41:10 +08:00
# copy the `ax_target` needed dlls into TARGET_FILE_DIR
function ( ax_copy_target_dll ax_target )
get_target_depends_ext_dlls ( ${ ax_target } all_depend_dlls )
2023-03-11 22:10:18 +08:00
2019-11-23 20:27:39 +08:00
# remove repeat items
if ( all_depend_dlls )
list ( REMOVE_DUPLICATES all_depend_dlls )
endif ( )
foreach ( cc_dll_file ${ all_depend_dlls } )
get_filename_component ( cc_dll_name ${ cc_dll_file } NAME )
2022-08-11 15:41:10 +08:00
add_custom_command ( TARGET ${ ax_target } POST_BUILD
2019-11-23 20:27:39 +08:00
#COMMAND ${CMAKE_COMMAND} -E echo "copy dll into target file dir: ${cc_dll_name} ..."
2022-08-11 15:41:10 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t $ { c c _ d l l _ f i l e } " $ < T A R G E T _ F I L E _ D I R : $ { a x _ t a r g e t } > / $ { c c _ d l l _ n a m e } "
2019-11-23 20:27:39 +08:00
)
endforeach ( )
2020-08-04 14:05:00 +08:00
2020-10-17 16:32:16 +08:00
# copy thirdparty dlls to target bin dir
2023-04-02 16:04:19 +08:00
if ( NOT CMAKE_GENERATOR MATCHES "Ninja" )
2022-08-19 19:52:10 +08:00
set ( BUILD_CONFIG_DIR "\$\(Configuration\)/" )
2022-04-26 15:16:02 +08:00
endif ( )
2020-10-17 16:32:16 +08:00
2023-01-06 19:11:10 +08:00
add_custom_command ( TARGET ${ ax_target } POST_BUILD
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y $ < T A R G E T _ R U N T I M E _ D L L S : $ { a x _ t a r g e t } > $ < T A R G E T _ F I L E _ D I R : $ { a x _ t a r g e t } >
C O M M A N D _ E X P A N D _ L I S T S
)
2023-01-06 18:38:16 +08:00
2021-09-01 10:28:37 +08:00
# Copy windows angle binaries
2023-08-25 16:49:08 +08:00
if ( WIN32 AND AX_GLES_PROFILE )
2022-09-02 19:24:22 +08:00
add_custom_command ( TARGET ${ ax_target } POST_BUILD
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t
2023-07-06 16:09:54 +08:00
$ { _ A X _ R O O T } / $ { _ A X _ T H I R D P A R T Y _ N A M E } / a n g l e / p r e b u i l t / $ { p l a t f o r m _ n a m e } / $ { A R C H _ A L I A S } / l i b G L E S v 2 . d l l
$ { _ A X _ R O O T } / $ { _ A X _ T H I R D P A R T Y _ N A M E } / a n g l e / p r e b u i l t / $ { p l a t f o r m _ n a m e } / $ { A R C H _ A L I A S } / l i b E G L . d l l
$ { _ A X _ R O O T } / $ { _ A X _ T H I R D P A R T Y _ N A M E } / a n g l e / p r e b u i l t / $ { p l a t f o r m _ n a m e } / $ { A R C H _ A L I A S } / d 3 d c o m p i l e r _ 4 7 . d l l
2022-09-02 19:24:22 +08:00
$ < T A R G E T _ F I L E _ D I R : $ { a x _ t a r g e t } >
)
endif ( )
2022-04-27 19:39:12 +08:00
# Copy webview2 for ninja
2022-09-02 20:06:05 +08:00
if ( AX_ENABLE_MSEDGE_WEBVIEW2 )
2023-04-02 16:04:19 +08:00
if ( CMAKE_GENERATOR MATCHES "Ninja" )
2022-09-02 20:06:05 +08:00
add_custom_command ( TARGET ${ ax_target } POST_BUILD
2023-04-02 16:04:19 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t
" $ { C M A K E _ B I N A R Y _ D I R } / p a c k a g e s / M i c r o s o f t . W e b . W e b V i e w 2 / b u i l d / n a t i v e / $ { A R C H _ A L I A S } / W e b V i e w 2 L o a d e r . d l l "
$ < T A R G E T _ F I L E _ D I R : $ { a x _ t a r g e t } > )
2022-09-02 20:06:05 +08:00
endif ( )
2022-04-27 19:39:12 +08:00
endif ( )
2023-06-17 00:26:46 +08:00
# copy libvlc plugins dir for windows
if ( AX_ENABLE_VLC_MEDIA )
add_custom_command ( TARGET ${ ax_target } POST_BUILD
2023-07-06 16:09:54 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ d i r e c t o r y $ { _ A X _ R O O T } / $ { _ A X _ T H I R D P A R T Y _ N A M E } / v l c / w i n / l i b / v l c / p l u g i n s
2023-06-17 00:26:46 +08:00
$ < T A R G E T _ F I L E _ D I R : $ { a x _ t a r g e t } > / p l u g i n s
)
endif ( )
2019-11-23 20:27:39 +08:00
endfunction ( )
2022-08-11 15:41:10 +08:00
function ( ax_copy_lua_dlls ax_target )
2022-02-17 18:06:19 +08:00
if ( NOT AX_USE_LUAJIT )
2023-04-02 16:04:19 +08:00
if ( NOT CMAKE_GENERATOR MATCHES "Ninja" )
2022-08-19 19:52:10 +08:00
set ( BUILD_CONFIG_DIR "\$\(Configuration\)/" )
2022-04-26 15:16:02 +08:00
endif ( )
2023-04-02 16:04:19 +08:00
if ( MSVC )
add_custom_command ( TARGET ${ ax_target } POST_BUILD
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t
" $ { C M A K E _ B I N A R Y _ D I R } / b i n / $ { B U I L D _ C O N F I G _ D I R } p l a i n l u a . d l l "
$ < T A R G E T _ F I L E _ D I R : $ { a x _ t a r g e t } > )
endif ( )
2022-01-17 23:50:05 +08:00
endif ( )
2021-10-12 13:16:27 +08:00
endfunction ( )
2019-11-23 20:27:39 +08:00
# mark `FILES` as resources, files will be put into sub-dir tree depend on its absolute path
2022-08-11 15:41:10 +08:00
function ( ax_mark_resources )
2019-11-23 20:27:39 +08:00
set ( oneValueArgs BASEDIR RESOURCEBASE )
set ( multiValueArgs FILES )
cmake_parse_arguments ( opt "" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
if ( NOT opt_RESOURCEBASE )
set ( opt_RESOURCEBASE Resources )
endif ( )
get_filename_component ( BASEDIR_ABS ${ opt_BASEDIR } ABSOLUTE )
foreach ( RES_FILE ${ opt_FILES } ${ opt_UNPARSED_ARGUMENTS } )
get_filename_component ( RES_FILE_ABS ${ RES_FILE } ABSOLUTE )
file ( RELATIVE_PATH RES ${ BASEDIR_ABS } ${ RES_FILE_ABS } )
get_filename_component ( RES_LOC ${ RES } PATH )
2023-03-11 22:10:18 +08:00
if ( APPLE )
set_source_files_properties ( ${ RES_FILE } PROPERTIES
M A C O S X _ P A C K A G E _ L O C A T I O N " $ { o p t _ R E S O U R C E B A S E } / $ { R E S _ L O C } "
H E A D E R _ F I L E _ O N L Y 1
)
elseif ( WINRT )
# MakeAppx.exe require deployment location path rule
# - must full quailfied windows style path
# - can't start with .\xxx.txt, must be xxx.txt
#
# Otherwise, will fail with:
# MakeAppx : error : 0x8007007b - The filename, directory name, or volume label syntax is incorrect.
if ( opt_RESOURCEBASE STREQUAL "." )
set ( basedir "" )
if ( NOT DEFINED basedir )
message ( FATAL_ERROR "empty string as false" )
endif ( )
else ( )
set ( basedir "${opt_RESOURCEBASE}\\" )
endif ( )
get_filename_component ( RES_EXTENSION ${ RES_FILE } LAST_EXT )
string ( TOLOWER "${RES_EXTENSION}" RES_EXTENSION )
if ( RES_EXTENSION STREQUAL ".obj" )
set_source_files_properties ( ${ RES_FILE } PROPERTIES HEADER_FILE_ONLY 1 )
endif ( )
string ( REPLACE "/" "\\" VSDEPLOY_LOC "${basedir}${RES_LOC}" )
# dir path can have one trailing / -> remove
string ( REGEX REPLACE "(.)\\\\$" "\\1" VSDEPLOY_LOC "${VSDEPLOY_LOC}" )
set_source_files_properties ( ${ RES_FILE } PROPERTIES
V S _ D E P L O Y M E N T _ C O N T E N T 1
V S _ D E P L O Y M E N T _ L O C A T I O N " $ { V S D E P L O Y _ L O C } "
)
else ( )
set_source_files_properties ( ${ RES_FILE } PROPERTIES
H E A D E R _ F I L E _ O N L Y 1
)
endif ( )
2019-11-23 20:27:39 +08:00
if ( XCODE OR VS )
string ( REPLACE "/" "\\" ide_source_group "${opt_RESOURCEBASE}/${RES_LOC}" )
source_group ( "${ide_source_group}" FILES ${ RES_FILE } )
endif ( )
endforeach ( )
endfunction ( )
2022-08-11 15:41:10 +08:00
# mark the code sources of `ax_target` into sub-dir tree
function ( ax_mark_code_files ax_target )
2019-11-23 20:27:39 +08:00
set ( oneValueArgs GROUPBASE )
cmake_parse_arguments ( opt "" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
if ( NOT opt_GROUPBASE )
set ( root_dir ${ CMAKE_CURRENT_SOURCE_DIR } )
else ( )
set ( root_dir ${ opt_GROUPBASE } )
2022-08-11 15:41:10 +08:00
message ( STATUS "target ${ax_target} code group base is: ${root_dir}" )
2019-11-23 20:27:39 +08:00
endif ( )
2022-08-11 15:41:10 +08:00
# message(STATUS "ax_mark_code_files: ${ax_target}")
2019-11-23 20:27:39 +08:00
2022-08-11 15:41:10 +08:00
get_property ( file_list TARGET ${ ax_target } PROPERTY SOURCES )
2019-11-23 20:27:39 +08:00
foreach ( single_file ${ file_list } )
source_group_single_file ( ${ single_file } GROUP_TO "Source Files" BASE_PATH "${root_dir}" )
endforeach ( )
endfunction ( )
# source group one file
# cut the `single_file` absolute path from `BASE_PATH`, then mark file to `GROUP_TO`
function ( source_group_single_file single_file )
set ( oneValueArgs GROUP_TO BASE_PATH )
cmake_parse_arguments ( opt "" "${oneValueArgs}" "${multiValueArgs}" ${ ARGN } )
# get relative_path
get_filename_component ( abs_path ${ single_file } ABSOLUTE )
file ( RELATIVE_PATH relative_path_with_name ${ opt_BASE_PATH } ${ abs_path } )
get_filename_component ( relative_path ${ relative_path_with_name } PATH )
# set source_group, consider sub source group
string ( REPLACE "/" "\\" ide_file_group "${opt_GROUP_TO}/${relative_path}" )
source_group ( "${ide_file_group}" FILES ${ single_file } )
endfunction ( )
2022-10-01 16:24:52 +08:00
# setup a ax application
2023-03-11 22:10:18 +08:00
function ( ax_setup_app_config app_name )
if ( WINRT )
target_include_directories ( ${ APP_NAME }
P R I V A T E " p r o j . w i n r t "
)
endif ( )
2023-04-02 16:04:19 +08:00
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
2023-02-23 21:57:30 +08:00
target_link_options ( ${ APP_NAME } PRIVATE "/STACK:4194304" )
endif ( )
2019-11-23 20:27:39 +08:00
# put all output app into bin/${app_name}
set_target_properties ( ${ app_name } PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/${app_name}" )
if ( APPLE )
# output macOS/iOS .app
set_target_properties ( ${ app_name } PROPERTIES MACOSX_BUNDLE 1 )
2020-08-29 01:39:27 +08:00
if ( IOS AND ( NOT ( "${CMAKE_OSX_SYSROOT}" MATCHES ".*simulator.*" ) ) )
set_xcode_property ( ${ APP_NAME } CODE_SIGNING_REQUIRED "YES" )
set_xcode_property ( ${ APP_NAME } CODE_SIGNING_ALLOWED "YES" )
2021-08-13 10:19:24 +08:00
else ( )
# By default, explicit disable codesign for macOS PC
set_xcode_property ( ${ APP_NAME } CODE_SIGN_IDENTITY "" )
set_xcode_property ( ${ APP_NAME } CODE_SIGNING_ALLOWED "NO" )
set_xcode_property ( ${ APP_NAME } CODE_SIGN_IDENTITY "NO" )
2020-08-29 01:39:27 +08:00
endif ( )
2023-04-02 16:04:19 +08:00
elseif ( WINDOWS )
# windows: visual studio/LLVM-clang default is Console app, but we need Windows app
if ( MSVC )
set_property ( TARGET ${ app_name } APPEND PROPERTY LINK_FLAGS "/SUBSYSTEM:WINDOWS" )
elseif ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
set_property ( TARGET ${ app_name } APPEND PROPERTY LINK_FLAGS "-Xlinker /subsystem:windows" )
endif ( )
2019-11-23 20:27:39 +08:00
endif ( )
# auto mark code files for IDE when mark app
if ( XCODE OR VS )
2022-08-11 15:41:10 +08:00
ax_mark_code_files ( ${ app_name } )
2019-11-23 20:27:39 +08:00
endif ( )
if ( XCODE )
2022-08-11 15:41:10 +08:00
ax_config_app_xcode_property ( ${ app_name } )
2019-11-23 20:27:39 +08:00
endif ( )
2020-10-17 16:32:16 +08:00
if ( BUILD_SHARED_LIBS )
target_compile_definitions ( ${ app_name } PRIVATE SPINEPLUGIN_API=DLLIMPORT ) # spine dll
endif ( )
2022-05-13 21:06:17 +08:00
target_link_libraries ( ${ app_name } ${ _AX_EXTENSION_LIBS } )
2021-08-10 11:43:16 +08:00
2022-02-17 17:11:17 +08:00
if ( XCODE AND AX_USE_ALSOFT AND ALSOFT_OSX_FRAMEWORK )
2021-08-10 11:43:16 +08:00
# Embedded soft_oal embedded framework
# XCODE_LINK_BUILD_PHASE_MODE BUILT_ONLY
2021-08-12 11:25:01 +08:00
# ???CMake BUG: XCODE_EMBED_FRAMEWORKS_CODE_SIGN_ON_COPY works for first app
message ( STATUS "Embedding framework soft_oal to ${app_name}..." )
2021-08-10 11:43:16 +08:00
set_target_properties ( ${ app_name } PROPERTIES
X C O D E _ L I N K _ B U I L D _ P H A S E _ M O D E K N O W N _ L O C A T I O N
X C O D E _ E M B E D _ F R A M E W O R K S O p e n A L
X C O D E _ E M B E D _ F R A M E W O R K S _ C O D E _ S I G N _ O N _ C O P Y O N
X C O D E _ E M B E D _ F R A M E W O R K S _ R E M O V E _ H E A D E R S _ O N _ C O P Y O N
)
endif ( )
2023-07-08 17:17:10 +08:00
2023-08-25 16:49:08 +08:00
# auto looking app shaders source dir and add to glslcc compile-list
get_target_property ( app_shaders_dir ${ app_name } SOURCE_DIR )
set ( app_shaders_dir "${app_shaders_dir}/Source/shaders" )
ax_find_shaders ( ${ app_shaders_dir } app_shaders RECURSE )
if ( app_shaders )
list ( LENGTH app_shaders app_shaders_count )
message ( STATUS "${app_shaders_count} shader sources found in ${app_shaders_dir}" )
# compile app shader to ${CMAKE_BINARY_DIR}/runtime/axslc/custom/
ax_target_compile_shaders ( ${ app_name } FILES ${ app_shaders } CUSTOM )
source_group ( "Source Files/Source/shaders" FILES ${ app_shaders } )
else ( )
message ( STATUS "No shader found in ${app_shaders_dir}" )
endif ( )
if ( IS_DIRECTORY ${ GLSLCC_OUT_DIR } )
get_target_property ( rt_output ${ app_name } RUNTIME_OUTPUT_DIRECTORY )
if ( ( WIN32 AND ( NOT WINRT ) ) OR LINUX )
ax_sync_target_res ( ${ app_name } LINK_TO "${rt_output}/${CMAKE_CFG_INTDIR}/axslc" FOLDERS ${ GLSLCC_OUT_DIR } SYM_LINK 1 SYNC_TARGET_ID axslc )
elseif ( APPLE )
# once cmake-3.28.0 released, uncomment follow line instead above 2 lines
set_target_properties ( ${ app_name } PROPERTIES XCODE_EMBED_RESOURCES_PATH ${ GLSLCC_OUT_DIR } )
elseif ( WINRT )
set ( app_all_shaders )
list ( APPEND app_all_shaders ${ ax_builtin_shaders } )
list ( APPEND app_all_shaders ${ app_shaders } )
ax_target_embed_compiled_shaders ( ${ app_name } ${ rt_output } FILES ${ app_all_shaders } )
2023-07-08 17:17:10 +08:00
endif ( )
endif ( )
2019-11-23 20:27:39 +08:00
endfunction ( )
# if cc_variable not set, then set it cc_value
2022-08-11 15:41:10 +08:00
macro ( ax_set_default_value cc_variable cc_value )
2019-11-23 20:27:39 +08:00
if ( NOT DEFINED ${ cc_variable } )
set ( ${ cc_variable } ${ cc_value } )
endif ( )
endmacro ( )
2023-03-11 22:10:18 +08:00
macro ( ax_setup_winrt_sources )
set_property ( SOURCE "proj.winrt/App.xaml" PROPERTY VS_XAML_TYPE "ApplicationDefinition" )
ax_mark_multi_resources ( platform_content_files RES_TO "Content" FOLDERS "${CMAKE_CURRENT_SOURCE_DIR}/proj.winrt/Content" )
get_target_depends_ext_dlls ( thirdparty prebuilt_dlls )
ax_mark_multi_resources ( prebuilt_dlls RES_TO "." FILES ${ prebuilt_dlls } )
list ( APPEND PLATFORM_SOURCES
p r o j . w i n r t / A p p . x a m l
p r o j . w i n r t / A p p . x a m l . h
p r o j . w i n r t / A p p . x a m l . c p p
p r o j . w i n r t / P a c k a g e . a p p x m a n i f e s t
2023-07-06 16:09:54 +08:00
$ { _ A X _ R O O T } / c o r e / p l a t f o r m / w i n r t / x a m l / O p e n G L E S . h
$ { _ A X _ R O O T } / c o r e / p l a t f o r m / w i n r t / x a m l / O p e n G L E S . c p p
$ { _ A X _ R O O T } / c o r e / p l a t f o r m / w i n r t / x a m l / O p e n G L E S P a g e . x a m l
$ { _ A X _ R O O T } / c o r e / p l a t f o r m / w i n r t / x a m l / O p e n G L E S P a g e . x a m l . h
$ { _ A X _ R O O T } / c o r e / p l a t f o r m / w i n r t / x a m l / O p e n G L E S P a g e . x a m l . c p p
$ { _ A X _ R O O T } / c o r e / p l a t f o r m / w i n r t / x a m l / A x m o l R e n d e r e r . h
$ { _ A X _ R O O T } / c o r e / p l a t f o r m / w i n r t / x a m l / A x m o l R e n d e r e r . c p p
2023-03-11 22:10:18 +08:00
)
2023-07-06 16:09:54 +08:00
list ( APPEND GAME_INC_DIRS ${ _AX_ROOT } /core/platform/winrt/xaml )
2023-03-11 22:10:18 +08:00
list ( APPEND GAME_HEADER
$ { P L A T F O R M _ H E A D E R S }
)
list ( APPEND GAME_SOURCE
$ { P L A T F O R M _ S O U R C E S }
$ { p l a t f o r m _ c o n t e n t _ f i l e s }
$ { p r e b u i l t _ d l l s }
)
endmacro ( )
2023-03-12 17:57:54 +08:00
# must call last line
function ( get_all_targets var )
set ( targets )
get_all_targets_recursive ( targets ${ CMAKE_CURRENT_SOURCE_DIR } )
set ( ${ var } ${ targets } PARENT_SCOPE )
endfunction ( )
macro ( get_all_targets_recursive targets dir )
get_property ( subdirectories DIRECTORY ${ dir } PROPERTY SUBDIRECTORIES )
foreach ( subdir ${ subdirectories } )
get_all_targets_recursive ( ${ targets } ${ subdir } )
endforeach ( )
get_property ( current_targets DIRECTORY ${ dir } PROPERTY BUILDSYSTEM_TARGETS )
list ( APPEND ${ targets } ${ current_targets } )
endmacro ( )
function ( ax_uwp_set_all_targets_deploy_min_version )
if ( WINRT )
2023-03-14 08:24:27 +08:00
if ( DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION )
message ( STATUS "You are using a cmake version which is support CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION=${CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION}, \nskip set VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION for targets one by one." )
else ( )
set ( oneValueArgs TARGET_PLATFORM_MIN_VERSION )
cmake_parse_arguments ( opt "" "${oneValueArgs}" "" ${ ARGN } )
if ( NOT opt_TARGET_PLATFORM_MIN_VERSION )
# The minmal deploy target version: Windows 10, version 1809 (Build 10.0.17763) for building msix package
# refer to: https://learn.microsoft.com/en-us/windows/msix/supported-platforms?source=recommendations
set ( opt_TARGET_PLATFORM_MIN_VERSION ${ AX_VS_DEPLOYMENT_TARGET } )
endif ( )
get_all_targets ( all_targets )
2023-03-12 17:57:54 +08:00
2023-03-14 08:24:27 +08:00
foreach ( target ${ all_targets } )
set_target_properties ( ${ target } PROPERTIES VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION "${opt_TARGET_PLATFORM_MIN_VERSION}" )
endforeach ( )
endif ( )
2023-03-12 17:57:54 +08:00
endif ( )
endfunction ( )
2019-11-23 20:27:39 +08:00
# set Xcode property for application, include all depend target
2022-08-11 15:41:10 +08:00
macro ( ax_config_app_xcode_property ax_app )
2019-11-23 20:27:39 +08:00
set ( depend_libs )
2022-08-11 15:41:10 +08:00
search_depend_libs_recursive ( ${ ax_app } depend_libs )
2019-11-23 20:27:39 +08:00
foreach ( depend_lib ${ depend_libs } )
if ( TARGET ${ depend_lib } )
2022-08-11 15:41:10 +08:00
ax_config_target_xcode_property ( ${ depend_lib } )
2019-11-23 20:27:39 +08:00
endif ( )
endforeach ( )
endmacro ( )
# custom Xcode property for iOS target
2022-08-11 15:41:10 +08:00
macro ( ax_config_target_xcode_property ax_target )
2019-11-23 20:27:39 +08:00
if ( IOS )
2021-05-05 14:04:06 +08:00
set ( real_target )
2022-08-11 15:41:10 +08:00
get_property ( real_target TARGET ${ ax_target } PROPERTY ALIASED_TARGET )
2021-05-05 14:04:06 +08:00
if ( NOT real_target )
2022-08-11 15:41:10 +08:00
set ( real_target ${ ax_target } )
2021-05-05 14:04:06 +08:00
endif ( )
set_xcode_property ( ${ real_target } ENABLE_BITCODE "NO" )
set_xcode_property ( ${ real_target } ONLY_ACTIVE_ARCH "YES" )
2019-11-23 20:27:39 +08:00
endif ( )
endmacro ( )
# This little macro lets you set any XCode specific property, from ios.toolchain.cmake
function ( set_xcode_property TARGET XCODE_PROPERTY XCODE_VALUE )
set_property ( TARGET ${ TARGET } PROPERTY XCODE_ATTRIBUTE_ ${ XCODE_PROPERTY } ${ XCODE_VALUE } )
endfunction ( set_xcode_property )
# works same as find_package, but do additional care to properly find
2022-08-11 15:41:10 +08:00
macro ( ax_find_package pkg_name pkg_prefix )
2019-11-23 20:27:39 +08:00
if ( NOT ${ pkg_prefix } _FOUND )
find_package ( ${ pkg_name } ${ ARGN } )
endif ( )
if ( NOT ${ pkg_prefix } _INCLUDE_DIRS AND ${ pkg_prefix } _INCLUDE_DIR )
set ( ${ pkg_prefix } _INCLUDE_DIRS ${ ${pkg_prefix } _INCLUDE_DIR} )
endif ( )
if ( NOT ${ pkg_prefix } _LIBRARIES AND ${ pkg_prefix } _LIBRARY )
set ( ${ pkg_prefix } _LIBRARIES ${ ${pkg_prefix } _LIBRARY} )
endif ( )
message ( STATUS "${pkg_name} include dirs: ${${pkg_prefix}_INCLUDE_DIRS}" )
endmacro ( )
2022-08-11 15:41:10 +08:00
# ax_use_pkg(pkg) function.
2019-11-23 20:27:39 +08:00
# This function applies standard package variables (after find_package(pkg) call) to current scope
# Recognized variables: <pkg>_INCLUDE_DIRS, <pkg>_LIBRARIES, <pkg>_LIBRARY_DIRS
# Also if BUILD_SHARED_LIBS variable off, it is try to use <pkg>_STATIC_* vars before
2022-08-11 15:41:10 +08:00
function ( ax_use_pkg target pkg )
2019-11-23 20:27:39 +08:00
set ( prefix ${ pkg } )
set ( _include_dirs )
if ( NOT _include_dirs )
set ( _include_dirs ${ ${prefix } _INCLUDE_DIRS} )
endif ( )
if ( NOT _include_dirs )
# backward compat with old package-find scripts
set ( _include_dirs ${ ${prefix } _INCLUDE_DIR} )
endif ( )
if ( _include_dirs )
include_directories ( ${ _include_dirs } )
2022-05-14 17:47:47 +08:00
message ( STATUS "${pkg} add to include_dirs: ${_include_dirs}" )
2019-11-23 20:27:39 +08:00
endif ( )
set ( _library_dirs )
if ( NOT _library_dirs )
set ( _library_dirs ${ ${prefix } _LIBRARY_DIRS} )
endif ( )
if ( _library_dirs )
link_directories ( ${ _library_dirs } )
# message(STATUS "${pkg} add to link_dirs: ${_library_dirs}")
endif ( )
set ( _libs )
if ( NOT _libs )
set ( _libs ${ ${prefix } _LIBRARIES} )
endif ( )
if ( NOT _libs )
set ( _libs ${ ${prefix } _LIBRARY} )
endif ( )
if ( _libs )
target_link_libraries ( ${ target } ${ _libs } )
2022-05-14 17:47:47 +08:00
message ( STATUS "${pkg} libs added to '${target}': ${_libs}" )
2019-11-23 20:27:39 +08:00
endif ( )
set ( _defs )
if ( NOT _defs )
set ( _defs ${ ${prefix } _DEFINITIONS} )
endif ( )
if ( _defs )
add_definitions ( ${ _defs } )
2022-05-14 17:47:47 +08:00
message ( STATUS "${pkg} add definitions: ${_defs}" )
2019-11-23 20:27:39 +08:00
endif ( )
set ( _dlls )
if ( NOT _dlls )
set ( _dlls ${ ${prefix } _DLLS} )
endif ( )
if ( _dlls )
if ( MSVC )
# message(STATUS "${target} add dll: ${_dlls}")
get_property ( pre_dlls
T A R G E T $ { t a r g e t }
2022-07-16 10:43:05 +08:00
P R O P E R T Y A X _ D E P E N D _ D L L S )
2019-11-23 20:27:39 +08:00
if ( pre_dlls )
set ( _dlls ${ pre_dlls } ${ _dlls } )
endif ( )
set_property ( TARGET ${ target }
P R O P E R T Y
2022-07-16 10:43:05 +08:00
A X _ D E P E N D _ D L L S $ { _ d l l s }
2019-11-23 20:27:39 +08:00
)
endif ( )
endif ( )
endfunction ( )
2022-05-18 12:52:05 +08:00
2022-10-18 19:13:40 +08:00
# The axmol preprocessors config helper macro
2022-08-11 15:41:10 +08:00
macro ( ax_config_pred target_name pred )
2022-05-18 12:52:05 +08:00
if ( ${ pred } )
target_compile_definitions ( ${ target_name } PUBLIC ${ pred } =1 )
endif ( )
endmacro ( )