More progress with cmake for Visual Studio projects
* Change conditon so that L137 onwards of main CMakelists.txt is executed fro VS project target. Main reason to do this was to make sure project actually built with streflop. * Change conditions after L137 so unwanted compile flags aren't added. * Project now builds multi threaded for VS project. Tries to use max number of cores. * Simplify cxx flags. Remove unneeded MT and MTd flags. * Set VS build output to mk/windoze. * Add FPUSettings.asm to streflop in cmake, if VS project specified. * Remove STREFLOP compile definitions. Not needed now streflop is configured properly. * Simplify cmake by adding "VS_BUILD" variable, instead of doing string comparisons all the time to check if is "Visual Studio" target.
This commit is contained in:
parent
c6a632c33c
commit
523229ab55
|
@ -2,16 +2,28 @@ CMAKE_MINIMUM_REQUIRED( VERSION 3.20 )
|
|||
|
||||
IF(WIN32)
|
||||
STRING(SUBSTRING ${CMAKE_GENERATOR} 0 13 GENERATOR_TYPE)
|
||||
IF(GENERATOR_TYPE STREQUAL "Visual Studio")
|
||||
SET(VS_BUILD GENERATOR_TYPE STREQUAL "Visual Studio" CACHE STRING "Target visual studio.")
|
||||
IF(VS_BUILD)
|
||||
# This must be Set before "PROJECT()" is called.
|
||||
set(VCPKG_TARGET_TRIPLET "x64-windows-static")
|
||||
|
||||
# Sets the flags MT/ MTd correctly.
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
|
||||
ADD_COMPILE_DEFINITIONS(UNICODE _UNICODE)
|
||||
include(ProcessorCount)
|
||||
ProcessorCount(N)
|
||||
IF(N GREATER 0)
|
||||
MESSAGE(STATUS "Will build on ${N} cores.")
|
||||
ELSE()
|
||||
SET(N 1)
|
||||
MESSAGE(STATUS "Could not find number of cores. Will attempt to build on ${N} cores.")
|
||||
ENDIF()
|
||||
|
||||
# "MP" is build with all cores.
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MP${N}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP${N}")
|
||||
SET(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_$} /MP${N}" )
|
||||
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_$} /MP${N}" )
|
||||
|
||||
SET(MEGAGLEST_DATA_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/" CACHE STRING "The installation path for data files ${COMMON_INFO_ABOUT_PATH}")
|
||||
SET(MEGAGLEST_INI_INSTALL_PATH "${MEGAGLEST_DATA_INSTALL_PATH}" CACHE STRING "Install path for ini files")
|
||||
|
@ -122,20 +134,24 @@ IF(APPLE)
|
|||
include(${PROJECT_SOURCE_DIR}/mk/macos/CMakeLists.txt)
|
||||
ENDIF(APPLE)
|
||||
|
||||
IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
|
||||
IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW OR VS_BUILD)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
MESSAGE(STATUS "Detected CLANG Compiler...")
|
||||
ELSEIF(CMAKE_COMPILER_IS_GNUCXX)
|
||||
MESSAGE(STATUS "Detected GNUC Compiler...")
|
||||
ELSEIF(MINGW)
|
||||
MESSAGE(STATUS "Detected MINGW Compiler...")
|
||||
ELSEIF(VS_BUILD)
|
||||
MESSAGE(STATUS "Detected VS target for building with msbuild...")
|
||||
ENDIF()
|
||||
|
||||
# Common generic GNU type compiler options that work with all generic GCC compatible compilers
|
||||
ADD_DEFINITIONS("-Wuninitialized -Wsign-compare -Wunused-function -Wunused-variable -Wreturn-type -fno-strict-aliasing")
|
||||
IF(NOT VS_BUILD)
|
||||
ADD_DEFINITIONS("-Wuninitialized -Wsign-compare -Wunused-function -Wunused-variable -Wreturn-type -fno-strict-aliasing")
|
||||
ENDIF()
|
||||
|
||||
# For gcc warning options see: http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
|
||||
IF(NOT MINGW)
|
||||
IF(NOT WIN32)
|
||||
# For tons of verbose warnings add: -Wall
|
||||
# ADD_DEFINITIONS("-Wreturn-type -fno-strict-aliasing -frounding-math -fsignaling-nans -mfpmath=sse -msse -rdynamic")
|
||||
# ADD_DEFINITIONS("-Wuninitialized -Wsign-compare -Wunused-function -Wunused-variable -Wreturn-type -fno-strict-aliasing -frounding-math -fsignaling-nans -rdynamic")
|
||||
|
@ -148,6 +164,8 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
|
|||
# CLang specific Compiler Options
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
|
||||
ELSEIF(VS_BUILD)
|
||||
|
||||
# GCC specific Compiler Options
|
||||
ELSE()
|
||||
ADD_DEFINITIONS("-frounding-math -fsignaling-nans")
|
||||
|
@ -194,25 +212,25 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
|
|||
MESSAGE(STATUS "*WARNING: Disabled use of STREFLOP! Out of synchs may occur")
|
||||
ENDIF()
|
||||
|
||||
include(CheckCXXSourceRuns)
|
||||
include(CheckCXXSourceRuns)
|
||||
|
||||
check_cxx_source_runs("
|
||||
#include <execinfo.h>
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
const size_t max_depth = 6;
|
||||
void *stack_addrs[max_depth];
|
||||
size_t stack_depth = backtrace(stack_addrs, max_depth);
|
||||
}"
|
||||
HAS_GCC_BACKTRACE)
|
||||
check_cxx_source_runs("
|
||||
#include <execinfo.h>
|
||||
#include <stdio.h>
|
||||
int main()
|
||||
{
|
||||
const size_t max_depth = 6;
|
||||
void *stack_addrs[max_depth];
|
||||
size_t stack_depth = backtrace(stack_addrs, max_depth);
|
||||
}"
|
||||
HAS_GCC_BACKTRACE)
|
||||
|
||||
IF(HAS_GCC_BACKTRACE)
|
||||
message(STATUS "Found GCC backtrace lib, will support backtraces")
|
||||
ADD_DEFINITIONS(-DHAS_GCC_BACKTRACE)
|
||||
ELSE()
|
||||
message(STATUS "**WARNING DID NOT Find GCC backtrace lib")
|
||||
ENDIF()
|
||||
IF(HAS_GCC_BACKTRACE)
|
||||
message(STATUS "Found GCC backtrace lib, will support backtraces")
|
||||
ADD_DEFINITIONS(-DHAS_GCC_BACKTRACE)
|
||||
ELSE()
|
||||
message(STATUS "**WARNING DID NOT Find GCC backtrace lib")
|
||||
ENDIF()
|
||||
|
||||
# Debug compiler flags
|
||||
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3")
|
||||
|
@ -348,7 +366,7 @@ IF(CMAKE_COMPILER_IS_GNUCXX OR MINGW)
|
|||
message(STATUS "CMAKE_CXX_FLAGS_${MG_BUILD_TYPE}: ${CMAKE_CXX_FLAGS_${MG_BUILD_TYPE}}")
|
||||
|
||||
# Win32 specific Compiler Flags
|
||||
IF(WIN32)
|
||||
IF(WIN32 AND NOT VS_BUILD)
|
||||
ADD_DEFINITIONS("-D_WINDOWS -D_WIN32 -D_STDCALL_SUPPORTED -D_M_IX86 -DXML_LIBRARY -D_LIB -DCURL_STATICLIB")
|
||||
ENDIF()
|
||||
ENDIF()
|
||||
|
@ -385,10 +403,20 @@ ELSEIF(UNIX AND APPLE)
|
|||
SET(MEGAGLEST_FRIENDLY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/mk/macos/")
|
||||
ELSEIF(UNIX AND NOT APPLE)
|
||||
SET(MEGAGLEST_FRIENDLY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/mk/other_unix/")
|
||||
ELSEIF(WIN32)
|
||||
SET(MEGAGLEST_FRIENDLY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/mk/windoze/")
|
||||
ELSE()
|
||||
SET(MEGAGLEST_FRIENDLY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/data/glest_game/")
|
||||
ENDIF()
|
||||
|
||||
# Set VS project exe outputs.
|
||||
IF(VS_BUILD)
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${MEGAGLEST_FRIENDLY_OUTPUT_PATH})
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${MEGAGLEST_FRIENDLY_OUTPUT_PATH})
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ${MEGAGLEST_FRIENDLY_OUTPUT_PATH})
|
||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${MEGAGLEST_FRIENDLY_OUTPUT_PATH})
|
||||
ENDIF()
|
||||
|
||||
# Check if sources exist
|
||||
IF(EXISTS "${PROJECT_SOURCE_DIR}/source/")
|
||||
MESSAGE(STATUS "**Found game source code.")
|
||||
|
|
|
@ -139,7 +139,7 @@ IF(BUILD_MEGAGLEST)
|
|||
ENDIF()
|
||||
|
||||
|
||||
IF(NOT GENERATOR_TYPE STREQUAL "Visual Studio")
|
||||
IF(NOT VS_BUILD)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
ENDIF()
|
||||
IF(FORCE_STREFLOP_SOFTWRAPPER)
|
||||
|
@ -263,7 +263,7 @@ IF(BUILD_MEGAGLEST)
|
|||
add_custom_target(run ALL DEPENDS mg.tmp)
|
||||
ENDIF()
|
||||
|
||||
IF(WIN32 AND NOT GENERATOR_TYPE STREQUAL "Visual Studio")
|
||||
IF(WIN32 AND NOT VS_BUILD)
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-subsystem,console -mconsole")
|
||||
ENDIF()
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
OPTION(FORCE_EMBEDDED_LIBS "Force use of embedded libraries' code." OFF)
|
||||
|
||||
# IMPORTANT: should come BEFORE finding packages
|
||||
IF(NOT GENERATOR_TYPE STREQUAL "Visual Studio")
|
||||
IF(NOT VS_BUILD)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
ENDIF()
|
||||
|
||||
|
@ -33,9 +33,6 @@ ENDIF()
|
|||
|
||||
IF(WANT_USE_STREFLOP)
|
||||
IF(NOT STREFLOP_FOUND)
|
||||
IF(WIN32 AND GENERATOR_TYPE STREQUAL "Visual Studio")
|
||||
ADD_COMPILE_DEFINITIONS(STREFLOP_SSE LIBM_COMPILING_FLT32)
|
||||
ENDIF()
|
||||
ADD_SUBDIRECTORY(sources/streflop)
|
||||
ELSE()
|
||||
INCLUDE_DIRECTORIES(${STREFLOP_INCLUDE_DIRS} ${STREFLOP_INCLUDE_DIRS}/streflop)
|
||||
|
@ -298,7 +295,7 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST
|
|||
FIND_PACKAGE(Miniupnpc)
|
||||
ENDIF()
|
||||
|
||||
if(NOT MINIUPNP_FOUND OR GENERATOR_TYPE STREQUAL "Visual Studio")
|
||||
if(NOT MINIUPNP_FOUND OR VS_BUILD)
|
||||
if(NOT FORCE_USE_EMBEDDED_Miniupnpc)
|
||||
MESSAGE(STATUS "*** Using EMBEDDED miniupnpc since dev system does not have it... MINIUPNP_FOUND [${MINIUPNP_FOUND}]")
|
||||
else()
|
||||
|
@ -314,7 +311,7 @@ IF(BUILD_MEGAGLEST_MODEL_VIEWER OR BUILD_MEGAGLEST_MAP_EDITOR OR BUILD_MEGAGLEST
|
|||
else()
|
||||
add_definitions (-D_POSIX_C_SOURCE=200809L)
|
||||
endif ()
|
||||
ELSEIF(GENERATOR_TYPE STREQUAL "Visual Studio")
|
||||
ELSEIF(VS_BUILD)
|
||||
ADD_COMPILE_DEFINITIONS(MINIUPNP_STATICLIB)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -13,6 +13,11 @@ INCLUDE_DIRECTORIES(
|
|||
|
||||
SET(STREFLOP_SRC ${STREFLOP_GLOBBED_CPP})
|
||||
|
||||
IF(VS_BUILD)
|
||||
ENABLE_LANGUAGE(ASM_MASM)
|
||||
SET(STREFLOP_SRC ${STREFLOP_SRC} FPUSettings.asm)
|
||||
ENDIF()
|
||||
|
||||
ADD_LIBRARY(streflop STATIC EXCLUDE_FROM_ALL
|
||||
${STREFLOP_SRC}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue