Port CMake-changes that were added to dhewm3 since the SDK was created

Make source files listing in VS usable (incl. fallback for old CMake)
CMake: Fix build in path with spaces
This commit is contained in:
Daniel Gibson 2020-09-06 04:09:12 +02:00
parent c198d4ebeb
commit 76529ab38f

View file

@ -100,7 +100,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_compile_options(-march=pentium3)
endif()
set(CMAKE_C_FLAGS_DEBUG "-g -D_DEBUG -O1")
set(CMAKE_C_FLAGS_DEBUG "-g -D_DEBUG -O0")
set(CMAKE_C_FLAGS_DEBUGALL "-g -ggdb -D_DEBUG")
set(CMAKE_C_FLAGS_PROFILE "-g -ggdb -D_DEBUG -O1 -fno-omit-frame-pointer")
set(CMAKE_C_FLAGS_RELEASE "-O2 -fno-unsafe-math-optimizations -fno-math-errno -fno-trapping-math -fomit-frame-pointer")
@ -167,7 +167,10 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
# set(sys_libs ${sys_libs} dl) FIXME: -ldl needed anyway?
endif()
elseif(MSVC)
add_definitions(/MP) # parallel build (use all cores, or as many as configured in VS)
add_compile_options(/W4)
add_compile_options(/we4840) # treat as error when passing a class to a vararg-function (probably printf-like)
add_compile_options(/wd4100) # unreferenced formal parameter
add_compile_options(/wd4127) # conditional expression is constant
add_compile_options(/wd4244) # possible loss of data
@ -217,6 +220,27 @@ if(NOT APPLE AND NOT WIN32)
message(STATUS " Data directory: ${datadir}")
endif()
# I'm a bit sloppy with headers and just glob them in..
# they're only handled in CMake at all so they turn up in Visual Studio solutions..
# globs all the headers from ${PATHPREFIX}/ and adds them to ${SRCLIST}
function(add_globbed_headers SRCLIST PATHPREFIX)
file(GLOB_RECURSE tmp_hdrs RELATIVE "${CMAKE_SOURCE_DIR}" "${PATHPREFIX}/*.h")
set(${SRCLIST} ${tmp_hdrs} ${${SRCLIST}} PARENT_SCOPE)
endfunction()
if(CMAKE_MAJOR_VERSION LESS 3 OR ( CMAKE_MAJOR_VERSION EQUAL 3 AND CMAKE_MINOR_VERSION LESS 8 ))
# cmake < 3.8 doesn't support source_group(TREE ...) so replace it with a dummy
# (it's only cosmetical anyway, to make source files show up properly in Visual Studio)
function(source_group)
endfunction()
message(STATUS "Using CMake < 3.8, doesn't support source_group(TREE ...), replacing it with a dummy")
message(STATUS " (this is only relevants for IDEs, doesn't matter for just compiling dhewm3)")
#else()
# message(STATUS "Using CMake >= 3.8, supports source_group(TREE ...)")
endif()
set(src_game
game/AF.cpp
game/AFEntity.cpp
@ -291,6 +315,8 @@ set(src_game
${src_game_mod}
)
add_globbed_headers(src_game "game")
set(src_d3xp
d3xp/AF.cpp
d3xp/AFEntity.cpp
@ -367,6 +393,8 @@ set(src_d3xp
${src_d3xp_mod}
)
add_globbed_headers(src_d3xp "d3xp")
set(src_idlib
idlib/bv/Bounds.cpp
idlib/bv/Frustum.cpp
@ -418,6 +446,18 @@ set(src_idlib
idlib/Heap.cpp
)
add_globbed_headers(src_idlib "idlib")
# just add all the remaining headers (that have no corresponding .cpp in the SDK)
# to idlib so they can be navigated there
add_globbed_headers(src_idlib "cm")
add_globbed_headers(src_idlib "framework")
add_globbed_headers(src_idlib "renderer")
add_globbed_headers(src_idlib "sound")
add_globbed_headers(src_idlib "sys")
add_globbed_headers(src_idlib "tools")
add_globbed_headers(src_idlib "ui")
include_directories(${CMAKE_BINARY_DIR})
include_directories(${CMAKE_SOURCE_DIR})
@ -435,6 +475,8 @@ else()
endif()
endif()
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX neo FILES ${src_idlib})
if(BASE)
if (AROS)
add_executable(base sys/aros/dll/dllglue.c ${src_game})
@ -444,9 +486,12 @@ if(BASE)
# so mods can create cdoom.dll instead of base.dll from the code in game/
set_target_properties(base PROPERTIES OUTPUT_NAME "${BASE_NAME}")
endif()
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX neo FILES ${src_game})
set_target_properties(base PROPERTIES PREFIX "")
set_target_properties(base PROPERTIES COMPILE_DEFINITIONS "${BASE_DEFS}")
set_target_properties(base PROPERTIES COMPILE_FLAGS "-I${CMAKE_SOURCE_DIR}/game")
target_include_directories(base PRIVATE "${CMAKE_SOURCE_DIR}/game")
set_target_properties(base PROPERTIES LINK_FLAGS "${ldflags}")
set_target_properties(base PROPERTIES INSTALL_NAME_DIR "@executable_path")
if (AROS)
@ -473,9 +518,12 @@ if(D3XP)
# so mods can create whatever.dll instead of d3xp.dll from the code in d3xp/
set_target_properties(d3xp PROPERTIES OUTPUT_NAME "${D3XP_NAME}")
endif()
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} PREFIX neo FILES ${src_d3xp})
set_target_properties(d3xp PROPERTIES PREFIX "")
set_target_properties(d3xp PROPERTIES COMPILE_DEFINITIONS "${D3XP_DEFS}")
set_target_properties(d3xp PROPERTIES COMPILE_FLAGS "-I${CMAKE_SOURCE_DIR}/d3xp")
target_include_directories(d3xp PRIVATE "${CMAKE_SOURCE_DIR}/d3xp")
set_target_properties(d3xp PROPERTIES LINK_FLAGS "${ldflags}")
set_target_properties(d3xp PROPERTIES INSTALL_NAME_DIR "@executable_path")
if (AROS)