Skip to content

Commit

Permalink
Wandows fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Crawford authored and Justin Crawford committed May 29, 2013
1 parent f5de8ef commit c0a40f5
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 67 deletions.
88 changes: 55 additions & 33 deletions CMakeLists.txt
Expand Up @@ -197,39 +197,7 @@ option(USE_LLVM_GOLD "If clang is specified, use LLVM Gold optimizations" OFF)
# Set the install directory for the .so's
set(BASEGAME "main")

# Set the basic build types, there's debug, release, and demo
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
set(DEBUG_BUILD TRUE)
set(CXXFLAGS "${CXXFLAGS} -g -Wall -O")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_definitions(-D__extern_always_inline=inline)
endif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
endif(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")

if(CMAKE_BUILD_TYPE STREQUAL "DEMO" OR CMAKE_BUILD_TYPE STREQUAL "RELEASE")
set(DEMO_BUILD TRUE)
add_definitions(-DNDEBUG)
# Flags to make clang happy and compatible
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(${USE_LLVM_GOLD})
# Attempt to use LLVM Gold and optimize the fuck out of this code
set(CXXFLAGS "${CXXFLAGS} -O4 -ffast-math -fsigned-char -emit-llvm")
else(${USE_LLVM_GOLD})
# Use normal optimizations that clang offers
set(CXXFLAGS "${CXXFLAGS} -O3 -ffast-math -fsigned-char")
endif(${USE_LLVM_GOLD})
# llvm fails with some of the inlining used in math.h, this fixes it
add_definitions(-D__extern_always_inline=inline)
else(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(CXXFLAGS "${CXXFLAGS} -O3 -ffast-math -fno-strict-aliasing -fstrength-reduce -fsigned-char")
endif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
# Demo mode only has a second definition from release
if(CMAKE_BUILD_TYPE STREQUAL "DEMO")
add_definitions(-DWOLF_SP_DEMO)
set(BASEGAME "demomain")
endif(CMAKE_BUILD_TYPE STREQUAL "DEMO")
endif(CMAKE_BUILD_TYPE STREQUAL "DEMO" OR CMAKE_BUILD_TYPE STREQUAL "RELEASE")

# If we're using clang..
if(CMAKE_C_COMPILER_ID STREQUAL "Clang" AND ${USE_LLVM_GOLD})
#SET (CMAKE_C_COMPILER "/usr/bin/clang")
SET (CMAKE_C_FLAGS "-Wall -std=c99")
Expand Down Expand Up @@ -271,6 +239,47 @@ if(WIN32)
add_definitions(-DWIN32 -D_WIN32)
endif(WIN32)


if(NOT WIN32)
# Set the basic build types, there's debug, release, and demo
if(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
set(DEBUG_BUILD TRUE)
set(CXXFLAGS "${CXXFLAGS} -g -Wall -O")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
add_definitions(-D__extern_always_inline=inline)
endif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
endif(CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR CMAKE_BUILD_TYPE STREQUAL "RELWITHDEBINFO")
endif(NOT WIN32)

if(CMAKE_BUILD_TYPE STREQUAL "DEMO" OR CMAKE_BUILD_TYPE STREQUAL "RELEASE")
set(DEMO_BUILD TRUE)
add_definitions(-DNDEBUG)

# Flags to make clang happy and compatible
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(${USE_LLVM_GOLD})
# Attempt to use LLVM Gold and optimize the fuck out of this code
set(CXXFLAGS "${CXXFLAGS} -O4 -ffast-math -fsigned-char -emit-llvm")
else(${USE_LLVM_GOLD})
# Use normal optimizations that clang offers
set(CXXFLAGS "${CXXFLAGS} -O3 -ffast-math -fsigned-char")
endif(${USE_LLVM_GOLD})
# llvm fails with some of the inlining used in math.h, this fixes it
add_definitions(-D__extern_always_inline=inline)
else(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(NOT MSVC)
set(CXXFLAGS "${CXXFLAGS} -O3 -ffast-math -fno-strict-aliasing -fstrength-reduce -fsigned-char")
endif(NOT MSVC)
endif(CMAKE_C_COMPILER_ID STREQUAL "Clang")

# Demo mode only has a second definition from release
if(CMAKE_BUILD_TYPE STREQUAL "DEMO")
add_definitions(-DWOLF_SP_DEMO)
set(BASEGAME "demomain")
endif(CMAKE_BUILD_TYPE STREQUAL "DEMO")
endif(CMAKE_BUILD_TYPE STREQUAL "DEMO" OR CMAKE_BUILD_TYPE STREQUAL "RELEASE")


# If we are not using Visual Studio, we'll run the following checks
if(NOT MSVC)
# Check if the C++ compiler can accept the -pipe flag, and add it to the compile flags if it works
Expand Down Expand Up @@ -301,6 +310,19 @@ if(NOT MSVC)
message(FATAL_ERROR "The pthread library is required to build ${PROJECT_NAME}")
endif(HAVE_PTHREAD)
endif(NOT WIN32)
else(NOT MSVC)
# If using Visual Studio, set the C++ flags accordingly
# Remove the default exception handling flags, also remove default warning level flag
string(REPLACE "/EHsc " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "/GX " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "/W3 " "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
# Set the compile flags to have warnings on the max setting (but disable a few annoying ones), exception handling turned on, the proper defines
set(CXXFLAGS "${CXXFLAGS} /W4 /wd4100 /wd4127 /wd4250 /wd4251 /wd4355 /wd4706 /wd4800 /wd4996 /EHs")
if(DEBUG_BUILD)
add_definitions(-D_DEBUG -D_WINDOWS -D__USEA3D -D__A3D_GEOM -DWIN32 -D_CRT_SECURE_NO_WARNINGS)
else(DEBUG_BUILD)
add_definitions(-DNDEBUG -D_WINDOWS -D__USEA3D -D__A3D_GEOM -DWIN32 -D_CRT_SECURE_NO_WARNINGS)
endif(DEBUG_BUILD)
endif(NOT MSVC)

# detect what package manager we have and if it is usable
Expand Down
8 changes: 6 additions & 2 deletions src/botlib/CMakeLists.txt
Expand Up @@ -6,8 +6,12 @@ file(GLOB C_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.c")
# Sort the C sources into a neat list
list(SORT C_SOURCES)

# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")
if(NOT WIN32)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")
else(NOT WIN32)
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS}")
endif(NOT WIN32)

# Add to our library.
add_library(botlib${CMAKE_STATIC_LIBRARY_SUFFIX} STATIC ${C_SOURCES})
Expand Down
17 changes: 13 additions & 4 deletions src/cgame/CMakeLists.txt
Expand Up @@ -17,18 +17,27 @@ list(APPEND C_SOURCES
# Sort the C sources into a neat list
list(SORT C_SOURCES)

#add_definitions(-DCGAMEDLL)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -fPIC")
if(NOT WIN32)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -fPIC")
else(NOT WIN32)
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS}")
endif(NOT WIN32)

# use the OS suffix instead of .dll, things get confusing when that happens
# the variable name is `SO` because I am on linux
set(SO cgame-rtcw${CMAKE_SHARED_LIBRARY_SUFFIX})

# Add to our library.
add_library(${SO} MODULE ${C_SOURCES})

set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE C PREFIX "" SUFFIX "" COMPILE_DEFINITIONS CGAMEDLL)
target_link_libraries(${SO} dl m)

if(NOT WIN32)
target_link_libraries(${SO} dl m)
else(NOT WIN32)
target_link_libraries(${SO} odbc32.lib odbccp32.lib)
endif(NOT WIN32)

install(
TARGETS ${SO}
Expand Down
41 changes: 26 additions & 15 deletions src/client/CMakeLists.txt
Expand Up @@ -62,17 +62,17 @@ list(SORT QCOMMON_SOURCES)


if(UNIX AND NOT APPLE)
# *nix specific sources
# We use a list to avoid the qvm stuff that fails to compile on x86_64
set(PLATFORM_SOURCES_UNIX
${CMAKE_SOURCE_DIR}/src/unix/unix_main.c
${CMAKE_SOURCE_DIR}/src/unix/unix_net.c
${CMAKE_SOURCE_DIR}/src/unix/unix_shared.c
# Linux common is a stub an should be removed..
${CMAKE_SOURCE_DIR}/src/unix/linux_common.c
)
file(GLOB PLATFORM_SOURCES_SDL RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../sdl/*.c")
list(APPEND PLATFORM_SOURCES ${PLATFORM_SOURCES_UNIX} ${PLATFORM_SOURCES_SDL})
# *nix specific sources
# We use a list to avoid the qvm stuff that fails to compile on x86_64
set(PLATFORM_SOURCES_UNIX
${CMAKE_SOURCE_DIR}/src/unix/unix_main.c
${CMAKE_SOURCE_DIR}/src/unix/unix_net.c
${CMAKE_SOURCE_DIR}/src/unix/unix_shared.c
# Linux common is a stub an should be removed..
${CMAKE_SOURCE_DIR}/src/unix/linux_common.c
)
file(GLOB PLATFORM_SOURCES_SDL RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "../sdl/*.c")
list(APPEND PLATFORM_SOURCES ${PLATFORM_SOURCES_UNIX} ${PLATFORM_SOURCES_SDL})
endif(UNIX AND NOT APPLE)

if(APPLE)
Expand Down Expand Up @@ -109,21 +109,32 @@ set(ADDITONAL_SOURCES
list(APPEND CLIENT_SOURCES ${RENDERER_SOURCES} ${QCOMMON_SOURCES} ${PLATFORM_SOURCES}
${ADDITONAL_SOURCES} ${SERVER_SOURCES} ${SERVER_SOURCES} ${QVM_SOURCES})

set_source_files_properties(${CLIENT_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")
if(NOT WIN32)
set_source_files_properties(${CLIENT_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")
else(NOT WIN32)
set_source_files_properties(${CLIENT_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS}")
endif(NOT WIN32)
# message(STATUS "CLIENT_SOURCES: ${CLIENT_SOURCES}")

# Compile our program
add_executable(${PROJECT_NAME} ${CLIENT_SOURCES})
add_dependencies(${PROJECT_NAME} botlib${CMAKE_STATIC_LIBRARY_SUFFIX} jpeg-6${CMAKE_STATIC_LIBRARY_SUFFIX} splines${CMAKE_STATIC_LIBRARY_SUFFIX})

# Our executable
if(NOT APPLE)
if(UNIX)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C PREFIX "" SUFFIX "")
target_link_libraries(${PROJECT_NAME} ${SDL_LIBRARY} ${SDL_IMAGE_LIBRARIES} SDL_image GL dl m botlib${CMAKE_STATIC_LIBRARY_SUFFIX} jpeg-6${CMAKE_STATIC_LIBRARY_SUFFIX} splines${CMAKE_STATIC_LIBRARY_SUFFIX})
else(NOT APPLE)
endif(UNIX)

if(APPLE)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C PREFIX "" SUFFIX "" LINK_FLAGS "-framework Carbon -framework GLUT -framework OpenGL -framework IOKit -framework AudioToolbox -framework CoreAudio -framework CoreServices")
target_link_libraries(${PROJECT_NAME} ${SDL_LIBRARY} ${SDL_IMAGE_LIBRARIES} dl m botlib${CMAKE_STATIC_LIBRARY_SUFFIX} jpeg-6${CMAKE_STATIC_LIBRARY_SUFFIX} splines${CMAKE_STATIC_LIBRARY_SUFFIX})
endif(NOT APPLE)
endif(APPLE)

if(WIN32)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C PREFIX "" SUFFIX "")
target_link_libraries(${PROJECT_NAME} winmm.lib wsock32.lib GL botlib${CMAKE_STATIC_LIBRARY_SUFFIX} jpeg-6${CMAKE_STATIC_LIBRARY_SUFFIX} splines${CMAKE_STATIC_LIBRARY_SUFFIX})
endif(WIN32)

install(
TARGETS ${PROJECT_NAME}
Expand Down
15 changes: 11 additions & 4 deletions src/extractfuncs/CMakeLists.txt
Expand Up @@ -7,11 +7,18 @@ file(GLOB C_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.c")
list(SORT C_SOURCES)

add_definitions(-DSCREWUP)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")

# Compile our program
if(NOT WIN32)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")
else(NOT WIN32)
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS}")
endif(NOT WIN32)

# Compile our program
add_executable(extractfuncs ${C_SOURCES})
set_target_properties(extractfuncs PROPERTIES LINKER_LANGUAGE C PREFIX "" SUFFIX "")
target_link_libraries(extractfuncs m)

if(NOT WIN32)
target_link_libraries(extractfuncs m)
endif(NOT WIN32)
1 change: 1 addition & 0 deletions src/extractfuncs/extractfuncs.c
Expand Up @@ -35,6 +35,7 @@ If you have questions concerning this license or the applicable additional terms
#ifdef _WIN32
#include <windows.h>
#include <io.h>
#define PATH_MAX MAX_PATH
#endif
#include "extractfuncs/l_memory.h"
#include "extractfuncs/l_script.h"
Expand Down
15 changes: 12 additions & 3 deletions src/game/CMakeLists.txt
Expand Up @@ -38,8 +38,12 @@ add_custom_target(
# Include those headers
include_directories(${CMAKE_CURRENT_BINARY_DIR})

# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -fPIC")
if(NOT WIN32)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -fPIC")
else(NOT WIN32)
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS}")
endif(NOT WIN32)

# use the OS suffix instead of .dll, things get confusing when that happens
# the variable name is `SO` because I am on linux
Expand All @@ -50,7 +54,12 @@ add_library(${SO} MODULE ${C_SOURCES})
set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE C PREFIX "" SUFFIX "" COMPILE_DEFINITIONS GAMEDLL)
# depend on the headers
add_dependencies(${SO} game_func_headers)
target_link_libraries(${SO} dl m)

if(NOT WIN32)
target_link_libraries(${SO} dl m)
else(NOT WIN32)
target_link_libraries(${SO} winmm.lib)
endif(NOT WIN32)

install(
TARGETS ${SO}
Expand Down
8 changes: 6 additions & 2 deletions src/jpeg-6/CMakeLists.txt
Expand Up @@ -6,8 +6,12 @@ file(GLOB C_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.c")
# Sort the C sources into a neat list
list(SORT C_SOURCES)

# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")
if(NOT WIN32)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")
else(NOT WIN32)
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS}")
endif(NOT WIN32)

# Add to our library.
add_library(jpeg-6${CMAKE_STATIC_LIBRARY_SUFFIX} STATIC ${C_SOURCES})
Expand Down
8 changes: 6 additions & 2 deletions src/splines/CMakeLists.txt
Expand Up @@ -6,8 +6,12 @@ file(GLOB CXX_SOURCES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.cpp")
# Sort the C sources into a neat list
list(SORT CXX_SOURCES)

# Set the compiler to use
set_source_files_properties(${CXX_SOURCES} PROPERTIES LANGUAGE CXX COMPILE_FLAGS "${CXXFLAGS} -g")
if(NOT WIN32)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -g")
else(NOT WIN32)
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS}")
endif(NOT WIN32)

# Add to our library.
add_library(splines${CMAKE_STATIC_LIBRARY_SUFFIX} STATIC ${CXX_SOURCES})
Expand Down
13 changes: 11 additions & 2 deletions src/ui/CMakeLists.txt
Expand Up @@ -13,8 +13,12 @@ list(APPEND C_SOURCES
# Sort the C sources into a neat list
list(SORT C_SOURCES)

if(NOT WIN32)
# Set the compiler to use
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -fPIC")
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS} -fPIC")
else(NOT WIN32)
set_source_files_properties(${C_SOURCES} PROPERTIES LANGUAGE C COMPILE_FLAGS "${CXXFLAGS}")
endif(NOT WIN32)

# use the OS suffix instead of .dll, things get confusing when that happens
# the variable name is `SO` because I am on linux
Expand All @@ -23,7 +27,12 @@ set(SO ui-rtcw${CMAKE_SHARED_LIBRARY_SUFFIX})
# Add to our library.
add_library(${SO} MODULE ${C_SOURCES})
set_target_properties(${SO} PROPERTIES LINKER_LANGUAGE C PREFIX "" SUFFIX "")
target_link_libraries(${SO} dl m)

if(NOT WIN32)
target_link_libraries(${SO} dl m)
else(NOT WIN32)
target_link_libraries(${SO} odbc32.lib odbccp32.lib)
endif(NOT WIN32)

install(
TARGETS ${SO}
Expand Down

0 comments on commit c0a40f5

Please sign in to comment.