Permalink
Browse files

Fix CMake on Windows

  • Loading branch information...
SupSuper committed Mar 30, 2018
1 parent db2f66e commit 039246188d721178fc63fbd33b66cf80b0e5cb99
@@ -69,6 +69,13 @@ if (LTO)
endif()
endif(LTO)
# MSVC has default flags that CMake doesn't set
if (MSVC)
add_definitions(-DUNICODE -D_UNICODE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /permissive-")
endif()
# Clang whines about unused arguments, which is annoying (for example) when
# using ccache and the clang exe never sees a non-preprocessed file, yet still
# gets passed the -I include arguments
@@ -29,7 +29,9 @@ target_include_directories(OpenApoc_LibSmacker PUBLIC ${CMAKE_SOURCE_DIR})
target_include_directories(OpenApoc_LibSmacker PRIVATE
${CMAKE_SOURCE_DIR}/dependencies/libsmacker)
target_compile_definitions(OpenApoc_LibSmacker PUBLIC PTHREADS_AVAILABLE)
if(NOT WIN32)
target_compile_definitions(OpenApoc_LibSmacker PUBLIC PTHREADS_AVAILABLE)
endif()
set (MINIZ_SOURCE_FILES
miniz/miniz.c
@@ -51,7 +53,9 @@ target_include_directories(OpenApoc_Miniz PUBLIC ${CMAKE_SOURCE_DIR})
target_include_directories(OpenApoc_Miniz PRIVATE
${CMAKE_SOURCE_DIR}/dependencies/miniz)
target_compile_definitions(OpenApoc_Miniz PUBLIC PTHREADS_AVAILABLE)
if(NOT WIN32)
target_compile_definitions(OpenApoc_Miniz PUBLIC PTHREADS_AVAILABLE)
endif()
set (LIBPUGIXML_SOURCE_FILES
pugixml/src/pugixml.cpp)
@@ -70,7 +74,9 @@ list(APPEND ALL_HEADER_FILES ${LIBPUGIXML_HEADER_FILES})
add_library(OpenApoc_LibPugixml STATIC ${LIBPUGIXML_SOURCE_FILES}
${LIBPUGIXML_HEADER_FILES})
target_compile_definitions(OpenApoc_LibPugixml PUBLIC PTHREADS_AVAILABLE)
if(NOT WIN32)
target_compile_definitions(OpenApoc_LibPugixml PUBLIC PTHREADS_AVAILABLE)
endif()
set_property(TARGET OpenApoc_LibPugixml PROPERTY CXX_STANDARD 11)
set_property(TARGET OpenApoc_LibPugixml PROPERTY CXX_STANDARD_REQUIRED ON)
@@ -91,7 +97,9 @@ list(APPEND ALL_HEADER_FILES ${LIBLODEPNG_HEADER_FILES})
add_library(OpenApoc_LibLodepng STATIC ${LIBLODEPNG_SOURCE_FILES}
${LIBLODEPNG_HEADER_FILES})
target_compile_definitions(OpenApoc_LibLodepng PUBLIC PTHREADS_AVAILABLE)
if(NOT WIN32)
target_compile_definitions(OpenApoc_LibLodepng PUBLIC PTHREADS_AVAILABLE)
endif()
set_property(TARGET OpenApoc_LibLodepng PROPERTY CXX_STANDARD 11)
set_property(TARGET OpenApoc_LibLodepng PROPERTY CXX_STANDARD_REQUIRED ON)
@@ -200,6 +200,8 @@ if(APPLE)
"-DBROKEN_THREAD_LOCAL")
# Disable libunwind use on Apple
SET(BACKTRACE_ON_ERROR OFF CACHE BOOL "Print backtrace on logging an error (Requires libunwind on linux, no extra dependencies on windows)" FORCE)
elseif(WIN32)
target_compile_definitions(OpenApoc_Framework PRIVATE "-DGLESWRAP_PLATFORM_WGL")
else()
target_compile_definitions(OpenApoc_Framework PRIVATE "-DGLESWRAP_PLATFORM_GLX")
endif()
@@ -237,46 +239,58 @@ target_link_libraries(OpenApoc_Framework PUBLIC ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(OpenApoc_Framework PUBLIC ${GLM_INCLIDE_DIR})
find_package(PkgConfig)
#Require SDL2 for input/graphics/sound/pretty much everything
pkg_check_modules(PC_SDL2 REQUIRED sdl2>=2.0)
if (NOT PC_SDL2_FOUND)
message(FATAL_ERROR "sdl2 not found")
if(WIN32)
find_path(SDL2_INCLUDE_DIR NAME SDL.h PATH_SUFFIXES SDL2)
find_library(SDL2_LIBRARY NAMES SDL2d SDL2)
find_library(SDL2_MAIN NAMES SDL2maind SDL2main)
target_link_libraries(OpenApoc_Framework PUBLIC ${SDL2_LIBRARY} ${SDL2_MAIN})
target_include_directories(OpenApoc_Framework PUBLIC ${SDL2_INCLUDE_DIR})
else()
find_package(PkgConfig)
pkg_check_modules(PC_SDL2 REQUIRED sdl2>=2.0)
if (NOT PC_SDL2_FOUND)
message(FATAL_ERROR "sdl2 not found")
endif()
foreach (SDL2_LIB ${PC_SDL2_LIBRARIES})
message("Searching for ${SDL2_LIB} in ${PC_SDL2_LIBRARY_DIRS}")
find_library(SDL2_LIBRARY_PATH-${SDL2_LIB} ${SDL2_LIB} HINTS ${PC_SDL2_LIBRARY_DIRS})
if (NOT SDL2_LIBRARY_PATH-${SDL2_LIB})
message(FATAL_ERROR "sdl2 library ${SDL2_LIB} not found in ${PC_SDL2_LIBRARY_DIRS}")
endif()
message("Found ${SDL2_LIB} at ${SDL2_LIBRARY_PATH-${SDL2_LIB}}")
target_link_libraries(OpenApoc_Framework PUBLIC ${SDL2_LIBRARY_PATH-${SDL2_LIB}})
endforeach()
target_include_directories(OpenApoc_Framework PUBLIC ${PC_SDL2_INCLUDE_DIRS})
endif()
foreach (SDL2_LIB ${PC_SDL2_LIBRARIES})
message("Searching for ${SDL2_LIB} in ${PC_SDL2_LIBRARY_DIRS}")
find_library(SDL2_LIBRARY_PATH-${SDL2_LIB} ${SDL2_LIB} HINTS ${PC_SDL2_LIBRARY_DIRS})
if (NOT SDL2_LIBRARY_PATH-${SDL2_LIB})
message(FATAL_ERROR "sdl2 library ${SDL2_LIB} not found in ${PC_SDL2_LIBRARY_DIRS}")
endif()
message("Found ${SDL2_LIB} at ${SDL2_LIBRARY_PATH-${SDL2_LIB}}")
target_link_libraries(OpenApoc_Framework PUBLIC ${SDL2_LIBRARY_PATH-${SDL2_LIB}})
endforeach()
target_include_directories(OpenApoc_Framework PUBLIC ${PC_SDL2_INCLUDE_DIRS})
# Dialog is handled by SDL2
if(DIALOG_ON_ERROR)
target_compile_definitions(OpenApoc_Framework PUBLIC -DERROR_DIALOG)
target_compile_definitions(OpenApoc_Framework PUBLIC -DERROR_DIALOG)
endif()
# Backtrace required libunwind
if(BACKTRACE_ON_ERROR)
pkg_check_modules(PC_UNWIND libunwind)
if (NOT PC_UNWIND_FOUND)
#Ubuntu 12.04 libunwind doesn't have a pkgconfig - try 'current' paths anyway
find_path(UNWIND_INCLUDE_DIR libunwind.h HINTS ${FRAMEWORK_INCLUDE_DIRS})
if (NOT UNWIND_INCLUDE_DIR)
message(FATAL_ERROR "Libunwind not found")
endif()
target_link_libraries(OpenApoc_Framework PUBLIC unwind dl)
#HACK - this assumes the library path is already searched?
if(WIN32)
target_link_libraries(OpenApoc_Framework PUBLIC dbghelp)
else()
find_path(UNWIND_INCLUDE_DIR libunwind.h HINTS ${PC_UNWIND_INCLUDEDIR})
target_link_libraries(OpenApoc_Framework PUBLIC ${PC_UNWIND_LIBRARIES} dl)
find_package(PkgConfig)
pkg_check_modules(PC_UNWIND libunwind)
if (NOT PC_UNWIND_FOUND)
#Ubuntu 12.04 libunwind doesn't have a pkgconfig - try 'current' paths anyway
find_path(UNWIND_INCLUDE_DIR libunwind.h HINTS ${FRAMEWORK_INCLUDE_DIRS})
if (NOT UNWIND_INCLUDE_DIR)
message(FATAL_ERROR "Libunwind not found")
endif()
target_link_libraries(OpenApoc_Framework PUBLIC unwind dl)
#HACK - this assumes the library path is already searched?
else()
find_path(UNWIND_INCLUDE_DIR libunwind.h HINTS ${PC_UNWIND_INCLUDEDIR})
target_link_libraries(OpenApoc_Framework PUBLIC ${PC_UNWIND_LIBRARIES} dl)
endif()
target_compile_definitions(OpenApoc_Framework PUBLIC -DBACKTRACE_LIBUNWIND)
target_include_directories(OpenApoc_Framework PUBLIC ${UNWIND_INCLUDE_DIR})
endif()
target_compile_definitions(OpenApoc_Framework PUBLIC -DBACKTRACE_LIBUNWIND)
target_include_directories(OpenApoc_Framework PUBLIC ${UNWIND_INCLUDE_DIR})
endif()
# OpenGL is required for any renderer
@@ -5,7 +5,9 @@ PROJECT(OpenApoc_GameState CXX C)
CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package (Threads REQUIRED)
find_package(Threads REQUIRED)
find_package(Boost REQUIRED COMPONENTS date_time)
set (GAMESTATE_SOURCE_FILES
battle/ai/aidecision.cpp
@@ -191,6 +193,10 @@ set (GAMESTATE_HEADER_FILES
tilemap/tileobject_vehicle.h)
source_group(gamestate\\headers FILES ${GAMESTATE_HEADER_FILES})
if (MSVC)
set_source_files_properties(gamestate_serialize_generated.cpp PROPERTIES COMPILE_FLAGS /bigobj)
endif()
list(APPEND ALL_SOURCE_FILES ${GAMESTATE_SOURCE_FILES})
list(APPEND ALL_HEADER_FILES ${GAMESTATE_HEADER_FILES})
@@ -200,6 +206,9 @@ add_library(OpenApoc_GameState STATIC ${GAMESTATE_SOURCE_FILES}
target_link_libraries(OpenApoc_GameState PUBLIC OpenApoc_Library)
target_link_libraries(OpenApoc_GameState PUBLIC OpenApoc_Framework)
target_link_libraries(OpenApoc_GameState PUBLIC ${Boost_LIBRARIES}
Threads::Threads)
# This needs to be public as gamestate_serialize_generated.h needs to be in
# the path
target_include_directories(OpenApoc_GameState PUBLIC ${CMAKE_BINARY_DIR})
@@ -41,4 +41,6 @@ target_include_directories(OpenApoc_Library PUBLIC ${GLM_INCLUDE_DIR})
target_include_directories(OpenApoc_Library PUBLIC ${Boost_INCLUDE_DIRS})
set_property(TARGET OpenApoc_Library PROPERTY CXX_STANDARD 11)
target_compile_definitions(OpenApoc_Library PUBLIC PTHREADS_AVAILABLE)
if(NOT WIN32)
target_compile_definitions(OpenApoc_Library PUBLIC PTHREADS_AVAILABLE)
endif()
@@ -3,15 +3,15 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
set (TEST_LIST test_rect test_voxel test_tilemap test_rng test_images
test_unicode)
foreach(TEST ${TEST_LIST})
add_executable(${TEST} ${TEST}.cpp)
# Just add all libs?
target_link_libraries(${TEST} OpenApoc_Library OpenApoc_Framework
OpenApoc_GameState)
target_compile_definitions(${TEST} PRIVATE -DUNIT_TEST)
add_test(NAME ${TEST} COMMAND ${EXECUTABLE_OUTPUT_PATH}/${TEST}
--Framework.CD=${CD_PATH} --Framework.Data=${CMAKE_SOURCE_DIR}/data)
\"--Framework.CD=${CD_PATH}\" \"--Framework.Data=${CMAKE_SOURCE_DIR}/data\")
set_property(TARGET ${TEST} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${TEST} PROPERTY CXX_STANDARD_REQUIRED ON)
endforeach()
@@ -24,9 +24,14 @@ target_link_libraries(${TEST} OpenApoc_Library OpenApoc_Framework
OpenApoc_GameState)
target_compile_definitions(${TEST} PRIVATE -DUNIT_TEST)
add_test(NAME ${TEST}_difficulty1 COMMAND ${EXECUTABLE_OUTPUT_PATH}/${TEST}
${CMAKE_SOURCE_DIR}/data/difficulty1_patched
${CMAKE_SOURCE_DIR}/data/gamestate_common
--Framework.CD=${CD_PATH} --Framework.Data=${CMAKE_SOURCE_DIR}/data)
\"${CMAKE_SOURCE_DIR}/data/difficulty1_patched\"
\"${CMAKE_SOURCE_DIR}/data/gamestate_common\"
\"--Framework.CD=${CD_PATH}\" \"--Framework.Data=${CMAKE_SOURCE_DIR}/data\")
set_property(TARGET ${TEST} PROPERTY CXX_STANDARD 11)
set_property(TARGET ${TEST} PROPERTY CXX_STANDARD_REQUIRED ON)
# MSVC is bad at detecting utf8
if (MSVC)
set_source_files_properties(test_unicode.cpp PROPERTIES COMPILE_FLAGS /utf-8)
endif()
@@ -102,7 +102,8 @@ function (add_extractor TARGET_LIST EXTRACTOR_NAME)
--Framework.Data=${CMAKE_SOURCE_DIR}/data
--Extractor.extract=${EXTRACTOR_NAME}
DEPENDS OpenApoc_DataExtractor
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
VERBATIM)
set(${TARGET_LIST} ${${TARGET_LIST}} ${EXTRACTOR_OUTPUT} PARENT_SCOPE)
endfunction(add_extractor)

0 comments on commit 0392461

Please sign in to comment.