Przeglądaj źródła

enable StupidAI and EmptyAI for static AI

Andrey Filipenkov 2 lat temu
rodzic
commit
0294a8b063

+ 2 - 4
AI/CMakeLists.txt

@@ -49,10 +49,8 @@ endif()
 
 add_subdirectory(BattleAI)
 add_subdirectory(VCAI)
-if(NOT ENABLE_STATIC_AI_LIBS)
-	add_subdirectory(StupidAI)
-	add_subdirectory(EmptyAI)
-endif()
+add_subdirectory(StupidAI)
+add_subdirectory(EmptyAI)
 if(ENABLE_NULLKILLER_AI)
 	add_subdirectory(Nullkiller)
 endif()

+ 10 - 6
AI/EmptyAI/CMakeLists.txt

@@ -1,8 +1,5 @@
 set(emptyAI_SRCS
-		StdInc.cpp
-
 		CEmptyAI.cpp
-		exp_funcs.cpp
 )
 
 set(emptyAI_HEADERS
@@ -11,13 +8,20 @@ set(emptyAI_HEADERS
 		CEmptyAI.h
 )
 
+if(NOT ENABLE_STATIC_AI_LIBS)
+	list(APPEND emptyAI_SRCS main.cpp StdInc.cpp)
+endif()
 assign_source_group(${emptyAI_SRCS} ${emptyAI_HEADERS})
 
-add_library(EmptyAI SHARED ${emptyAI_SRCS} ${emptyAI_HEADERS})
+if(ENABLE_STATIC_AI_LIBS)
+	add_library(EmptyAI STATIC ${emptyAI_SRCS} ${emptyAI_HEADERS})
+else()
+	add_library(EmptyAI SHARED ${emptyAI_SRCS} ${emptyAI_HEADERS})
+	install(TARGETS EmptyAI RUNTIME DESTINATION ${AI_LIB_DIR} LIBRARY DESTINATION ${AI_LIB_DIR})
+endif()
+
 target_include_directories(EmptyAI PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 target_link_libraries(EmptyAI PRIVATE ${VCMI_LIB_TARGET})
 
 vcmi_set_output_dir(EmptyAI "AI")
 enable_pch(EmptyAI)
-
-install(TARGETS EmptyAI RUNTIME DESTINATION ${AI_LIB_DIR} LIBRARY DESTINATION ${AI_LIB_DIR} OPTIONAL)

+ 1 - 1
AI/EmptyAI/exp_funcs.cpp → AI/EmptyAI/main.cpp

@@ -1,5 +1,5 @@
 /*
- * exp_funcs.cpp, part of VCMI engine
+ * main.cpp, part of VCMI engine
  *
  * Authors: listed in file AUTHORS in main folder
  *

+ 10 - 6
AI/StupidAI/CMakeLists.txt

@@ -1,7 +1,4 @@
 set(stupidAI_SRCS
-		StdInc.cpp
-
-		main.cpp
 		StupidAI.cpp
 )
 
@@ -11,13 +8,20 @@ set(stupidAI_HEADERS
 		StupidAI.h
 )
 
+if(NOT ENABLE_STATIC_AI_LIBS)
+	list(APPEND stupidAI_SRCS main.cpp StdInc.cpp)
+endif()
 assign_source_group(${stupidAI_SRCS} ${stupidAI_HEADERS})
 
-add_library(StupidAI SHARED ${stupidAI_SRCS} ${stupidAI_HEADERS})
+if(ENABLE_STATIC_AI_LIBS)
+	add_library(StupidAI STATIC ${stupidAI_SRCS} ${stupidAI_HEADERS})
+else()
+	add_library(StupidAI SHARED ${stupidAI_SRCS} ${stupidAI_HEADERS})
+	install(TARGETS StupidAI RUNTIME DESTINATION ${AI_LIB_DIR} LIBRARY DESTINATION ${AI_LIB_DIR})
+endif()
+
 target_link_libraries(StupidAI PRIVATE ${VCMI_LIB_TARGET})
 target_include_directories(StupidAI PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
 
 vcmi_set_output_dir(StupidAI "AI")
 enable_pch(StupidAI)
-
-install(TARGETS StupidAI RUNTIME DESTINATION ${AI_LIB_DIR} LIBRARY DESTINATION ${AI_LIB_DIR})

+ 1 - 0
client/CMakeLists.txt

@@ -255,6 +255,7 @@ add_dependencies(vcmiclient vcmiserver)
 if(NOT ENABLE_STATIC_AI_LIBS)
 	add_dependencies(vcmiclient
 		BattleAI
+		EmptyAI
 		StupidAI
 		VCAI
 	)

+ 7 - 1
lib/CGameInterface.cpp

@@ -20,6 +20,8 @@
 # include "AI/VCAI/VCAI.h"
 # include "AI/Nullkiller/AIGateway.h"
 # include "AI/BattleAI/BattleAI.h"
+# include "AI/StupidAI/StupidAI.h"
+# include "AI/EmptyAI/CEmptyAI.h"
 #else
 # ifdef VCMI_WINDOWS
 #  include <windows.h> //for .dll libs
@@ -113,7 +115,11 @@ std::shared_ptr<CGlobalAI> createAny(const boost::filesystem::path & libpath, co
 template<>
 std::shared_ptr<CBattleGameInterface> createAny(const boost::filesystem::path & libpath, const std::string & methodName)
 {
-	return std::make_shared<CBattleAI>();
+	if(libpath.stem() == "libBattleAI")
+		return std::make_shared<CBattleAI>();
+	else if(libpath.stem() == "libStupidAI")
+		return std::make_shared<CStupidAI>();
+	return std::make_shared<CEmptyAI>();
 }
 
 #endif // STATIC_AI

+ 2 - 0
lib/CMakeLists.txt

@@ -3,6 +3,8 @@ if(ENABLE_STATIC_AI_LIBS)
 	target_compile_definitions(${VCMI_LIB_TARGET} PRIVATE STATIC_AI)
 	target_link_libraries(${VCMI_LIB_TARGET} PRIVATE
 		BattleAI
+		EmptyAI
+		StupidAI
 		VCAI
 	)
 	if(ENABLE_NULLKILLER_AI)