mirror of
https://github.com/ModOrganizer2/cmake_common.git
synced 2026-07-27 14:06:46 -07:00
new variables install_dir, run_elevated
replaced CMAKE_PROJECT_NAME with PROJECT_NAME, the former doesn't change when there are multiple projects optional plugins for deploy_qt() fixed gamebryo handling added requires_library(), handles loot, cpptoml and python
This commit is contained in:
@@ -42,7 +42,7 @@ macro(do_cpp_project)
|
||||
GITID="${GIT_COMMIT_HASH}")
|
||||
|
||||
set_property(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" PROPERTY
|
||||
VS_STARTUP_PROJECT ${CMAKE_PROJECT_NAME})
|
||||
VS_STARTUP_PROJECT ${PROJECT_NAME})
|
||||
endmacro()
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ macro(cpp_pre_target)
|
||||
qt5_create_translation(
|
||||
qm_files
|
||||
${CMAKE_SOURCE_DIR}/src ${additional_translations}
|
||||
${CMAKE_SOURCE_DIR}/src/${CMAKE_PROJECT_NAME}_en.ts
|
||||
${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}_en.ts
|
||||
OPTIONS -silent
|
||||
)
|
||||
endif()
|
||||
@@ -78,15 +78,14 @@ macro(cpp_pre_target)
|
||||
${Boost_LIBRARY_DIRS}
|
||||
${LZ4_ROOT}/bin
|
||||
${ZLIB_ROOT}/lib
|
||||
${LOOT_PATH}
|
||||
)
|
||||
endmacro()
|
||||
|
||||
|
||||
|
||||
macro(cpp_post_target)
|
||||
# this needs to happen after the include() above because they rely on the
|
||||
# target being created
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${Boost_INCLUDE_DIRS}
|
||||
${SPDLOG_ROOT}/include
|
||||
${SEVENZ_ROOT}/CPP
|
||||
@@ -101,20 +100,20 @@ macro(cpp_post_target)
|
||||
source_group(resources FILES ${rc_files} ${qrc_files})
|
||||
|
||||
if(EXISTS ${CMAKE_SOURCE_DIR}/src/pch.h)
|
||||
target_precompile_headers(${CMAKE_PROJECT_NAME}
|
||||
target_precompile_headers(${PROJECT_NAME}
|
||||
PRIVATE ${CMAKE_SOURCE_DIR}/src/pch.h)
|
||||
endif()
|
||||
|
||||
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
COMPILE_FLAGS "${COMPILE_FLAGS}")
|
||||
|
||||
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
COMPILE_FLAGS_RELWITHDEBINFO "${OPTIMIZE_COMPILE_FLAGS}")
|
||||
|
||||
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
LINK_FLAGS_RELWITHDEBINFO "${OPTIMIZE_LINK_FLAGS}")
|
||||
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME}
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
Qt5::Widgets
|
||||
Qt5::WinExtras
|
||||
Qt5::WebEngineWidgets
|
||||
@@ -129,9 +128,14 @@ macro(cpp_post_target)
|
||||
Dbghelp Version Shlwapi
|
||||
)
|
||||
|
||||
if(NOT ${CMAKE_PROJECT_NAME} STREQUAL "uibase")
|
||||
if(NOT ${PROJECT_NAME} STREQUAL "uibase")
|
||||
requires_project("uibase")
|
||||
endif()
|
||||
|
||||
if(${run_elevated})
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS
|
||||
"/MANIFESTUAC:\"level='requireAdministrator' uiAccess='false'\"")
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
@@ -152,19 +156,33 @@ endfunction()
|
||||
function(requires_project)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 requires "" "" "")
|
||||
|
||||
foreach(project_name ${requires_UNPARSED_ARGUMENTS})
|
||||
if(${project_name} STREQUAL "game_gamebryo")
|
||||
foreach(name ${requires_UNPARSED_ARGUMENTS})
|
||||
if(${name} STREQUAL "game_gamebryo")
|
||||
set(src_dirs
|
||||
"${modorganizer_super_path}/game_gamebryo/src/gamebryo"
|
||||
"${modorganizer_super_path}/game_gamebryo/src/creation")
|
||||
|
||||
set(libs game_gamebryo game_creation)
|
||||
set(include_dirs ${src_dirs})
|
||||
set(libs "")
|
||||
|
||||
if(NOT ${PROJECT_NAME} STREQUAL "game_gamebryo")
|
||||
set(libs ${libs} game_gamebryo)
|
||||
endif()
|
||||
|
||||
if(NOT ${PROJECT_NAME} STREQUAL "game_creation")
|
||||
set(libs ${libs} game_creation)
|
||||
endif()
|
||||
elseif(${name} STREQUAL "usvfs")
|
||||
set(src_dirs "${modorganizer_build_path}/usvfs/src")
|
||||
set(include_dirs "${modorganizer_build_path}/usvfs/include")
|
||||
set(libs "usvfs_x64")
|
||||
else()
|
||||
set(src_dirs "${modorganizer_super_path}/${project_name}/src")
|
||||
set(libs ${project_name})
|
||||
set(src_dirs "${modorganizer_super_path}/${name}/src")
|
||||
set(include_dirs ${src_dirs})
|
||||
set(libs ${name})
|
||||
endif()
|
||||
|
||||
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${src_dirs})
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE ${include_dirs})
|
||||
|
||||
set(has_source_files FALSE)
|
||||
foreach(src_dir ${src_dirs})
|
||||
@@ -176,7 +194,44 @@ function(requires_project)
|
||||
endforeach()
|
||||
|
||||
if(${has_source_files})
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} ${libs})
|
||||
target_link_libraries(${PROJECT_NAME} ${libs})
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
function(requires_library)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 requires "" "" "")
|
||||
|
||||
foreach(name ${requires_UNPARSED_ARGUMENTS})
|
||||
if(${name} STREQUAL "loot")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${LOOT_PATH}/include)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} loot)
|
||||
elseif(${name} STREQUAL "cpptoml")
|
||||
include(ExternalProject)
|
||||
|
||||
ExternalProject_Add(
|
||||
cpptoml
|
||||
PREFIX "external"
|
||||
URL "https://github.com/skystrife/cpptoml/archive/2051836a96a25e5a2d5283be7f633a157848f15e.tar.gz"
|
||||
CONFIGURE_COMMAND ""
|
||||
BUILD_COMMAND ""
|
||||
INSTALL_COMMAND "")
|
||||
|
||||
ExternalProject_Get_Property(cpptoml SOURCE_DIR)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
"${SOURCE_DIR}/include")
|
||||
|
||||
add_dependencies(${PROJECT_NAME} cpptoml)
|
||||
elseif(${name} STREQUAL "python")
|
||||
target_include_directories(${PROJECT_NAME} PRIVATE
|
||||
${PYTHON_ROOT}/Include)
|
||||
else()
|
||||
message(FATAL_ERROR "unknown library ${name}")
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cpp.cmake)
|
||||
|
||||
if(NOT DEFINED install_dir)
|
||||
set(install_dir bin)
|
||||
endif()
|
||||
|
||||
macro(do_project)
|
||||
do_cpp_project()
|
||||
endmacro()
|
||||
@@ -9,13 +13,13 @@ endmacro()
|
||||
macro(do_src)
|
||||
cpp_pre_target()
|
||||
|
||||
add_library(${CMAKE_PROJECT_NAME} SHARED ${input_files})
|
||||
add_library(${PROJECT_NAME} SHARED ${input_files})
|
||||
|
||||
install(TARGETS ${CMAKE_PROJECT_NAME}
|
||||
RUNTIME DESTINATION bin
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
RUNTIME DESTINATION ${install_dir}
|
||||
ARCHIVE DESTINATION libs)
|
||||
|
||||
install(FILES $<TARGET_PDB_FILE:${CMAKE_PROJECT_NAME}>
|
||||
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}>
|
||||
DESTINATION pdb)
|
||||
|
||||
cpp_post_target()
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cpp.cmake)
|
||||
|
||||
if(NOT DEFINED install_dir)
|
||||
set(install_dir bin)
|
||||
endif()
|
||||
|
||||
function(set_project_to_run_from_install)
|
||||
set(vcxproj_user_file "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_PROJECT_NAME}.vcxproj.user")
|
||||
get_target_property(output_name ${CMAKE_PROJECT_NAME} OUTPUT_NAME)
|
||||
set(vcxproj_user_file "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.vcxproj.user")
|
||||
get_target_property(output_name ${PROJECT_NAME} OUTPUT_NAME)
|
||||
|
||||
if(NOT EXISTS ${vcxproj_user_file})
|
||||
file(WRITE ${vcxproj_user_file}
|
||||
@@ -20,20 +24,25 @@ endfunction()
|
||||
|
||||
|
||||
function(deploy_qt)
|
||||
cmake_parse_arguments(PARSE_ARGV 0 deploy_qt "" "" "BINARIES")
|
||||
cmake_parse_arguments(PARSE_ARGV 0 deploy_qt "NOPLUGINS" "" "BINARIES")
|
||||
|
||||
set(qt5bin ${Qt5Core_DIR}/../../../bin)
|
||||
find_program(WINDEPLOYQT_COMMAND windeployqt PATHS ${qt5bin} NO_DEFAULT_PATH)
|
||||
|
||||
set(args
|
||||
"--no-translations \
|
||||
--plugindir qtplugins \
|
||||
--verbose 0 \
|
||||
--webenginewidgets \
|
||||
--websockets \
|
||||
--libdir dlls \
|
||||
--no-compiler-runtime")
|
||||
|
||||
if(${deploy_qt_NOPLUGINS})
|
||||
set(args "${args} --no-plugins")
|
||||
else()
|
||||
set(args "${args} --plugindir qtplugins")
|
||||
endif()
|
||||
|
||||
set(bin "${CMAKE_INSTALL_PREFIX}/bin")
|
||||
|
||||
set(deploys "")
|
||||
@@ -50,11 +59,16 @@ function(deploy_qt)
|
||||
file(REMOVE_RECURSE ${bin}/platforms)
|
||||
file(REMOVE_RECURSE ${bin}/styles)
|
||||
file(REMOVE_RECURSE ${bin}/dlls/imageformats)
|
||||
file(RENAME ${bin}/qtplugins/platforms ${bin}/platforms)
|
||||
file(RENAME ${bin}/qtplugins/styles ${bin}/styles)
|
||||
file(RENAME ${bin}/qtplugins/imageformats ${bin}/dlls/imageformats)
|
||||
file(REMOVE_RECURSE ${bin}/qtplugins)
|
||||
")
|
||||
|
||||
if(NOT ${deploy_qt_NOPLUGINS})
|
||||
install(CODE "
|
||||
file(RENAME ${bin}/qtplugins/platforms ${bin}/platforms)
|
||||
file(RENAME ${bin}/qtplugins/styles ${bin}/styles)
|
||||
file(RENAME ${bin}/qtplugins/imageformats ${bin}/dlls/imageformats)
|
||||
file(REMOVE_RECURSE ${bin}/qtplugins)
|
||||
")
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
|
||||
@@ -66,16 +80,16 @@ endmacro()
|
||||
macro(do_src)
|
||||
cpp_pre_target()
|
||||
|
||||
add_executable(${CMAKE_PROJECT_NAME} WIN32 ${input_files})
|
||||
add_executable(${PROJECT_NAME} WIN32 ${input_files})
|
||||
set_project_to_run_from_install()
|
||||
|
||||
if(DEFINED executable_name)
|
||||
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES
|
||||
set_target_properties(${PROJECT_NAME} PROPERTIES
|
||||
OUTPUT_NAME ${executable_name})
|
||||
endif()
|
||||
|
||||
cpp_post_target()
|
||||
|
||||
install(TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION bin)
|
||||
install(FILES $<TARGET_PDB_FILE:${CMAKE_PROJECT_NAME}> DESTINATION pdb)
|
||||
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${install_dir})
|
||||
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION pdb)
|
||||
endmacro()
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cpp.cmake)
|
||||
|
||||
if(NOT DEFINED install_dir)
|
||||
set(install_dir libs)
|
||||
endif()
|
||||
|
||||
macro(do_project)
|
||||
do_cpp_project()
|
||||
endmacro()
|
||||
@@ -9,10 +13,10 @@ endmacro()
|
||||
macro(do_src)
|
||||
cpp_pre_target()
|
||||
|
||||
add_library(${CMAKE_PROJECT_NAME} STATIC ${input_files})
|
||||
add_library(${PROJECT_NAME} STATIC ${input_files})
|
||||
|
||||
install(TARGETS ${CMAKE_PROJECT_NAME}
|
||||
ARCHIVE DESTINATION libs)
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
ARCHIVE DESTINATION ${install_dir})
|
||||
|
||||
cpp_post_target()
|
||||
endmacro()
|
||||
|
||||
+9
-4
@@ -1,6 +1,11 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/cpp.cmake)
|
||||
|
||||
if(NOT DEFINED install_dir)
|
||||
set(install_dir bin/plugins)
|
||||
endif()
|
||||
|
||||
|
||||
macro(do_project)
|
||||
do_cpp_project()
|
||||
endmacro()
|
||||
@@ -9,12 +14,12 @@ endmacro()
|
||||
macro(do_src)
|
||||
cpp_pre_target()
|
||||
|
||||
add_library(${CMAKE_PROJECT_NAME} SHARED ${input_files})
|
||||
target_link_libraries(${CMAKE_PROJECT_NAME} uibase)
|
||||
add_library(${PROJECT_NAME} SHARED ${input_files})
|
||||
target_link_libraries(${PROJECT_NAME} uibase)
|
||||
|
||||
cpp_post_target()
|
||||
|
||||
|
||||
install(TARGETS ${CMAKE_PROJECT_NAME} RUNTIME DESTINATION bin/plugins)
|
||||
install(FILES $<TARGET_PDB_FILE:${CMAKE_PROJECT_NAME}> DESTINATION pdb)
|
||||
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${install_dir})
|
||||
install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION pdb)
|
||||
endmacro()
|
||||
|
||||
+8
-1
@@ -30,6 +30,11 @@ if(NOT DEFINED additional_translations)
|
||||
set(additional_translations "")
|
||||
endif()
|
||||
|
||||
if(NOT DEFINED run_elevated)
|
||||
set(run_elevated OFF)
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
set(COMPILE_FLAGS "/std:c++latest /MP")
|
||||
set(OPTIMIZE_COMPILE_FLAGS "/O2")
|
||||
@@ -48,12 +53,14 @@ required_variable(BOOST_LIBRARYDIR)
|
||||
required_variable(QT_ROOT)
|
||||
required_variable(FMT_ROOT)
|
||||
required_variable(SPDLOG_ROOT)
|
||||
required_variable(LOOT_PATH)
|
||||
required_variable(LZ4_ROOT)
|
||||
required_variable(ZLIB_ROOT)
|
||||
required_variable(PYTHON_ROOT)
|
||||
required_variable(SEVENZ_ROOT)
|
||||
required_variable(CMAKE_INSTALL_PREFIX)
|
||||
|
||||
get_real_path(modorganizer_build_path "${CMAKE_CURRENT_SOURCE_DIR}/../..")
|
||||
get_real_path(modorganizer_build_path "${CMAKE_CURRENT_LIST_DIR}/../..")
|
||||
get_real_path(modorganizer_super_path "${modorganizer_build_path}/modorganizer_super")
|
||||
get_real_path(uibase_path "${modorganizer_super_path}/uibase")
|
||||
get_real_path(uibase_include_path "${uibase_path}/src")
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ macro(do_python_project)
|
||||
pyqt5_create_translation(
|
||||
qm_files
|
||||
${CMAKE_SOURCE_DIR}/src ${additional_translations}
|
||||
${CMAKE_SOURCE_DIR}/src/${CMAKE_PROJECT_NAME}_en.ts
|
||||
${CMAKE_SOURCE_DIR}/src/${PROJECT_NAME}_en.ts
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
+6
-1
@@ -1,11 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/python.cmake)
|
||||
|
||||
if(NOT DEFINED install_dir)
|
||||
set(install_dir bin/plugins)
|
||||
endif()
|
||||
|
||||
|
||||
macro(do_project)
|
||||
do_python_project()
|
||||
endmacro()
|
||||
|
||||
|
||||
macro(do_src)
|
||||
install(FILES ${source_files} DESTINATION bin/plugins)
|
||||
install(FILES ${source_files} DESTINATION ${install_dir})
|
||||
endmacro()
|
||||
|
||||
Reference in New Issue
Block a user