CMakeLists.txt 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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/TestDataFactory.cpp
  147. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/TestHelper.hpp
  148. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/XmlParserTestWrapper.cpp)
  149. set(TEST_FILES_LOGIC
  150. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateConnectionTest.cpp
  151. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateMachineTest.cpp
  152. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateTest.cpp
  153. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateConnectionTest.cpp
  154. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateMachineTest.cpp
  155. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateTest.cpp)
  156. set(TEST_FILES_SERIALIZATION
  157. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/JsonTest.cpp)
  158. set(TEST_FILES_TIME
  159. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/DateTest.cpp)
  160. set(TEST_FILES
  161. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestDataFactory.hpp
  162. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestDataFactory.cpp)
  163. endif ()
  164. ##########################################################
  165. # Build Tests (boxing)
  166. ##########################################################
  167. if (${LS_STD_BUILD_WITH_TESTS})
  168. message("${MODULE_NAME_BOXING}: Building tests...")
  169. add_executable(${MODULE_NAME_BOXING}_test ${TEST_FILES_BOXING})
  170. endif ()
  171. ##########################################################
  172. # Build Tests (core)
  173. ##########################################################
  174. if (${LS_STD_BUILD_WITH_TESTS})
  175. message("${MODULE_NAME_CORE}: Building tests...")
  176. add_executable(${MODULE_NAME_CORE}_test ${TEST_FILES_CORE})
  177. endif ()
  178. ##########################################################
  179. # Build Tests (event)
  180. ##########################################################
  181. if (${LS_STD_BUILD_WITH_TESTS})
  182. message("${MODULE_NAME_EVENT}: Building tests...")
  183. add_executable(${MODULE_NAME_EVENT}_test ${TEST_FILES_EVENT})
  184. endif ()
  185. ##########################################################
  186. # Build Tests (io)
  187. ##########################################################
  188. if (${LS_STD_BUILD_WITH_TESTS})
  189. message("${MODULE_NAME_IO}: Building tests...")
  190. add_executable(${MODULE_NAME_IO}_test ${TEST_FILES_IO})
  191. endif ()
  192. ##########################################################
  193. # Build Tests
  194. ##########################################################
  195. if (${LS_STD_BUILD_WITH_TESTS})
  196. message("${PROJECT_NAME}: Building tests...")
  197. add_executable(${PROJECT_NAME}_test
  198. ${TEST_FILES_BOXING}
  199. ${TEST_FILES_CORE}
  200. ${TEST_FILES_EVENT}
  201. ${TEST_FILES_IO}
  202. ${TEST_FILES_LOGIC}
  203. ${TEST_FILES_SERIALIZATION}
  204. ${TEST_FILES_TIME}
  205. ${TEST_FILES})
  206. endif ()
  207. ##########################################################
  208. # Build Library (boxing)
  209. ##########################################################
  210. message("${PROJECT_NAME}: Building ${MODULE_NAME_BOXING} library version ${PROJECT_VERSION}...")
  211. if (${LS_STD_BUILD_STATIC})
  212. add_library("${MODULE_NAME_BOXING}" STATIC ${SOURCE_FILES_BOXING})
  213. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  214. endif ()
  215. if (${LS_STD_BUILD_SHARED})
  216. add_library("${MODULE_NAME_BOXING}" SHARED ${SOURCE_FILES_BOXING})
  217. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  218. endif ()
  219. if (${LS_STD_BUILD_MODULE})
  220. add_library("${MODULE_NAME_BOXING}" MODULE ${SOURCE_FILES_BOXING})
  221. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  222. endif ()
  223. ##########################################################
  224. # Build Library (core)
  225. ##########################################################
  226. message("${PROJECT_NAME}: Building ${MODULE_NAME_CORE} library version ${PROJECT_VERSION}...")
  227. if (${LS_STD_BUILD_STATIC})
  228. add_library("${MODULE_NAME_CORE}" STATIC ${SOURCE_FILES_CORE})
  229. set_target_properties("${MODULE_NAME_CORE}" PROPERTIES DEBUG_POSTFIX "_d")
  230. endif ()
  231. ##########################################################
  232. # Build Library (event)
  233. ##########################################################
  234. message("${PROJECT_NAME}: Building ${MODULE_NAME_EVENT} library version ${PROJECT_VERSION}...")
  235. if (${LS_STD_BUILD_STATIC})
  236. add_library("${MODULE_NAME_EVENT}" STATIC ${SOURCE_FILES_EVENT})
  237. set_target_properties("${MODULE_NAME_EVENT}" PROPERTIES DEBUG_POSTFIX "_d")
  238. endif ()
  239. ##########################################################
  240. # Build Library (io)
  241. ##########################################################
  242. message("${PROJECT_NAME}: Building ${MODULE_NAME_IO} library version ${PROJECT_VERSION}...")
  243. if (${LS_STD_BUILD_STATIC})
  244. add_library("${MODULE_NAME_IO}" STATIC ${SOURCE_FILES_IO})
  245. set_target_properties("${MODULE_NAME_IO}" PROPERTIES DEBUG_POSTFIX "_d")
  246. endif ()
  247. ##########################################################
  248. # Build Library (logic)
  249. ##########################################################
  250. message("${PROJECT_NAME}: Building ${MODULE_NAME_LOGIC} library version ${PROJECT_VERSION}...")
  251. if (${LS_STD_BUILD_STATIC})
  252. add_library("${MODULE_NAME_LOGIC}" STATIC ${SOURCE_FILES_LOGIC})
  253. set_target_properties("${MODULE_NAME_LOGIC}" PROPERTIES DEBUG_POSTFIX "_d")
  254. endif ()
  255. ##########################################################
  256. # Build Library (time)
  257. ##########################################################
  258. message("${PROJECT_NAME}: Building ${MODULE_NAME_TIME} library version ${PROJECT_VERSION}...")
  259. if (${LS_STD_BUILD_STATIC})
  260. add_library("${MODULE_NAME_TIME}" STATIC ${SOURCE_FILES_TIME})
  261. set_target_properties("${MODULE_NAME_TIME}" PROPERTIES DEBUG_POSTFIX "_d")
  262. endif ()
  263. ##########################################################
  264. # Linking (boxing)
  265. ##########################################################
  266. if (${LS_STD_BUILD_WITH_TESTS})
  267. message("${MODULE_NAME_BOXING}: Linking libraries for test application...")
  268. target_link_libraries(${MODULE_NAME_BOXING}_test
  269. gtest
  270. gmock
  271. gtest_main
  272. "${MODULE_NAME_BOXING}"
  273. "${MODULE_NAME_CORE}")
  274. endif ()
  275. ##########################################################
  276. # Linking (core)
  277. ##########################################################
  278. if (${LS_STD_BUILD_WITH_TESTS})
  279. message("${MODULE_NAME_CORE}: Linking libraries for test application...")
  280. target_link_libraries(${MODULE_NAME_CORE}_test
  281. gtest
  282. gmock
  283. gtest_main
  284. "${MODULE_NAME_CORE}")
  285. endif ()
  286. ##########################################################
  287. # Linking (event)
  288. ##########################################################
  289. if (${LS_STD_BUILD_WITH_TESTS})
  290. message("${MODULE_NAME_EVENT}: Linking libraries for test application...")
  291. target_link_libraries(${MODULE_NAME_EVENT}_test
  292. gtest
  293. gmock
  294. gtest_main
  295. "${MODULE_NAME_EVENT}"
  296. "${MODULE_NAME_CORE}")
  297. endif ()
  298. ##########################################################
  299. # Linking (io)
  300. ##########################################################
  301. if (${LS_STD_BUILD_WITH_TESTS})
  302. message("${MODULE_NAME_IO}: Linking libraries for test application...")
  303. target_link_libraries(${MODULE_NAME_IO}_test
  304. gtest
  305. gmock
  306. gtest_main
  307. "${MODULE_NAME_IO}"
  308. "${MODULE_NAME_CORE}")
  309. endif ()
  310. ##########################################################
  311. # Linking
  312. ##########################################################
  313. if (${LS_STD_BUILD_WITH_TESTS})
  314. message("${PROJECT_NAME}: Linking libraries for test application...")
  315. target_link_libraries(${PROJECT_NAME}_test
  316. gtest
  317. gmock
  318. gtest_main
  319. "${MODULE_NAME_CORE}"
  320. "${MODULE_NAME_BOXING}"
  321. "${MODULE_NAME_EVENT}"
  322. "${MODULE_NAME_IO}"
  323. "${MODULE_NAME_LOGIC}"
  324. "${MODULE_NAME_TIME}")
  325. endif ()