Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMake/Common.cmake
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
option(BUILD_EDITOR "Build Explosion editor" ON)
option(CI "Build in CI" OFF)
option(USE_UNITY_BUILD "Use unity build" ON)
option(EXPORT_COMPILE_COMMANDS "Whether to export all compile commands" OFF)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_UNITY_BUILD ${USE_UNITY_BUILD})
set(CMAKE_EXPORT_COMPILE_COMMANDS ${EXPORT_COMPILE_COMMANDS})

get_cmake_property(GENERATOR_IS_MULTI_CONFIG GENERATOR_IS_MULTI_CONFIG)
if (${GENERATOR_IS_MULTI_CONFIG})
Expand Down
80 changes: 45 additions & 35 deletions CMake/Target.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ else()
add_definitions(-DBUILD_TEST=0)
endif()

function(CombineRuntimeDependencies)
function(exp_combine_runtime_deps)
cmake_parse_arguments(PARAMS "" "NAME" "RUNTIME_DEP" ${ARGN})

get_target_property(RESULT ${PARAMS_NAME} RUNTIME_DEP)
Expand All @@ -27,7 +27,7 @@ function(CombineRuntimeDependencies)
)
endfunction()

function(LinkLibraries)
function(exp_link_libs)
cmake_parse_arguments(PARAMS "" "NAME" "LIB" ${ARGN})

foreach(L ${PARAMS_LIB})
Expand Down Expand Up @@ -61,28 +61,28 @@ function(LinkLibraries)

