/
CMakeLists.txt
156 lines (136 loc) · 5.42 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# Place executables and shared libs under "build-dir/",
# instead of under "build-dir/rts/"
# This way, we have the build-dir structure more like the install-dir one,
# which makes testing spring in the builddir easier, eg. like this:
# cd build-dir
# SPRING_DATADIR=$(pwd) ./spring
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "../..")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
find_package_static(ZLIB REQUIRED)
list(APPEND unitsync_libs ${CMAKE_DL_LIBS})
list(APPEND unitsync_libs 7zip lua headlessStubs archives)
list(APPEND unitsync_libs ${ZLIB_LIBRARY})
list(APPEND unitsync_libs ${SPRING_MINIZIP_LIBRARY})
if (WIN32)
list(APPEND unitsync_libs ${IPHLPAPI_LIBRARY})
list(APPEND unitsync_libs ${WINMM_LIBRARY})
endif (WIN32)
if (MINGW OR MSVC)
# We still need these header files,
# even if we are not going to link with SDL.
# We have them available anyway (mingwlibs).
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIR})
else (MINGW OR MSVC)
# Use a direct copy of the GL and SDL headers,
# as these may not be available on headless systems.
include_directories(${CMAKE_SOURCE_DIR}/include/SDL2)
endif (MINGW OR MSVC)
add_definitions(-DUNITSYNC)
if (NOT WIN32)
add_definitions(-fPIC)
add_definitions(${PIC_FLAG})
endif()
add_definitions(-DNOT_USING_CREG)
add_definitions(-DHEADLESS)
add_definitions(-DNO_SOUND)
add_definitions(-DBITMAP_NO_OPENGL)
#add_definitions(-DENABLE_DEPRECATED_FUNCTIONS)
remove_definitions(-DTHREADPOOL)
set(ENGINE_SRC_ROOT "../../rts")
include_directories(${SPRING_MINIZIP_INCLUDE_DIR})
include_directories(${ENGINE_SRC_ROOT}/lib/lua/include)
include_directories(${ENGINE_SRC_ROOT}/lib/7zip)
include_directories(${ENGINE_SRC_ROOT})
include_directories(${CMAKE_BINARY_DIR}/src-generated/engine)
set(main_files
"${ENGINE_SRC_ROOT}/ExternalAI/LuaAIImplHandler.cpp"
"${ENGINE_SRC_ROOT}/Game/GameVersion.cpp"
"${ENGINE_SRC_ROOT}/Lua/LuaConstEngine.cpp"
"${ENGINE_SRC_ROOT}/Lua/LuaMemPool.cpp"
"${ENGINE_SRC_ROOT}/Lua/LuaParser.cpp"
"${ENGINE_SRC_ROOT}/Lua/LuaUtils.cpp"
"${ENGINE_SRC_ROOT}/Lua/LuaIO.cpp"
"${ENGINE_SRC_ROOT}/Map/MapParser.cpp"
"${ENGINE_SRC_ROOT}/Map/SMF/SMFMapFile.cpp"
"${ENGINE_SRC_ROOT}/Sim/Misc/SideParser.cpp"
"${ENGINE_SRC_ROOT}/Sim/Units/CommandAI/Command.cpp" ## LuaUtils::ParseCommand*
## -DUNITSYNC is not passed onto VFS code, which references globalConfig
"${ENGINE_SRC_ROOT}/System/GlobalConfig.cpp"
"${ENGINE_SRC_ROOT}/System/Config/ConfigHandler.cpp"
"${ENGINE_SRC_ROOT}/System/Config/ConfigLocater.cpp"
"${ENGINE_SRC_ROOT}/System/Config/ConfigSource.cpp"
"${ENGINE_SRC_ROOT}/System/Config/ConfigVariable.cpp"
"${ENGINE_SRC_ROOT}/System/Config/ConfigLocater.cpp"
"${ENGINE_SRC_ROOT}/System/Misc/SpringTime.cpp"
"${ENGINE_SRC_ROOT}/System/Platform/CpuID.cpp"
"${ENGINE_SRC_ROOT}/System/Platform/Misc.cpp"
"${ENGINE_SRC_ROOT}/System/Platform/ScopedFileLock.cpp"
"${ENGINE_SRC_ROOT}/System/Platform/Threading.cpp"
"${ENGINE_SRC_ROOT}/System/Threading/ThreadPool.cpp"
"${ENGINE_SRC_ROOT}/System/Sync/SHA512.cpp"
"${ENGINE_SRC_ROOT}/System/CRC.cpp"
"${ENGINE_SRC_ROOT}/System/float4.cpp"
"${ENGINE_SRC_ROOT}/System/Info.cpp"
"${ENGINE_SRC_ROOT}/System/LogOutput.cpp"
"${ENGINE_SRC_ROOT}/System/Option.cpp"
"${ENGINE_SRC_ROOT}/System/SafeVector.cpp"
"${ENGINE_SRC_ROOT}/System/SafeCStrings.c"
"${ENGINE_SRC_ROOT}/System/TdfParser.cpp"
"${ENGINE_SRC_ROOT}/System/UriParser.cpp"
"${ENGINE_SRC_ROOT}/System/StringUtil.cpp"
)
if (WIN32)
list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Win/WinVersion.cpp")
else (WIN32)
list(APPEND main_files "${ENGINE_SRC_ROOT}/System/Platform/Linux/ThreadSupport.cpp")
endif (WIN32)
set(unitsync_files
${sources_engine_System_FileSystem}
${sources_engine_System_Threading}
${sources_engine_System_Log}
${sources_engine_System_Log_sinkFile}
${sources_engine_System_Log_sinkOutputDebugString}
${main_files}
${CMAKE_CURRENT_SOURCE_DIR}/unitsync.cpp
${CMAKE_CURRENT_SOURCE_DIR}/LuaParserAPI.cpp
)
# Add list of all exported functions to .def file to prevent decoration
if (MSVC)
list(APPEND unitsync_files ${CMAKE_CURRENT_SOURCE_DIR}/exports.def)
endif ()
# HACK unitsync should actually be MODULE (not SHARED),
# but the python bindings need it as SHARED,
# to be able to link to it
add_library(unitsync SHARED ${unitsync_files})
add_dependencies(unitsync generateVersionFiles)
target_link_libraries(unitsync ${unitsync_libs})
# hide exported symbols
# see nm -c libunitsync.so
include(CMakePushCheckState)
include(CheckCXXCompilerFlag)
function(check_linker_flag flag out_var)
cmake_push_check_state()
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${flag}")
check_cxx_compiler_flag("" ${out_var})
cmake_pop_check_state()
endfunction()
check_linker_flag("-Wl,--exclude-libs,ALL" LINKER_HAS_EXCLUDELIBS)
if (LINKER_HAS_EXCLUDELIBS)
set_target_properties(unitsync PROPERTIES LINK_FLAGS -Wl,--exclude-libs,ALL)
else()
message(WARNING "linker doesn't support -Wl,--exclude-libs,ALL this leads to a broken unitsync.so")
endif()
if (MINGW)
set_target_properties(unitsync PROPERTIES LINK_FLAGS -Wl,--add-stdcall-alias)
endif (MINGW)
fix_lib_name(unitsync)
install (TARGETS unitsync
RUNTIME DESTINATION ${LIBDIR}
LIBRARY DESTINATION ${LIBDIR})
add_subdirectory(test)
option(UNITSYNC_PYTHON_BINDINGS "compile python bindings for unitsync (FIXME: broken with gcc 4.9 see #4377)" OFF)
if (UNITSYNC_PYTHON_BINDINGS)
# only add this if the submodule is present
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/python")
endif()