CMakeLists.txt 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. ##########################################################
  2. # Basic
  3. ##########################################################
  4. cmake_minimum_required(VERSION 3.17)
  5. project(ls_std VERSION 2022.1.0)
  6. set(MODULE_NAME_BOXING ls_std_boxing)
  7. set(MODULE_NAME_CORE ls_std_core)
  8. set(MODULE_NAME_EVENT ls_std_event)
  9. set(MODULE_NAME_IO ls_std_io)
  10. set(MODULE_NAME_LOGIC ls_std_logic)
  11. set(MODULE_NAME_TIME ls_std_time)
  12. ##########################################################
  13. # Options
  14. ##########################################################
  15. option(LS_STD_BUILD_WITH_TESTS "Build project with tests..." OFF)
  16. option(LS_STD_BUILD_STATIC "Build ls_std static library..." ON)
  17. option(LS_STD_BUILD_SHARED "Build ls_std shared library..." OFF)
  18. option(LS_STD_BUILD_MODULE "Build ls_std module library..." OFF)
  19. ##########################################################
  20. # Compiler Settings
  21. ##########################################################
  22. message("${PROJECT_NAME}: Setting compiler flags...")
  23. set(CMAKE_CXX_STANDARD 11)
  24. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  25. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  26. ######################################################
  27. # Include Directories
  28. ######################################################
  29. message("${PROJECT_NAME}: Adding include directories...")
  30. if (${LS_STD_BUILD_WITH_TESTS})
  31. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test)
  32. include_directories(${CMAKE_CURRENT_LIST_DIR}/test/lib/googletest-1.8.1/googletest/include)
  33. include_directories(${CMAKE_CURRENT_LIST_DIR}/test/lib/googletest-1.8.1/googlemock/include)
  34. endif ()
  35. include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
  36. ######################################################
  37. # Add Other CMake Dependencies
  38. ######################################################
  39. message("${PROJECT_NAME}: Adding additional cmake dependencies...")
  40. if (${LS_STD_BUILD_WITH_TESTS})
  41. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test/lib/googletest-1.8.1)
  42. endif ()
  43. ##########################################################
  44. # Source Files
  45. ##########################################################
  46. set(SOURCE_FILES_BOXING
  47. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Boolean.cpp
  48. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Double.cpp
  49. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Float.cpp
  50. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Integer.cpp
  51. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Long.cpp
  52. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/String.cpp)
  53. set(SOURCE_FILES_CORE
  54. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Class.cpp
  55. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/core/Version.cpp)
  56. set(SOURCE_FILES_EVENT
  57. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/serialization/SerializableJsonEvent.cpp
  58. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/Event.cpp
  59. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/EventHandler.cpp
  60. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/EventManager.cpp
  61. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/Narrator.cpp)
  62. set(SOURCE_FILES_IO
  63. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/kv/KvDocument.cpp
  64. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/kv/KvFileReader.cpp
  65. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/kv/KvPair.cpp
  66. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/kv/KvParser.cpp
  67. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/logging/Logger.cpp
  68. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/logging/LogLevel.cpp
  69. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XmlAttribute.cpp
  70. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XmlDeclaration.cpp
  71. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XmlDocument.cpp
  72. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XmlNode.cpp
  73. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XmlParser.cpp
  74. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XmlReader.cpp
  75. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/File.cpp
  76. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/FileOutputStream.cpp
  77. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/FileReader.cpp
  78. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/FileWriter.cpp
  79. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/StandardOutputWriter.cpp
  80. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/StorableFile.cpp)
  81. set(SOURCE_FILES_LOGIC
  82. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/serialization/SerializableJsonState.cpp
  83. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/serialization/SerializableJsonStateConnection.cpp
  84. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/serialization/SerializableJsonStateMachine.cpp
  85. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/State.cpp
  86. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/StateConnection.cpp
  87. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/StateMachine.cpp)
  88. set(SOURCE_FILES_TIME
  89. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/time/Date.cpp)
  90. if (${LS_STD_BUILD_WITH_TESTS})
  91. set(TEST_FILES_BOXING
  92. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/BooleanTest.cpp
  93. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/DoubleTest.cpp
  94. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/FloatTest.cpp
  95. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/IntegerTest.cpp
  96. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/LongTest.cpp
  97. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/StringTest.cpp)
  98. set(TEST_FILES_CORE
  99. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/EventNotHandledExceptionTest.cpp
  100. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/EventNotSubscribedExceptionTest.cpp
  101. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/FileNotFoundExceptionTest.cpp
  102. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/FileOperationExceptionTest.cpp
  103. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/IllegalArgumentExceptionTest.cpp
  104. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/IllegalArithmeticOperationExceptionTest.cpp
  105. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/IncompleteJsonExceptionTest.cpp
  106. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/exception/NullPointerExceptionTest.cpp
  107. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/utils/RegexUtilsTest.cpp
  108. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/utils/STLUtilsTest.cpp
  109. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/ClassTest.cpp
  110. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/LibraryVersionTest.cpp
  111. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/core/VersionTest.cpp)
  112. set(TEST_FILES_EVENT
  113. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/serialization/SerializableJsonEventTest.cpp
  114. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventHandlerTest.cpp
  115. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventManagerTest.cpp
  116. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventTest.cpp
  117. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/NarratorTest.cpp
  118. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/Colour.cpp
  119. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/DailyNewsAgency.cpp
  120. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/GossipNewsAgency.cpp
  121. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/GossipNewsEvent.cpp
  122. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/NewsAgency.cpp
  123. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/SeriousNewsEvent.cpp
  124. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/TestDataCar.cpp
  125. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/TestDataMercedesCar.cpp)
  126. set(TEST_FILES_IO
  127. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvDocumentTest.cpp
  128. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvFileReaderTest.cpp
  129. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvPairTest.cpp
  130. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvParserTest.cpp
  131. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/logging/LoggerTest.cpp
  132. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/logging/LogLevelTest.cpp
  133. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlAttributeTest.cpp
  134. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlDeclarationTest.cpp
  135. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlDocumentTest.cpp
  136. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlNodeTest.cpp
  137. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlParserTest.cpp
  138. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlParserTestWrapperTest.cpp
  139. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlReaderTest.cpp
  140. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileOutputStreamTest.cpp
  141. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileReaderTest.cpp
  142. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileTest.cpp
  143. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileWriterTest.cpp
  144. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/StandardOutputWriterTest.cpp
  145. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/StorableFileTest.cpp
  146. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/XmlParserTestWrapper.cpp)
  147. set(TEST_FILES_LOGIC
  148. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateConnectionTest.cpp
  149. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateMachineTest.cpp
  150. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateTest.cpp
  151. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateConnectionTest.cpp
  152. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateMachineTest.cpp
  153. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateTest.cpp)
  154. set(TEST_FILES_SERIALIZATION
  155. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/JsonTest.cpp)
  156. set(TEST_FILES_TIME
  157. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/DateTest.cpp)
  158. set(TEST_FILES
  159. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestHelper.hpp
  160. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestDataFactory.hpp
  161. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestDataFactory.cpp)
  162. endif ()
  163. ##########################################################
  164. # Build Tests (boxing)
  165. ##########################################################
  166. if (${LS_STD_BUILD_WITH_TESTS})
  167. message("${MODULE_NAME_BOXING}: Building tests...")
  168. add_executable(${MODULE_NAME_BOXING}_test ${TEST_FILES_BOXING})
  169. endif ()
  170. ##########################################################
  171. # Build Tests (core)
  172. ##########################################################
  173. if (${LS_STD_BUILD_WITH_TESTS})
  174. message("${MODULE_NAME_CORE}: Building tests...")
  175. add_executable(${MODULE_NAME_CORE}_test ${TEST_FILES_CORE})
  176. endif ()
  177. ##########################################################
  178. # Build Tests (event)
  179. ##########################################################
  180. if (${LS_STD_BUILD_WITH_TESTS})
  181. message("${MODULE_NAME_EVENT}: Building tests...")
  182. add_executable(${MODULE_NAME_EVENT}_test ${TEST_FILES_EVENT})
  183. endif ()
  184. ##########################################################
  185. # Build Tests
  186. ##########################################################
  187. if (${LS_STD_BUILD_WITH_TESTS})
  188. message("${PROJECT_NAME}: Building tests...")
  189. add_executable(${PROJECT_NAME}_test
  190. ${TEST_FILES_BOXING}
  191. ${TEST_FILES_CORE}
  192. ${TEST_FILES_EVENT}
  193. ${TEST_FILES_IO}
  194. ${TEST_FILES_LOGIC}
  195. ${TEST_FILES_SERIALIZATION}
  196. ${TEST_FILES_TIME}
  197. ${TEST_FILES})
  198. endif ()
  199. ##########################################################
  200. # Build Library (boxing)
  201. ##########################################################
  202. message("${PROJECT_NAME}: Building ${MODULE_NAME_BOXING} library version ${PROJECT_VERSION}...")
  203. if (${LS_STD_BUILD_STATIC})
  204. add_library("${MODULE_NAME_BOXING}" STATIC ${SOURCE_FILES_BOXING})
  205. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  206. endif ()
  207. if (${LS_STD_BUILD_SHARED})
  208. add_library("${MODULE_NAME_BOXING}" SHARED ${SOURCE_FILES_BOXING})
  209. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  210. endif ()
  211. if (${LS_STD_BUILD_MODULE})
  212. add_library("${MODULE_NAME_BOXING}" MODULE ${SOURCE_FILES_BOXING})
  213. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  214. endif ()
  215. ##########################################################
  216. # Build Library (core)
  217. ##########################################################
  218. message("${PROJECT_NAME}: Building ${MODULE_NAME_CORE} library version ${PROJECT_VERSION}...")
  219. if (${LS_STD_BUILD_STATIC})
  220. add_library("${MODULE_NAME_CORE}" STATIC ${SOURCE_FILES_CORE})
  221. set_target_properties("${MODULE_NAME_CORE}" PROPERTIES DEBUG_POSTFIX "_d")
  222. endif ()
  223. ##########################################################
  224. # Build Library (event)
  225. ##########################################################
  226. message("${PROJECT_NAME}: Building ${MODULE_NAME_EVENT} library version ${PROJECT_VERSION}...")
  227. if (${LS_STD_BUILD_STATIC})
  228. add_library("${MODULE_NAME_EVENT}" STATIC ${SOURCE_FILES_EVENT})
  229. set_target_properties("${MODULE_NAME_EVENT}" PROPERTIES DEBUG_POSTFIX "_d")
  230. endif ()
  231. ##########################################################
  232. # Build Library (io)
  233. ##########################################################
  234. message("${PROJECT_NAME}: Building ${MODULE_NAME_IO} library version ${PROJECT_VERSION}...")
  235. if (${LS_STD_BUILD_STATIC})
  236. add_library("${MODULE_NAME_IO}" STATIC ${SOURCE_FILES_IO})
  237. set_target_properties("${MODULE_NAME_IO}" PROPERTIES DEBUG_POSTFIX "_d")
  238. endif ()
  239. ##########################################################
  240. # Build Library (logic)
  241. ##########################################################
  242. message("${PROJECT_NAME}: Building ${MODULE_NAME_LOGIC} library version ${PROJECT_VERSION}...")
  243. if (${LS_STD_BUILD_STATIC})
  244. add_library("${MODULE_NAME_LOGIC}" STATIC ${SOURCE_FILES_LOGIC})
  245. set_target_properties("${MODULE_NAME_LOGIC}" PROPERTIES DEBUG_POSTFIX "_d")
  246. endif ()
  247. ##########################################################
  248. # Build Library (time)
  249. ##########################################################
  250. message("${PROJECT_NAME}: Building ${MODULE_NAME_TIME} library version ${PROJECT_VERSION}...")
  251. if (${LS_STD_BUILD_STATIC})
  252. add_library("${MODULE_NAME_TIME}" STATIC ${SOURCE_FILES_TIME})
  253. set_target_properties("${MODULE_NAME_TIME}" PROPERTIES DEBUG_POSTFIX "_d")
  254. endif ()
  255. ##########################################################
  256. # Linking (boxing)
  257. ##########################################################
  258. if (${LS_STD_BUILD_WITH_TESTS})
  259. message("${MODULE_NAME_BOXING}: Linking libraries for test application...")
  260. target_link_libraries(${MODULE_NAME_BOXING}_test
  261. gtest
  262. gmock
  263. gtest_main
  264. "${MODULE_NAME_BOXING}"
  265. "${MODULE_NAME_CORE}")
  266. endif ()
  267. ##########################################################
  268. # Linking (core)
  269. ##########################################################
  270. if (${LS_STD_BUILD_WITH_TESTS})
  271. message("${MODULE_NAME_CORE}: Linking libraries for test application...")
  272. target_link_libraries(${MODULE_NAME_CORE}_test
  273. gtest
  274. gmock
  275. gtest_main
  276. "${MODULE_NAME_CORE}")
  277. endif ()
  278. ##########################################################
  279. # Linking (event)
  280. ##########################################################
  281. if (${LS_STD_BUILD_WITH_TESTS})
  282. message("${MODULE_NAME_EVENT}: Linking libraries for test application...")
  283. target_link_libraries(${MODULE_NAME_EVENT}_test
  284. gtest
  285. gmock
  286. gtest_main
  287. "${MODULE_NAME_EVENT}"
  288. "${MODULE_NAME_CORE}")
  289. endif ()
  290. ##########################################################
  291. # Linking
  292. ##########################################################
  293. if (${LS_STD_BUILD_WITH_TESTS})
  294. message("${PROJECT_NAME}: Linking libraries for test application...")
  295. target_link_libraries(${PROJECT_NAME}_test
  296. gtest
  297. gmock
  298. gtest_main
  299. "${MODULE_NAME_CORE}"
  300. "${MODULE_NAME_BOXING}"
  301. "${MODULE_NAME_EVENT}"
  302. "${MODULE_NAME_IO}"
  303. "${MODULE_NAME_LOGIC}"
  304. "${MODULE_NAME_TIME}")
  305. endif ()