get_target_property(RUNTIME_DEP ${L} 3RD_RUNTIME_DEP)
if (NOT ("${RUNTIME_DEP}" STREQUAL "RUNTIME_DEP-NOTFOUND"))
CombineRuntimeDependencies(
exp_combine_runtime_deps(
NAME ${PARAMS_NAME}
RUNTIME_DEP "${RUNTIME_DEP}"
)
endif()
endforeach()
endfunction()

function(LinkBasicLibs)
function(exp_link_basic_libs)
cmake_parse_arguments(PARAMS "" "NAME" "LIB" ${ARGN})

foreach(L ${PARAMS_LIB})
if (NOT (${PARAMS_NAME} STREQUAL ${L}))
LinkLibraries(
exp_link_libs(
NAME ${PARAMS_NAME}
LIB ${L}
)
endif()
endforeach()
endfunction()

function(GetTargetRuntimeDependenciesRecurse)
function(exp_get_target_runtime_deps_recurse)
cmake_parse_arguments(PARAMS "" "NAME;OUTPUT" "" ${ARGN})

get_target_property(RUNTIME_DEP ${PARAMS_NAME} RUNTIME_DEP)
Expand All @@ -99,7 +99,7 @@ function(GetTargetRuntimeDependenciesRecurse)
continue()
endif()

GetTargetRuntimeDependenciesRecurse(
exp_get_target_runtime_deps_recurse(
NAME ${L}
OUTPUT TEMP
)
Expand All @@ -113,10 +113,10 @@ function(GetTargetRuntimeDependenciesRecurse)
set(${PARAMS_OUTPUT} ${RESULT} PARENT_SCOPE)
endfunction()

function(AddRuntimeDependenciesCopyCommand)
function(exp_add_runtime_deps_copy_command)
cmake_parse_arguments(PARAMS "NOT_INSTALL" "NAME" "" ${ARGN})

GetTargetRuntimeDependenciesRecurse(
exp_get_target_runtime_deps_recurse(
NAME ${PARAMS_NAME}
OUTPUT RUNTIME_DEPS
)
Expand Down Expand Up @@ -158,7 +158,7 @@ function(AddRuntimeDependenciesCopyCommand)
endforeach()
endfunction()

function(ExpandResourcePathExpression)
function(exp_expand_resource_path_expression)
cmake_parse_arguments(PARAMS "" "INPUT;OUTPUT_SRC;OUTPUT_DST" "" ${ARGN})

string(REPLACE "->" ";" TEMP ${PARAMS_INPUT})
Expand All @@ -169,11 +169,11 @@ function(ExpandResourcePathExpression)
set(${PARAMS_OUTPUT_DST} ${DST} PARENT_SCOPE)
endfunction()

function(AddResourcesCopyCommand)
function(exp_add_resources_copy_command)
cmake_parse_arguments(PARAMS "NOT_INSTALL" "NAME" "RES" ${ARGN})

foreach(R ${PARAMS_RES})
ExpandResourcePathExpression(
exp_expand_resource_path_expression(
INPUT ${R}
OUTPUT_SRC SRC
OUTPUT_DST DST
Expand All @@ -196,7 +196,7 @@ function(AddResourcesCopyCommand)
add_dependencies(${PARAMS_NAME} ${COPY_RES_TARGET_NAME})
endfunction()

function(GetTargetIncludeDirectoriesRecurse)
function(exp_get_target_include_dirs_recurse)
cmake_parse_arguments(PARAMS "" "NAME;OUTPUT" "" ${ARGN})

if (NOT (TARGET ${PARAMS_NAME}))
Expand All @@ -215,7 +215,7 @@ function(GetTargetIncludeDirectoriesRecurse)
get_target_property(TARGET_LIBS ${PARAMS_NAME} LINK_LIBRARIES)
if (NOT ("${TARGET_LIBS}" STREQUAL "TARGET_LIBS-NOTFOUND"))
foreach(TARGET_LIB ${TARGET_LIBS})
GetTargetIncludeDirectoriesRecurse(
exp_get_target_include_dirs_recurse(
NAME ${TARGET_LIB}
OUTPUT LIB_INCS
)
Expand All @@ -237,8 +237,8 @@ function(GetTargetIncludeDirectoriesRecurse)
set(${PARAMS_OUTPUT} ${RESULT} PARENT_SCOPE)
endfunction()

function(AddMirrorInfoSourceGenerationTarget)
cmake_parse_arguments(PARAMS "DYNAMIC" "NAME;OUTPUT_SRC;OUTPUT_TARGET_NAME" "SEARCH_DIR;PUBLIC_INC;PRIVATE_INC;LIB" ${ARGN})
function(exp_add_mirror_info_source_generation_target)
cmake_parse_arguments(PARAMS "DYNAMIC" "NAME;OUTPUT_SRC;OUTPUT_TARGET_NAME" "SEARCH_DIR;PUBLIC_INC;PRIVATE_INC;LIB;FRAMEWORK_DIR" ${ARGN})

if (DEFINED PARAMS_PUBLIC_INC)
list(APPEND INC ${PARAMS_PUBLIC_INC})
Expand All @@ -248,7 +248,7 @@ function(AddMirrorInfoSourceGenerationTarget)
endif()
if (DEFINED PARAMS_LIB)
foreach (L ${PARAMS_LIB})
GetTargetIncludeDirectoriesRecurse(
exp_get_target_include_dirs_recurse(
NAME ${L}
OUTPUT TARGET_INCS
)
Expand All @@ -262,10 +262,20 @@ function(AddMirrorInfoSourceGenerationTarget)
list(APPEND INC_ARGS "-I")
foreach (I ${INC})
get_filename_component(ABSOLUTE_I ${I} ABSOLUTE)
list(APPEND ABSOLUTE_INC ${ABSOLUTE_I})
list(APPEND INC_ARGS ${ABSOLUTE_I})
endforeach()

if (DEFINED PARAMS_FRAMEWORK_DIR)
list(APPEND FWK_DIR ${PARAMS_FRAMEWORK_DIR})
list(APPEND FWK_DIR_ARGS "-F")
endif ()
list(REMOVE_DUPLICATES FWK_DIR)

foreach (F ${FWK_DIR})
get_filename_component(ABSOLUTE_F ${F} ABSOLUTE)
list(APPEND FWK_DIR_ARGS ${ABSOLUTE_F})
endforeach ()

if (${PARAMS_DYNAMIC})
list(APPEND DYNAMIC_ARG "-d")
endif ()
Expand All @@ -282,7 +292,7 @@ function(AddMirrorInfoSourceGenerationTarget)

add_custom_command(
OUTPUT ${OUTPUT_SOURCE}
COMMAND "$<TARGET_FILE:MirrorTool>" ${DYNAMIC_ARG} "-i" ${INPUT_HEADER_FILE} "-o" ${OUTPUT_SOURCE} ${INC_ARGS}
COMMAND "$<TARGET_FILE:MirrorTool>" ${DYNAMIC_ARG} "-i" ${INPUT_HEADER_FILE} "-o" ${OUTPUT_SOURCE} ${INC_ARGS} ${FWK_DIR_ARGS}
DEPENDS MirrorTool ${INPUT_HEADER_FILE}
)
endforeach()
Expand All @@ -301,7 +311,7 @@ function(AddMirrorInfoSourceGenerationTarget)
endif()
endfunction()

function(AddExecutable)
function(exp_add_executable)
cmake_parse_arguments(PARAMS "SAMPLE;NOT_INSTALL" "NAME" "SRC;INC;LINK;LIB;DEP_TARGET;RES;REFLECT" ${ARGN})

if (${PARAMS_SAMPLE} AND (NOT ${BUILD_SAMPLE}))
Expand All @@ -315,7 +325,7 @@ function(AddExecutable)
endif ()

if (DEFINED PARAMS_REFLECT)
AddMirrorInfoSourceGenerationTarget(
exp_add_mirror_info_source_generation_target(
NAME ${PARAMS_NAME}
OUTPUT_SRC GENERATED_SRC
OUTPUT_TARGET_NAME GENERATED_TARGET
Expand All @@ -338,19 +348,19 @@ function(AddExecutable)
${PARAMS_NAME}
PRIVATE ${PARAMS_LINK}
)
LinkBasicLibs(
exp_link_basic_libs(
NAME ${PARAMS_NAME}
LIB ${BASIC_LIBS}
)
LinkLibraries(
exp_link_libs(
NAME ${PARAMS_NAME}
LIB ${PARAMS_LIB}
)
AddRuntimeDependenciesCopyCommand(
exp_add_runtime_deps_copy_command(
NAME ${PARAMS_NAME}
${NOT_INSTALL_FLAG}
)
AddResourcesCopyCommand(
exp_add_resources_copy_command(
NAME ${PARAMS_NAME}
RES ${PARAMS_RES}
${NOT_INSTALL_FLAG}
Expand Down Expand Up @@ -378,7 +388,7 @@ function(AddExecutable)
endif ()
endfunction()

function(AddLibrary)
function(exp_add_library)
cmake_parse_arguments(PARAMS "NOT_INSTALL" "NAME;TYPE" "SRC;PRIVATE_INC;PUBLIC_INC;PRIVATE_LINK;LIB;REFLECT" ${ARGN})

if ("${PARAMS_TYPE}" STREQUAL "SHARED")
Expand All @@ -390,7 +400,7 @@ function(AddLibrary)
list(APPEND EXTRA_PARAMS DYNAMIC)
endif ()

AddMirrorInfoSourceGenerationTarget(
exp_add_mirror_info_source_generation_target(
NAME ${PARAMS_NAME}
OUTPUT_SRC GENERATED_SRC
OUTPUT_TARGET_NAME GENERATED_TARGET
Expand Down Expand Up @@ -420,11 +430,11 @@ function(AddLibrary)
PRIVATE ${PARAMS_PRIVATE_LINK}
PUBLIC ${PARAMS_PUBLIC_LINK}
)
LinkBasicLibs(
exp_link_basic_libs(
NAME ${PARAMS_NAME}
LIB ${BASIC_LIBS}
)
LinkLibraries(
exp_link_libs(
NAME ${PARAMS_NAME}
LIB ${PARAMS_LIB}
)
Expand Down Expand Up @@ -481,15 +491,15 @@ function(AddLibrary)
endif ()
endfunction()

function(AddTest)
function(exp_add_test)
if (NOT ${BUILD_TEST})
return()
endif()

cmake_parse_arguments(PARAMS "META" "NAME" "SRC;INC;LINK;LIB;DEP_TARGET;RES;REFLECT" ${ARGN})

if (DEFINED PARAMS_REFLECT)
AddMirrorInfoSourceGenerationTarget(
exp_add_mirror_info_source_generation_target(
NAME ${PARAMS_NAME}
OUTPUT_SRC GENERATED_SRC
OUTPUT_TARGET_NAME GENERATED_TARGET
Expand All @@ -512,19 +522,19 @@ function(AddTest)
${PARAMS_NAME}
PRIVATE ${PARAMS_LINK}
)
LinkBasicLibs(
exp_link_basic_libs(
NAME ${PARAMS_NAME}
LIB ${BASIC_LIBS} ${BASIC_TEST_LIBS}
)
LinkLibraries(
exp_link_libs(
NAME ${PARAMS_NAME}
LIB ${PARAMS_LIB}
)
AddRuntimeDependenciesCopyCommand(
exp_add_runtime_deps_copy_command(
NAME ${PARAMS_NAME}
NOT_INSTALL
)
AddResourcesCopyCommand(
exp_add_resources_copy_command(
NAME ${PARAMS_NAME}
RES ${PARAMS_RES}
NOT_INSTALL
Expand Down
Loading
Loading