1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-24 08:32:34 +02:00

CMake: multiple improvements for builds and project generation

- Change default build output directory name from "build" to "bin"
- Implement new function vcmi_get_cmake_debug_info
- Link client with SDL2main on Windows and disable debug console
- Remove all old MinGW-specific options since they outdated and MXE work fine
- Set AUTOGEN_TARGETS_FOLDER for better Xcode and Visual Studio projects
- Remove useless vcmitestFiles custom target for less garbage in project files
This commit is contained in:
Arseniy Shestakov 2017-08-11 05:31:23 +03:00
parent 56f89270db
commit 7dca95c8cc
6 changed files with 49 additions and 29 deletions

View File

@ -6,6 +6,7 @@ if(NOT CMAKE_BUILD_TYPE)
FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo)
endif()
set(CMAKE_MACOSX_RPATH 1)
set(CMAKE_MODULE_PATH ${CMAKE_HOME_DIRECTORY}/cmake_modules)
include(VCMIUtils)
@ -57,14 +58,14 @@ if(WIN32)
if(MINGW)
#MinGW: check for iconv (may be needed for boost.locale)
include(CheckLibraryExists)
check_library_exists(iconv libiconv_open "" ICONV_FOUND)
if(ICONV_FOUND)
set(SYSTEM_LIBS ${SYSTEM_LIBS} iconv)
endif()
#include(CheckLibraryExists)
#check_library_exists(iconv libiconv_open "" ICONV_FOUND)
#if(ICONV_FOUND)
# set(SYSTEM_LIBS ${SYSTEM_LIBS} iconv)
#endif()
#MinGW: use O1 to prevent compiler crash in some cases
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O1")
endif()
if(MSVC)
@ -73,7 +74,7 @@ if(WIN32)
set(Boost_USE_STATIC_LIBS OFF)
#MSVC: Don't link with SDLMain
set(SDL2_BUILDING_LIBRARY ON)
#set(SDL2_BUILDING_LIBRARY ON)
#MSVC: Suppress warnings
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
@ -125,11 +126,6 @@ if(ENABLE_LAUNCHER)
find_package(Qt5Network REQUIRED)
endif()
if(ENABLE_TEST)
# find_package overwrites BOOST_* variables which are already set, so all components have to be included again
find_package(Boost 1.48.0 COMPONENTS date_time program_options filesystem system thread locale REQUIRED)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32) #so far all *nix compilers support such parameters
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CLANG_SPECIFIC_FLAGS "-Wno-mismatched-tags -Wno-unknown-warning-option")
@ -252,6 +248,12 @@ set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSIO
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
INSTALL(CODE "
set(BU_CHMOD_BUNDLE_ITEMS ON)
include(BundleUtilities)
fixup_bundle(\"${APP_BUNDLE_DIR}\" \"\" \"\")
" COMPONENT Runtime)
if("${PACKAGE_NAME_SUFFIX}" STREQUAL "")
set(CPACK_PACKAGE_NAME "VCMI")
else()

View File

@ -219,9 +219,10 @@ static void SDLLogCallback(void* userdata,
logGlobal->debug("SDL(category %d; priority %d) %s", category, priority, message);
}
#if defined(VCMI_WINDOWS) && !defined (__GNUC__)
int wmain(int argc, wchar_t* argv[])
#elif defined(VCMI_APPLE) || defined(VCMI_ANDROID)
//#if defined(VCMI_WINDOWS) && !defined (__GNUC__)
//int wmain(int argc, wchar_t* argv[])
//#el
#if defined(VCMI_APPLE) || defined(VCMI_ANDROID)
int SDL_main(int argc, char *argv[])
#else
int main(int argc, char * argv[])

View File

@ -133,6 +133,7 @@ if(WIN32)
OUTPUT_NAME "VCMI_client"
PROJECT_LABEL "VCMI_client"
)
target_link_libraries(vcmiclient ${SDLMAIN_LIBRARY})
endif()
target_link_libraries(vcmiclient vcmi ${Boost_LIBRARIES} ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLMIXER_LIBRARY} ${SDLTTF_LIBRARY} ${ZLIB_LIBRARIES} ${FFMPEG_LIBRARIES} ${FFMPEG_EXTRA_LINKING_OPTIONS} ${SYSTEM_LIBS})

View File

@ -15,22 +15,16 @@ macro(vcmi_set_output_dir name dir)
# Multi-config builds for Visual Studio, Xcode
foreach (OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIGUPPERCASE)
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/${OUTPUTCONFIG}/${dir})
set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/${OUTPUTCONFIG}/${dir})
set_target_properties(${name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/${OUTPUTCONFIG}/${dir})
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/bin/${OUTPUTCONFIG}/${dir})
set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/bin/${OUTPUTCONFIG}/${dir})
set_target_properties(${name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIGUPPERCASE} ${CMAKE_BINARY_DIR}/bin/${OUTPUTCONFIG}/${dir})
endforeach()
# Generic no-config case for Makefiles, Ninja.
# This is what Qt Creator is using
if(APPLE)
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${APP_BUNDLE_BINARY_DIR}/${dir})
set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${APP_BUNDLE_BINARY_DIR}/${dir})
set_target_properties(${name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${APP_BUNDLE_BINARY_DIR}/${dir})
else()
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/${dir})
set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/${dir})
set_target_properties(${name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/build/${dir})
endif()
set_target_properties(${name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${dir})
set_target_properties(${name} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${dir})
set_target_properties(${name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/${dir})
endmacro()
#######################################
@ -79,3 +73,21 @@ if(${CMAKE_GENERATOR} MATCHES "Xcode")
endmacro(set_xcode_property)
endif(${CMAKE_GENERATOR} MATCHES "Xcode")
#######################################
# CMake debugging #
#######################################
# Can be called to see check cmake variables and environment variables
# For "install" debugging just copy it here. There no easy way to include modules from source.
function(vcmi_get_cmake_debug_info)
message(STATUS "Debug - Internal variables:")
get_cmake_property(_variableNames VARIABLES)
foreach(_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
message(STATUS "Debug - Environment variables:")
execute_process(COMMAND "${CMAKE_COMMAND}" "-E" "environment")
endfunction()

View File

@ -97,6 +97,11 @@ if(WIN32)
target_link_libraries(vcmilauncher Qt5::WinMain)
endif()
if(APPLE)
# This makes Xcode project prettier by moving vcmilauncher_autogen directory into vcmiclient subfolder
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER vcmilauncher)
endif()
target_link_libraries(vcmilauncher vcmi Qt5::Widgets Qt5::Network ${SDL_LIBRARY})
vcmi_set_output_dir(vcmilauncher "")

View File

@ -50,7 +50,6 @@ set_target_properties(vcmitest PROPERTIES ${PCH_PROPERTIES})
cotire(vcmitest)
# Files to copy to the build directory
add_custom_target(vcmitestFiles ALL)
set(vcmitest_FILES
testdata/TerrainViewTest.h3m
testdata/terrainViewMappings.json
@ -61,7 +60,7 @@ set(vcmitest_FILES
)
foreach(file ${vcmitest_FILES})
add_custom_command(TARGET vcmitestFiles POST_BUILD
add_custom_command(TARGET vcmitest POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/${file}" ${CMAKE_CURRENT_BINARY_DIR}
)
endforeach()