Skip to content

Commit

Permalink
internal: solve CMakeLists.txt conflicts forever (skyrim-multiplayer#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pospelove authored Nov 2, 2024
1 parent cd07b66 commit 5a107eb
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 75 deletions.
58 changes: 43 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions client-deps/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS client-deps)
set(CMAKEPROJ_PRIORITY_client-deps 2)
2 changes: 2 additions & 0 deletions libespm/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS libespm)
set(CMAKEPROJ_PRIORITY_libespm 1)
2 changes: 2 additions & 0 deletions papyrus-vm/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS papyrus-vm)
set(CMAKEPROJ_PRIORITY_papyrus-vm 1)
2 changes: 2 additions & 0 deletions savefile/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS savefile)
set(CMAKEPROJ_PRIORITY_savefile 1)
2 changes: 2 additions & 0 deletions skymp5-client/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS skymp5-client)
set(CMAKEPROJ_PRIORITY_skymp5-client 2)
2 changes: 2 additions & 0 deletions skymp5-front/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS skymp5-front)
set(CMAKEPROJ_PRIORITY_skymp5-front 2)
2 changes: 2 additions & 0 deletions skymp5-functions-lib/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS skymp5-functions-lib)
set(CMAKEPROJ_PRIORITY_skymp5-functions-lib 2)
2 changes: 2 additions & 0 deletions skymp5-scripts/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS skymp5-scripts)
set(CMAKEPROJ_PRIORITY_skymp5-scripts 2)
2 changes: 2 additions & 0 deletions skymp5-server/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS skymp5-server)
set(CMAKEPROJ_PRIORITY_skymp5-server 3)
2 changes: 2 additions & 0 deletions skyrim-platform/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS skyrim-platform)
set(CMAKEPROJ_PRIORITY_skyrim-platform 2)
125 changes: 65 additions & 60 deletions unit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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=$<TARGET_FILE:unit>
-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=$<TARGET_FILE:unit>
-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=$<TARGET_FILE:unit>
-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()
2 changes: 2 additions & 0 deletions unit/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS unit)
set(CMAKEPROJ_PRIORITY_unit 4)
2 changes: 2 additions & 0 deletions viet/cmakeproj.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
list(APPEND CMAKEPROJ_PROJECTS viet)
set(CMAKEPROJ_PRIORITY_viet 0)

0 comments on commit 5a107eb

Please sign in to comment.