diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 77be7c54be..7246db7e54 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -132,6 +132,7 @@ Clang_Format: before_script: - CI/install_debian_deps.sh openmw-clang-format script: + - CI/check_cmake_format.sh - CI/check_file_names.sh - CI/check_clang_format.sh diff --git a/CI/check_cmake_format.sh b/CI/check_cmake_format.sh new file mode 100755 index 0000000000..40cd0b77f6 --- /dev/null +++ b/CI/check_cmake_format.sh @@ -0,0 +1,6 @@ +#!/bin/bash -ex + +git ls-files -- ':(exclude)extern/' 'CMakeLists.txt' '*.cmake' | + xargs grep -P '^\s*\t' && + ( echo 'CMake files contain leading tab character. Use only spaces for indentation'; exit -1 ) +exit 0 diff --git a/CMakeLists.txt b/CMakeLists.txt index e2d538ae6c..4954722843 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,9 +58,9 @@ option(BUILD_BULLETOBJECTTOOL "Build Bullet object tool" ON) set(OpenGL_GL_PREFERENCE LEGACY) # Use LEGACY as we use GL2; GLNVD is for GL3 and up. if (NOT BUILD_LAUNCHER AND NOT BUILD_OPENCS AND NOT BUILD_WIZARD) - set(USE_QT FALSE) + set(USE_QT FALSE) else() - set(USE_QT TRUE) + set(USE_QT TRUE) endif() # If the user doesn't supply a CMAKE_BUILD_TYPE via command line, choose one for them. @@ -227,7 +227,7 @@ if (WIN32) endif() if(MSVC) - add_compile_options("/utf-8") + add_compile_options("/utf-8") endif() # Dependencies @@ -237,10 +237,10 @@ find_package(LZ4 REQUIRED) if (USE_QT) find_package(QT REQUIRED COMPONENTS Core NAMES Qt6 Qt5) - if (QT_VERSION_MAJOR VERSION_EQUAL 5) + if (QT_VERSION_MAJOR VERSION_EQUAL 5) find_package(Qt5 5.15 COMPONENTS Core Widgets Network OpenGL REQUIRED) - else() - find_package(Qt6 COMPONENTS Core Widgets Network OpenGL REQUIRED) + else() + find_package(Qt6 COMPONENTS Core Widgets Network OpenGL REQUIRED) endif() message(STATUS "Using Qt${QT_VERSION}") endif() @@ -509,7 +509,7 @@ include_directories( link_directories(${SDL2_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS} ${COLLADA_DOM_LIBRARY_DIRS}) if(MYGUI_STATIC) - add_definitions(-DMYGUI_STATIC) + add_definitions(-DMYGUI_STATIC) endif (MYGUI_STATIC) if (APPLE) @@ -638,31 +638,31 @@ if (BUILD_OPENMW) endif() if (BUILD_BSATOOL) - add_subdirectory( apps/bsatool ) + add_subdirectory( apps/bsatool ) endif() if (BUILD_ESMTOOL) - add_subdirectory( apps/esmtool ) + add_subdirectory( apps/esmtool ) endif() if (BUILD_LAUNCHER) - add_subdirectory( apps/launcher ) + add_subdirectory( apps/launcher ) endif() if (BUILD_MWINIIMPORTER) - add_subdirectory( apps/mwiniimporter ) + add_subdirectory( apps/mwiniimporter ) endif() if (BUILD_ESSIMPORTER) - add_subdirectory (apps/essimporter ) + add_subdirectory (apps/essimporter ) endif() if (BUILD_OPENCS) - add_subdirectory (apps/opencs) + add_subdirectory (apps/opencs) endif() if (BUILD_WIZARD) - add_subdirectory(apps/wizard) + add_subdirectory(apps/wizard) endif() if (BUILD_NIFTEST) @@ -671,136 +671,136 @@ endif(BUILD_NIFTEST) # UnitTests if (BUILD_UNITTESTS) - add_subdirectory( apps/openmw_test_suite ) + add_subdirectory( apps/openmw_test_suite ) endif() if (BUILD_BENCHMARKS) - add_subdirectory(apps/benchmarks) + add_subdirectory(apps/benchmarks) endif() if (BUILD_NAVMESHTOOL) - add_subdirectory(apps/navmeshtool) + add_subdirectory(apps/navmeshtool) endif() if (BUILD_BULLETOBJECTTOOL) - add_subdirectory( apps/bulletobjecttool ) + add_subdirectory( apps/bulletobjecttool ) endif() if (WIN32) - if (MSVC) - foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) - string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) - set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "$(SolutionDir)$(Configuration)" ) - set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "$(ProjectDir)$(Configuration)" ) - endforeach( OUTPUTCONFIG ) - - if (USE_DEBUG_CONSOLE AND BUILD_OPENMW) - set_target_properties(openmw PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") - set_target_properties(openmw PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE") - set_target_properties(openmw PROPERTIES COMPILE_DEFINITIONS $<$:_CONSOLE>) - elseif (BUILD_OPENMW) - # Turn off debug console, debug output will be written to visual studio output instead - set_target_properties(openmw PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS") - set_target_properties(openmw PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:WINDOWS") - endif() + if (MSVC) + foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} ) + string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG ) + set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "$(SolutionDir)$(Configuration)" ) + set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} "$(ProjectDir)$(Configuration)" ) + endforeach( OUTPUTCONFIG ) + + if (USE_DEBUG_CONSOLE AND BUILD_OPENMW) + set_target_properties(openmw PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:CONSOLE") + set_target_properties(openmw PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:CONSOLE") + set_target_properties(openmw PROPERTIES COMPILE_DEFINITIONS $<$:_CONSOLE>) + elseif (BUILD_OPENMW) + # Turn off debug console, debug output will be written to visual studio output instead + set_target_properties(openmw PROPERTIES LINK_FLAGS_DEBUG "/SUBSYSTEM:WINDOWS") + set_target_properties(openmw PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/SUBSYSTEM:WINDOWS") + endif() - if (BUILD_OPENMW) - # Release builds don't use the debug console - set_target_properties(openmw PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") - set_target_properties(openmw PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS") - endif() + if (BUILD_OPENMW) + # Release builds don't use the debug console + set_target_properties(openmw PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") + set_target_properties(openmw PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS") + endif() - # Play a bit with the warning levels - - set(WARNINGS "/W4") - - set(WARNINGS_DISABLE - 4100 # Unreferenced formal parameter (-Wunused-parameter) - 4127 # Conditional expression is constant - 4996 # Function was declared deprecated - 5054 # Deprecated operations between enumerations of different types caused by Qt headers - ) - - if( "${MyGUI_VERSION}" VERSION_LESS_EQUAL "3.4.0" ) - set(WARNINGS_DISABLE ${WARNINGS_DISABLE} - 4866 # compiler may not enforce left-to-right evaluation order for call - ) - endif() + # Play a bit with the warning levels - if( "${MyGUI_VERSION}" VERSION_LESS_EQUAL "3.4.1" ) - set(WARNINGS_DISABLE ${WARNINGS_DISABLE} - 4275 # non dll-interface class 'MyGUI::delegates::IDelegateUnlink' used as base for dll-interface class 'MyGUI::Widget' - ) - endif() + set(WARNINGS "/W4") - foreach(d ${WARNINGS_DISABLE}) - set(WARNINGS "${WARNINGS} /wd${d}") - endforeach(d) + set(WARNINGS_DISABLE + 4100 # Unreferenced formal parameter (-Wunused-parameter) + 4127 # Conditional expression is constant + 4996 # Function was declared deprecated + 5054 # Deprecated operations between enumerations of different types caused by Qt headers + ) - if(OPENMW_MSVC_WERROR) - set(WARNINGS "${WARNINGS} /WX") - endif() + if( "${MyGUI_VERSION}" VERSION_LESS_EQUAL "3.4.0" ) + set(WARNINGS_DISABLE ${WARNINGS_DISABLE} + 4866 # compiler may not enforce left-to-right evaluation order for call + ) + endif() - set_target_properties(components PROPERTIES COMPILE_FLAGS "${WARNINGS}") - set_target_properties(osg-ffmpeg-videoplayer PROPERTIES COMPILE_FLAGS "${WARNINGS}") - - if (MSVC_VERSION GREATER_EQUAL 1915 AND MSVC_VERSION LESS 1920) - target_compile_definitions(components INTERFACE _ENABLE_EXTENDED_ALIGNED_STORAGE) - endif() + if( "${MyGUI_VERSION}" VERSION_LESS_EQUAL "3.4.1" ) + set(WARNINGS_DISABLE ${WARNINGS_DISABLE} + 4275 # non dll-interface class 'MyGUI::delegates::IDelegateUnlink' used as base for dll-interface class 'MyGUI::Widget' + ) + endif() - if (BUILD_BSATOOL) - set_target_properties(bsatool PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + foreach(d ${WARNINGS_DISABLE}) + set(WARNINGS "${WARNINGS} /wd${d}") + endforeach(d) - if (BUILD_ESMTOOL) - set_target_properties(esmtool PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if(OPENMW_MSVC_WERROR) + set(WARNINGS "${WARNINGS} /WX") + endif() - if (BUILD_ESSIMPORTER) - set_target_properties(openmw-essimporter PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + set_target_properties(components PROPERTIES COMPILE_FLAGS "${WARNINGS}") + set_target_properties(osg-ffmpeg-videoplayer PROPERTIES COMPILE_FLAGS "${WARNINGS}") - if (BUILD_LAUNCHER) - set_target_properties(openmw-launcher PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if (MSVC_VERSION GREATER_EQUAL 1915 AND MSVC_VERSION LESS 1920) + target_compile_definitions(components INTERFACE _ENABLE_EXTENDED_ALIGNED_STORAGE) + endif() - if (BUILD_MWINIIMPORTER) - set_target_properties(openmw-iniimporter PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if (BUILD_BSATOOL) + set_target_properties(bsatool PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() - if (BUILD_OPENCS) - set_target_properties(openmw-cs PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if (BUILD_ESMTOOL) + set_target_properties(esmtool PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() - if (BUILD_OPENMW) - set_target_properties(openmw PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if (BUILD_ESSIMPORTER) + set_target_properties(openmw-essimporter PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() - if (BUILD_WIZARD) - set_target_properties(openmw-wizard PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if (BUILD_LAUNCHER) + set_target_properties(openmw-launcher PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() - if (BUILD_UNITTESTS) - set_target_properties(openmw_test_suite PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if (BUILD_MWINIIMPORTER) + set_target_properties(openmw-iniimporter PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() - if (BUILD_BENCHMARKS) - set_target_properties(openmw_detournavigator_navmeshtilescache_benchmark PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if (BUILD_OPENCS) + set_target_properties(openmw-cs PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() - if (BUILD_NAVMESHTOOL) - set_target_properties(openmw-navmeshtool PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() + if (BUILD_OPENMW) + set_target_properties(openmw PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() - if (BUILD_BULLETOBJECTTOOL) - set(WARNINGS "${WARNINGS} ${MT_BUILD}") - set_target_properties(openmw-bulletobjecttool PROPERTIES COMPILE_FLAGS "${WARNINGS}") - endif() - endif(MSVC) + if (BUILD_WIZARD) + set_target_properties(openmw-wizard PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() + + if (BUILD_UNITTESTS) + set_target_properties(openmw_test_suite PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() + + if (BUILD_BENCHMARKS) + set_target_properties(openmw_detournavigator_navmeshtilescache_benchmark PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() + + if (BUILD_NAVMESHTOOL) + set_target_properties(openmw-navmeshtool PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() + + if (BUILD_BULLETOBJECTTOOL) + set(WARNINGS "${WARNINGS} ${MT_BUILD}") + set_target_properties(openmw-bulletobjecttool PROPERTIES COMPILE_FLAGS "${WARNINGS}") + endif() + endif(MSVC) - # TODO: At some point release builds should not use the console but rather write to a log file - #set_target_properties(openmw PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") - #set_target_properties(openmw PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS") + # TODO: At some point release builds should not use the console but rather write to a log file + #set_target_properties(openmw PROPERTIES LINK_FLAGS_RELEASE "/SUBSYSTEM:WINDOWS") + #set_target_properties(openmw PROPERTIES LINK_FLAGS_MINSIZEREL "/SUBSYSTEM:WINDOWS") endif() if (BUILD_OPENMW AND APPLE) @@ -829,11 +829,11 @@ if (OPENMW_OSX_DEPLOYMENT AND APPLE) configure_file("${OpenMW_SOURCE_DIR}/files/mac/qt.conf" "${APP_BUNDLE_DIR}/Contents/Resources/qt.conf" COPYONLY) if (BUILD_OPENCS) - get_property(OPENCS_BUNDLE_NAME_TMP TARGET openmw-cs PROPERTY OUTPUT_NAME) - set(OPENCS_BUNDLE_NAME "${OPENCS_BUNDLE_NAME_TMP}.app") - configure_file("${QT_COCOA_PLUGIN_PATH}" "${OPENCS_BUNDLE_NAME}/Contents/PlugIns/${QT_COCOA_PLUGIN_GROUP}/${QT_COCOA_PLUGIN_NAME}" COPYONLY) - configure_file("${QT_QMACSTYLE_PLUGIN_PATH}" "${OPENCS_BUNDLE_NAME}/Contents/PlugIns/${QT_QMACSTYLE_PLUGIN_GROUP}/${QT_QMACSTYLE_PLUGIN_NAME}" COPYONLY) - configure_file("${OpenMW_SOURCE_DIR}/files/mac/qt.conf" "${OPENCS_BUNDLE_NAME}/Contents/Resources/qt.conf" COPYONLY) + get_property(OPENCS_BUNDLE_NAME_TMP TARGET openmw-cs PROPERTY OUTPUT_NAME) + set(OPENCS_BUNDLE_NAME "${OPENCS_BUNDLE_NAME_TMP}.app") + configure_file("${QT_COCOA_PLUGIN_PATH}" "${OPENCS_BUNDLE_NAME}/Contents/PlugIns/${QT_COCOA_PLUGIN_GROUP}/${QT_COCOA_PLUGIN_NAME}" COPYONLY) + configure_file("${QT_QMACSTYLE_PLUGIN_PATH}" "${OPENCS_BUNDLE_NAME}/Contents/PlugIns/${QT_QMACSTYLE_PLUGIN_GROUP}/${QT_QMACSTYLE_PLUGIN_NAME}" COPYONLY) + configure_file("${OpenMW_SOURCE_DIR}/files/mac/qt.conf" "${OPENCS_BUNDLE_NAME}/Contents/Resources/qt.conf" COPYONLY) endif () install(DIRECTORY "${APP_BUNDLE_DIR}" USE_SOURCE_PERMISSIONS DESTINATION "." COMPONENT Runtime) diff --git a/apps/benchmarks/CMakeLists.txt b/apps/benchmarks/CMakeLists.txt index 095a841742..18bc56ec60 100644 --- a/apps/benchmarks/CMakeLists.txt +++ b/apps/benchmarks/CMakeLists.txt @@ -13,3 +13,8 @@ endif() if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) target_precompile_headers(openmw_detournavigator_navmeshtilescache_benchmark PRIVATE ) endif() + +if (BUILD_WITH_CODE_COVERAGE) + target_compile_options(openmw_detournavigator_navmeshtilescache_benchmark PRIVATE --coverage) + target_link_libraries(openmw_detournavigator_navmeshtilescache_benchmark gcov) +endif() diff --git a/apps/bsatool/CMakeLists.txt b/apps/bsatool/CMakeLists.txt index 6312c33aaf..0ee6d8472a 100644 --- a/apps/bsatool/CMakeLists.txt +++ b/apps/bsatool/CMakeLists.txt @@ -1,21 +1,21 @@ set(BSATOOL - bsatool.cpp + bsatool.cpp ) source_group(apps\\bsatool FILES ${BSATOOL}) # Main executable openmw_add_executable(bsatool - ${BSATOOL} + ${BSATOOL} ) target_link_libraries(bsatool - ${Boost_PROGRAM_OPTIONS_LIBRARY} - components + ${Boost_PROGRAM_OPTIONS_LIBRARY} + components ) if (BUILD_WITH_CODE_COVERAGE) - add_definitions (--coverage) - target_link_libraries(bsatool gcov) + target_compile_options(bsatool PRIVATE --coverage) + target_link_libraries(bsatool gcov) endif() if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) diff --git a/apps/bulletobjecttool/CMakeLists.txt b/apps/bulletobjecttool/CMakeLists.txt index bc19a29e21..924f66301c 100644 --- a/apps/bulletobjecttool/CMakeLists.txt +++ b/apps/bulletobjecttool/CMakeLists.txt @@ -11,7 +11,7 @@ target_link_libraries(openmw-bulletobjecttool ) if (BUILD_WITH_CODE_COVERAGE) - add_definitions(--coverage) + target_compile_options(openmw-bulletobjecttool PRIVATE --coverage) target_link_libraries(openmw-bulletobjecttool gcov) endif() diff --git a/apps/esmtool/CMakeLists.txt b/apps/esmtool/CMakeLists.txt index 841fb4b219..ad95b2b8e5 100644 --- a/apps/esmtool/CMakeLists.txt +++ b/apps/esmtool/CMakeLists.txt @@ -1,28 +1,28 @@ set(ESMTOOL - esmtool.cpp - labels.hpp - labels.cpp - record.hpp - record.cpp - arguments.hpp - tes4.hpp - tes4.cpp + esmtool.cpp + labels.hpp + labels.cpp + record.hpp + record.cpp + arguments.hpp + tes4.hpp + tes4.cpp ) source_group(apps\\esmtool FILES ${ESMTOOL}) # Main executable openmw_add_executable(esmtool - ${ESMTOOL} + ${ESMTOOL} ) target_link_libraries(esmtool - ${Boost_PROGRAM_OPTIONS_LIBRARY} - components + ${Boost_PROGRAM_OPTIONS_LIBRARY} + components ) if (BUILD_WITH_CODE_COVERAGE) - add_definitions (--coverage) - target_link_libraries(esmtool gcov) + target_compile_options(esmtool PRIVATE --coverage) + target_link_libraries(esmtool gcov) endif() if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) diff --git a/apps/essimporter/CMakeLists.txt b/apps/essimporter/CMakeLists.txt index 4d53bc4cb3..3928d88e8f 100644 --- a/apps/essimporter/CMakeLists.txt +++ b/apps/essimporter/CMakeLists.txt @@ -39,12 +39,12 @@ target_link_libraries(openmw-essimporter ) if (BUILD_WITH_CODE_COVERAGE) - add_definitions (--coverage) - target_link_libraries(openmw-essimporter gcov) + target_compile_options(openmw-essimporter PRIVATE --coverage) + target_link_libraries(openmw-essimporter gcov) endif() if (WIN32) - INSTALL(TARGETS openmw-essimporter RUNTIME DESTINATION ".") + INSTALL(TARGETS openmw-essimporter RUNTIME DESTINATION ".") endif(WIN32) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 790c5436f0..fe27dfc498 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -85,8 +85,8 @@ target_link_libraries(openmw-launcher target_link_libraries(openmw-launcher Qt::Widgets Qt::Core) if (BUILD_WITH_CODE_COVERAGE) - add_definitions (--coverage) - target_link_libraries(openmw-launcher gcov) + target_compile_options(openmw-launcher PRIVATE --coverage) + target_link_libraries(openmw-launcher gcov) endif() if(USE_QT) diff --git a/apps/mwiniimporter/CMakeLists.txt b/apps/mwiniimporter/CMakeLists.txt index 3f767bc6f6..d5cd2e6362 100644 --- a/apps/mwiniimporter/CMakeLists.txt +++ b/apps/mwiniimporter/CMakeLists.txt @@ -25,12 +25,12 @@ if (WIN32) endif(WIN32) if (MINGW) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -municode") endif() if (BUILD_WITH_CODE_COVERAGE) - add_definitions (--coverage) - target_link_libraries(openmw-iniimporter gcov) + target_compile_options(openmw-iniimporter PRIVATE --coverage) + target_link_libraries(openmw-iniimporter gcov) endif() if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) diff --git a/apps/navmeshtool/CMakeLists.txt b/apps/navmeshtool/CMakeLists.txt index 9f57d52a7e..09d7af3b23 100644 --- a/apps/navmeshtool/CMakeLists.txt +++ b/apps/navmeshtool/CMakeLists.txt @@ -13,7 +13,7 @@ target_link_libraries(openmw-navmeshtool ) if (BUILD_WITH_CODE_COVERAGE) - add_definitions(--coverage) + target_compile_options(openmw-navmeshtool PRIVATE --coverage) target_link_libraries(openmw-navmeshtool gcov) endif() diff --git a/apps/niftest/CMakeLists.txt b/apps/niftest/CMakeLists.txt index 2f0dcb59e3..5ca21c10c7 100644 --- a/apps/niftest/CMakeLists.txt +++ b/apps/niftest/CMakeLists.txt @@ -9,12 +9,12 @@ openmw_add_executable(niftest ) target_link_libraries(niftest - components + components ) if (BUILD_WITH_CODE_COVERAGE) - add_definitions (--coverage) - target_link_libraries(niftest gcov) + target_compile_options(niftest PRIVATE --coverage) + target_link_libraries(niftest gcov) endif() if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index ab63be0437..a55ba56330 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -260,6 +260,11 @@ if(USE_QT) set_property(TARGET openmw-cs PROPERTY AUTOMOC ON) endif(USE_QT) +if (BUILD_WITH_CODE_COVERAGE) + target_compile_options(openmw-cs PRIVATE --coverage) + target_link_libraries(openmw-cs gcov) +endif() + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16 AND MSVC) target_precompile_headers(openmw-cs PRIVATE diff --git a/apps/openmw/CMakeLists.txt b/apps/openmw/CMakeLists.txt index ff2ecfe5c9..15a6b8713c 100644 --- a/apps/openmw/CMakeLists.txt +++ b/apps/openmw/CMakeLists.txt @@ -192,12 +192,12 @@ if (USE_SYSTEM_TINYXML) endif() if (NOT UNIX) -target_link_libraries(openmw ${SDL2MAIN_LIBRARY}) + target_link_libraries(openmw ${SDL2MAIN_LIBRARY}) endif() # Fix for not visible pthreads functions for linker with glibc 2.15 if (UNIX AND NOT APPLE) -target_link_libraries(openmw ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(openmw ${CMAKE_THREAD_LIBS_INIT}) endif() if(APPLE) @@ -230,8 +230,8 @@ if(APPLE) endif(APPLE) if (BUILD_WITH_CODE_COVERAGE) - add_definitions (--coverage) - target_link_libraries(openmw gcov) + target_compile_options(openmw PRIVATE --coverage) + target_link_libraries(openmw gcov) endif() if (WIN32) diff --git a/apps/openmw_test_suite/CMakeLists.txt b/apps/openmw_test_suite/CMakeLists.txt index ae5723cd25..6e7f191eae 100644 --- a/apps/openmw_test_suite/CMakeLists.txt +++ b/apps/openmw_test_suite/CMakeLists.txt @@ -108,7 +108,7 @@ if (UNIX AND NOT APPLE) endif() if (BUILD_WITH_CODE_COVERAGE) - add_definitions(--coverage) + target_compile_options(openmw_test_suite PRIVATE --coverage) target_link_libraries(openmw_test_suite gcov) endif() diff --git a/apps/wizard/CMakeLists.txt b/apps/wizard/CMakeLists.txt index 895fe0ee46..588b100ef2 100644 --- a/apps/wizard/CMakeLists.txt +++ b/apps/wizard/CMakeLists.txt @@ -94,13 +94,13 @@ if(DPKG_PROGRAM) endif() if (BUILD_WITH_CODE_COVERAGE) - add_definitions (--coverage) - target_link_libraries(openmw-wizard gcov) + target_compile_options(openmw-wizard PRIVATE --coverage) + target_link_libraries(openmw-wizard gcov) endif() # Workaround for binutil => 2.23 problem when linking, should be fixed eventually upstream if (CMAKE_SYSTEM_NAME MATCHES "Linux") -target_link_libraries(openmw-wizard dl Xt) + target_link_libraries(openmw-wizard dl Xt) endif() if (WIN32) diff --git a/cmake/OpenMWMacros.cmake b/cmake/OpenMWMacros.cmake index 2cb7e6eec8..991125526d 100644 --- a/cmake/OpenMWMacros.cmake +++ b/cmake/OpenMWMacros.cmake @@ -112,64 +112,64 @@ endmacro (opencs_hdrs) include(CMakeParseArguments) macro (openmw_add_executable target) - set(OMW_ADD_EXE_OPTIONS WIN32 MACOSX_BUNDLE EXCLUDE_FROM_ALL) - set(OMW_ADD_EXE_VALUES) - set(OMW_ADD_EXE_MULTI_VALUES) - cmake_parse_arguments(OMW_ADD_EXE "${OMW_ADD_EXE_OPTIONS}" "${OMW_ADD_EXE_VALUES}" "${OMW_ADD_EXE_MULTI_VALUES}" ${ARGN}) - - if (OMW_ADD_EXE_WIN32) - set(OMW_ADD_EXE_WIN32_VALUE WIN32) - endif (OMW_ADD_EXE_WIN32) - - if (OMW_ADD_EXE_MACOSX_BUNDLE) - set(OMW_ADD_EXE_MACOSX_BUNDLE_VALUE MACOSX_BUNDLE) - endif (OMW_ADD_EXE_MACOSX_BUNDLE) - - if (OMW_ADD_EXE_EXCLUDE_FROM_ALL) - set(OMW_ADD_EXE_EXCLUDE_FROM_ALL_VALUE EXCLUDE_FROM_ALL) - endif (OMW_ADD_EXE_EXCLUDE_FROM_ALL) - - add_executable(${target} ${OMW_ADD_EXE_WIN32_VALUE} ${OMW_ADD_EXE_MACOSX_BUNDLE_VALUE} ${OMW_ADD_EXE_EXCLUDE_FROM_ALL_VALUE} ${OMW_ADD_EXE_UNPARSED_ARGUMENTS}) - - if (MSVC) - if (CMAKE_VERSION VERSION_GREATER 3.8 OR CMAKE_VERSION VERSION_EQUAL 3.8) - set_target_properties(${target} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$") - endif (CMAKE_VERSION VERSION_GREATER 3.8 OR CMAKE_VERSION VERSION_EQUAL 3.8) - endif (MSVC) + set(OMW_ADD_EXE_OPTIONS WIN32 MACOSX_BUNDLE EXCLUDE_FROM_ALL) + set(OMW_ADD_EXE_VALUES) + set(OMW_ADD_EXE_MULTI_VALUES) + cmake_parse_arguments(OMW_ADD_EXE "${OMW_ADD_EXE_OPTIONS}" "${OMW_ADD_EXE_VALUES}" "${OMW_ADD_EXE_MULTI_VALUES}" ${ARGN}) + + if (OMW_ADD_EXE_WIN32) + set(OMW_ADD_EXE_WIN32_VALUE WIN32) + endif (OMW_ADD_EXE_WIN32) + + if (OMW_ADD_EXE_MACOSX_BUNDLE) + set(OMW_ADD_EXE_MACOSX_BUNDLE_VALUE MACOSX_BUNDLE) + endif (OMW_ADD_EXE_MACOSX_BUNDLE) + + if (OMW_ADD_EXE_EXCLUDE_FROM_ALL) + set(OMW_ADD_EXE_EXCLUDE_FROM_ALL_VALUE EXCLUDE_FROM_ALL) + endif (OMW_ADD_EXE_EXCLUDE_FROM_ALL) + + add_executable(${target} ${OMW_ADD_EXE_WIN32_VALUE} ${OMW_ADD_EXE_MACOSX_BUNDLE_VALUE} ${OMW_ADD_EXE_EXCLUDE_FROM_ALL_VALUE} ${OMW_ADD_EXE_UNPARSED_ARGUMENTS}) + + if (MSVC) + if (CMAKE_VERSION VERSION_GREATER 3.8 OR CMAKE_VERSION VERSION_EQUAL 3.8) + set_target_properties(${target} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "$") + endif (CMAKE_VERSION VERSION_GREATER 3.8 OR CMAKE_VERSION VERSION_EQUAL 3.8) + endif (MSVC) endmacro (openmw_add_executable) macro (get_generator_is_multi_config VALUE) - if (DEFINED generator_is_multi_config_var) - set(${VALUE} ${generator_is_multi_config_var}) - else (DEFINED generator_is_multi_config_var) - if (CMAKE_VERSION VERSION_GREATER 3.9 OR CMAKE_VERSION VERSION_EQUAL 3.9) - get_cmake_property(${VALUE} GENERATOR_IS_MULTI_CONFIG) - else (CMAKE_VERSION VERSION_GREATER 3.9 OR CMAKE_VERSION VERSION_EQUAL 3.9) - list(LENGTH CMAKE_CONFIGURATION_TYPES ${VALUE}) - endif (CMAKE_VERSION VERSION_GREATER 3.9 OR CMAKE_VERSION VERSION_EQUAL 3.9) - endif (DEFINED generator_is_multi_config_var) + if (DEFINED generator_is_multi_config_var) + set(${VALUE} ${generator_is_multi_config_var}) + else (DEFINED generator_is_multi_config_var) + if (CMAKE_VERSION VERSION_GREATER 3.9 OR CMAKE_VERSION VERSION_EQUAL 3.9) + get_cmake_property(${VALUE} GENERATOR_IS_MULTI_CONFIG) + else (CMAKE_VERSION VERSION_GREATER 3.9 OR CMAKE_VERSION VERSION_EQUAL 3.9) + list(LENGTH CMAKE_CONFIGURATION_TYPES ${VALUE}) + endif (CMAKE_VERSION VERSION_GREATER 3.9 OR CMAKE_VERSION VERSION_EQUAL 3.9) + endif (DEFINED generator_is_multi_config_var) endmacro (get_generator_is_multi_config) macro (copy_resource_file source_path destination_dir_base dest_path_relative) - get_generator_is_multi_config(multi_config) - if (multi_config) - foreach(cfgtype ${CMAKE_CONFIGURATION_TYPES}) - configure_file(${source_path} "${destination_dir_base}/${cfgtype}/${dest_path_relative}" COPYONLY) - endforeach(cfgtype) - else (multi_config) - configure_file(${source_path} "${destination_dir_base}/${dest_path_relative}" COPYONLY) - endif (multi_config) + get_generator_is_multi_config(multi_config) + if (multi_config) + foreach(cfgtype ${CMAKE_CONFIGURATION_TYPES}) + configure_file(${source_path} "${destination_dir_base}/${cfgtype}/${dest_path_relative}" COPYONLY) + endforeach(cfgtype) + else (multi_config) + configure_file(${source_path} "${destination_dir_base}/${dest_path_relative}" COPYONLY) + endif (multi_config) endmacro (copy_resource_file) macro (configure_resource_file source_path destination_dir_base dest_path_relative) - get_generator_is_multi_config(multi_config) - if (multi_config) - foreach(cfgtype ${CMAKE_CONFIGURATION_TYPES}) - configure_file(${source_path} "${destination_dir_base}/${cfgtype}/${dest_path_relative}") - endforeach(cfgtype) - else (multi_config) - configure_file(${source_path} "${destination_dir_base}/${dest_path_relative}") - endif (multi_config) + get_generator_is_multi_config(multi_config) + if (multi_config) + foreach(cfgtype ${CMAKE_CONFIGURATION_TYPES}) + configure_file(${source_path} "${destination_dir_base}/${cfgtype}/${dest_path_relative}") + endforeach(cfgtype) + else (multi_config) + configure_file(${source_path} "${destination_dir_base}/${dest_path_relative}") + endif (multi_config) endmacro (configure_resource_file) macro (pack_resource_file source_path destination_dir_base dest_path_relative) @@ -185,8 +185,8 @@ macro (pack_resource_file source_path destination_dir_base dest_path_relative) endmacro (pack_resource_file) macro (copy_all_resource_files source_dir destination_dir_base destination_dir_relative files) - foreach (f ${files}) - get_filename_component(filename ${f} NAME) - copy_resource_file("${source_dir}/${f}" "${destination_dir_base}" "${destination_dir_relative}/${f}") - endforeach (f) + foreach (f ${files}) + get_filename_component(filename ${f} NAME) + copy_resource_file("${source_dir}/${f}" "${destination_dir_base}" "${destination_dir_relative}/${f}") + endforeach (f) endmacro (copy_all_resource_files) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index a78d8c61cb..5304086ee7 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -462,6 +462,11 @@ if (USE_QT) add_library(components_qt STATIC ${COMPONENT_QT_FILES} ${ESM_UI_HDR}) target_link_libraries(components_qt components Qt::Widgets Qt::Core) target_compile_definitions(components_qt PRIVATE OPENMW_DOC_BASEURL="${OPENMW_DOC_BASEURL}") + + if (BUILD_WITH_CODE_COVERAGE) + target_compile_options(components_qt PRIVATE --coverage) + target_link_libraries(components_qt gcov) + endif() endif() if (GIT_CHECKOUT) @@ -483,11 +488,11 @@ endif() # Fix for not visible pthreads functions for linker with glibc 2.15 if (UNIX AND NOT APPLE) -target_link_libraries(components ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(components ${CMAKE_THREAD_LIBS_INIT}) endif() if (BUILD_WITH_CODE_COVERAGE) - add_definitions(--coverage) + target_compile_options(components PRIVATE --coverage) target_link_libraries(components gcov) endif()