diff --git a/CMakeLists.txt b/CMakeLists.txt index caadee3b6f..eaa82b446b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -144,24 +144,52 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) -add_subdirectory(viet) -add_subdirectory(savefile) -add_subdirectory(papyrus-vm) -add_subdirectory(libespm) -add_subdirectory(skyrim-platform) +# Initialize the CMAKEPROJ projects and their configurations +list(APPEND CMAKEPROJ_PROJECTS_LIST) # List of all projects +set(CMAKEPROJ_PROJECTS_DEPENDENCIES) # Dependencies for each project +set(CMAKEPROJ_PROJECTS_PRIORITY) # Priority for each project + +# Glob directories under source directory root +file(GLOB ROOT_DIRS RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/*) +foreach(dir ${ROOT_DIRS}) + if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/${dir}) + # Check if directory has a cmakeproj.cmake file + if(EXISTS ${CMAKE_SOURCE_DIR}/${dir}/cmakeproj.cmake) + include(${CMAKE_SOURCE_DIR}/${dir}/cmakeproj.cmake) + # Add project to the list if not already added + if(NOT "${CMAKEPROJ_PROJECTS_LIST}" MATCHES "${dir}") + list(APPEND CMAKEPROJ_PROJECTS_LIST ${dir}) + endif() + # Set default priority if not set + if (NOT DEFINED CMAKEPROJ_PRIORITY_${dir}) + set(CMAKEPROJ_PRIORITY_${dir} 0) # Default priority 0 if not defined + endif() + + # Store dependencies and priorities for sorting + set(CMAKEPROJ_PROJECTS_DEPENDENCIES ${CMAKEPROJ_PROJECTS_DEPENDENCIES} "${CMAKEPROJ_DEPS_${dir}}") + set(CMAKEPROJ_PROJECTS_PRIORITY ${CMAKEPROJ_PROJECTS_PRIORITY} ${CMAKEPROJ_PRIORITY_${dir}}) + endif() + endif() +endforeach() +foreach(proj ${CMAKEPROJ_PROJECTS_LIST}) + list(APPEND priorities_list ${CMAKEPROJ_PRIORITY_${proj}}) +endforeach() +list(REMOVE_DUPLICATES priorities_list) +list(SORT priorities_list COMPARE NATURAL) -add_subdirectory(client-deps) -add_subdirectory(skymp5-client) -add_subdirectory(skymp5-front) -add_subdirectory(skymp5-functions-lib) -add_subdirectory(skymp5-scripts) -add_subdirectory(skymp5-server) +foreach(priority ${priorities_list}) + foreach(proj ${CMAKEPROJ_PROJECTS_LIST}) + if(${CMAKEPROJ_PRIORITY_${proj}} STREQUAL ${priority}) + list(APPEND sorted_projects ${proj}) + endif() + endforeach() +endforeach() -# TODO: enable for Emscripten once stabilize -if(BUILD_UNIT_TESTS AND NOT EMSCRIPTEN) - add_subdirectory(unit) -endif() +foreach(project ${sorted_projects}) + message(STATUS "Adding project: ${project} with priority ${CMAKEPROJ_PRIORITY_${project}}") + add_subdirectory(${project}) +endforeach() if(PREPARE_NEXUS_ARCHIVES) add_custom_target( diff --git a/client-deps/cmakeproj.cmake b/client-deps/cmakeproj.cmake new file mode 100644 index 0000000000..26795ad561 --- /dev/null +++ b/client-deps/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS client-deps) +set(CMAKEPROJ_PRIORITY_client-deps 2) diff --git a/libespm/cmakeproj.cmake b/libespm/cmakeproj.cmake new file mode 100644 index 0000000000..93ba4c3247 --- /dev/null +++ b/libespm/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS libespm) +set(CMAKEPROJ_PRIORITY_libespm 1) diff --git a/papyrus-vm/cmakeproj.cmake b/papyrus-vm/cmakeproj.cmake new file mode 100644 index 0000000000..868a8989bc --- /dev/null +++ b/papyrus-vm/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS papyrus-vm) +set(CMAKEPROJ_PRIORITY_papyrus-vm 1) diff --git a/savefile/cmakeproj.cmake b/savefile/cmakeproj.cmake new file mode 100644 index 0000000000..479ffcd189 --- /dev/null +++ b/savefile/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS savefile) +set(CMAKEPROJ_PRIORITY_savefile 1) diff --git a/skymp5-client/cmakeproj.cmake b/skymp5-client/cmakeproj.cmake new file mode 100644 index 0000000000..328eb435aa --- /dev/null +++ b/skymp5-client/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS skymp5-client) +set(CMAKEPROJ_PRIORITY_skymp5-client 2) diff --git a/skymp5-front/cmakeproj.cmake b/skymp5-front/cmakeproj.cmake new file mode 100644 index 0000000000..8be9ba5e7e --- /dev/null +++ b/skymp5-front/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS skymp5-front) +set(CMAKEPROJ_PRIORITY_skymp5-front 2) diff --git a/skymp5-functions-lib/cmakeproj.cmake b/skymp5-functions-lib/cmakeproj.cmake new file mode 100644 index 0000000000..3d5543a740 --- /dev/null +++ b/skymp5-functions-lib/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS skymp5-functions-lib) +set(CMAKEPROJ_PRIORITY_skymp5-functions-lib 2) diff --git a/skymp5-scripts/cmakeproj.cmake b/skymp5-scripts/cmakeproj.cmake new file mode 100644 index 0000000000..544ed8075f --- /dev/null +++ b/skymp5-scripts/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS skymp5-scripts) +set(CMAKEPROJ_PRIORITY_skymp5-scripts 2) diff --git a/skymp5-server/cmakeproj.cmake b/skymp5-server/cmakeproj.cmake new file mode 100644 index 0000000000..559f67c007 --- /dev/null +++ b/skymp5-server/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS skymp5-server) +set(CMAKEPROJ_PRIORITY_skymp5-server 3) diff --git a/skyrim-platform/cmakeproj.cmake b/skyrim-platform/cmakeproj.cmake new file mode 100644 index 0000000000..63b8277082 --- /dev/null +++ b/skyrim-platform/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS skyrim-platform) +set(CMAKEPROJ_PRIORITY_skyrim-platform 2) diff --git a/unit/CMakeLists.txt b/unit/CMakeLists.txt index cac6193f80..f1975264fe 100644 --- a/unit/CMakeLists.txt +++ b/unit/CMakeLists.txt @@ -1,81 +1,86 @@ -include(${CMAKE_SOURCE_DIR}/cmake/add_papyrus_library_ck.cmake) +# TODO: enable for Emscripten once stabilize +if(BUILD_UNIT_TESTS AND NOT EMSCRIPTEN) -# -# papyrus_test_files -# + include(${CMAKE_SOURCE_DIR}/cmake/add_papyrus_library_ck.cmake) + include(${CMAKE_SOURCE_DIR}/cmake/apply_default_settings.cmake) -add_papyrus_library_ck( - NAME papyrus_test_files - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/papyrus_test_files - OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/papyrus_test_files/pex - COMPILER_EXECUTABLE_PATH "${SKYRIM_DIR}/Papyrus compiler/PapyrusCompiler.exe" -) + # + # papyrus_test_files + # -# -# unit executable -# + add_papyrus_library_ck( + NAME papyrus_test_files + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/papyrus_test_files + OUTPUT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/papyrus_test_files/pex + COMPILER_EXECUTABLE_PATH "${SKYRIM_DIR}/Papyrus compiler/PapyrusCompiler.exe" + ) -file(GLOB src "${CMAKE_CURRENT_SOURCE_DIR}/*") -list(APPEND src "${CMAKE_SOURCE_DIR}/.clang-format") -if(TARGET platform_lib) - file(GLOB src_windows "${CMAKE_CURRENT_SOURCE_DIR}/platform_lib_tests/*") - list(APPEND src ${src_windows}) -endif() + # + # unit executable + # -add_executable(unit ${src}) + file(GLOB src "${CMAKE_CURRENT_SOURCE_DIR}/*") + list(APPEND src "${CMAKE_SOURCE_DIR}/.clang-format") + if(TARGET platform_lib) + file(GLOB src_windows "${CMAKE_CURRENT_SOURCE_DIR}/platform_lib_tests/*") + list(APPEND src ${src_windows}) + endif() -find_package(Catch2 CONFIG REQUIRED) -target_link_libraries(unit PRIVATE Catch2::Catch2) + add_executable(unit ${src}) -target_link_libraries(unit PUBLIC server_guest_lib espm) -if(TARGET platform_lib) - target_link_libraries(unit PUBLIC platform_lib) -endif() -apply_default_settings(TARGETS unit) -list(APPEND VCPKG_DEPENDENT unit) + find_package(Catch2 CONFIG REQUIRED) + target_link_libraries(unit PRIVATE Catch2::Catch2) -if(SKYRIM_SE) - target_compile_definitions(unit PRIVATE SKYRIM_SE=1) -endif() + target_link_libraries(unit PUBLIC server_guest_lib espm) + if(TARGET platform_lib) + target_link_libraries(unit PUBLIC platform_lib) + endif() + apply_default_settings(TARGETS unit) + list(APPEND VCPKG_DEPENDENT unit) -target_compile_definitions(unit PRIVATE - TEST_PEX_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/papyrus_test_files/standard_scripts\" - BUILT_PEX_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/papyrus_test_files/pex\" - SKYRIM_DIR=\"${SKYRIM_DIR}\" - UNIT_DATA_DIR=\"${UNIT_DATA_DIR}\" - DIST_DIR=\"${CMAKE_BINARY_DIR}/dist\" -) + if(SKYRIM_SE) + target_compile_definitions(unit PRIVATE SKYRIM_SE=1) + endif() -if(WIN32) - target_compile_options(unit PRIVATE "/bigobj") - target_link_libraries(unit PUBLIC Dbghelp.lib) -endif() + target_compile_definitions(unit PRIVATE + TEST_PEX_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/papyrus_test_files/standard_scripts\" + BUILT_PEX_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/papyrus_test_files/pex\" + SKYRIM_DIR=\"${SKYRIM_DIR}\" + UNIT_DATA_DIR=\"${UNIT_DATA_DIR}\" + DIST_DIR=\"${CMAKE_BINARY_DIR}/dist\" + ) -# -# ctest tests -# + if(WIN32) + target_compile_options(unit PRIVATE "/bigobj") + target_link_libraries(unit PUBLIC Dbghelp.lib) + endif() -# run without coverage but with dumps -add_test( - NAME test_unit - COMMAND ${CMAKE_COMMAND} - -DEXE_PATH=$ - -DCOVERAGE_HTML_OUT_DIR=${CMAKE_BINARY_DIR}/__coverage - -DCPPCOV=OFF - -DCPPCOV_PATH=${CPPCOV_PATH} - -DUNIT_WORKING_DIRECTORY=${CMAKE_BINARY_DIR} - -P ${CMAKE_SOURCE_DIR}/cmake/run_test_unit.cmake -) + # + # ctest tests + # -# run with coverage but without dumps -if(CPPCOV_PATH) + # run without coverage but with dumps add_test( - NAME test_unit_coverage + NAME test_unit COMMAND ${CMAKE_COMMAND} -DEXE_PATH=$ -DCOVERAGE_HTML_OUT_DIR=${CMAKE_BINARY_DIR}/__coverage - -DCPPCOV=ON + -DCPPCOV=OFF -DCPPCOV_PATH=${CPPCOV_PATH} + -DUNIT_WORKING_DIRECTORY=${CMAKE_BINARY_DIR} -P ${CMAKE_SOURCE_DIR}/cmake/run_test_unit.cmake ) + + # run with coverage but without dumps + if(CPPCOV_PATH) + add_test( + NAME test_unit_coverage + COMMAND ${CMAKE_COMMAND} + -DEXE_PATH=$ + -DCOVERAGE_HTML_OUT_DIR=${CMAKE_BINARY_DIR}/__coverage + -DCPPCOV=ON + -DCPPCOV_PATH=${CPPCOV_PATH} + -P ${CMAKE_SOURCE_DIR}/cmake/run_test_unit.cmake + ) + endif() endif() diff --git a/unit/cmakeproj.cmake b/unit/cmakeproj.cmake new file mode 100644 index 0000000000..6be0f0bf2f --- /dev/null +++ b/unit/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS unit) +set(CMAKEPROJ_PRIORITY_unit 4) diff --git a/viet/cmakeproj.cmake b/viet/cmakeproj.cmake new file mode 100644 index 0000000000..ce8298cb2d --- /dev/null +++ b/viet/cmakeproj.cmake @@ -0,0 +1,2 @@ +list(APPEND CMAKEPROJ_PROJECTS viet) +set(CMAKEPROJ_PRIORITY_viet 0)