CMakeLists.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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/NewsAgency.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/SeriousNewsEvent.cpp)
  123. set(TEST_FILES_IO
  124. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvDocumentTest.cpp
  125. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvFileReaderTest.cpp
  126. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvPairTest.cpp
  127. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/kv/KvParserTest.cpp
  128. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/logging/LoggerTest.cpp
  129. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/logging/LogLevelTest.cpp
  130. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlAttributeTest.cpp
  131. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlDeclarationTest.cpp
  132. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlDocumentTest.cpp
  133. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlNodeTest.cpp
  134. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlParserTest.cpp
  135. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlParserTestWrapperTest.cpp
  136. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XmlReaderTest.cpp
  137. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileOutputStreamTest.cpp
  138. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileReaderTest.cpp
  139. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileTest.cpp
  140. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileWriterTest.cpp
  141. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/StandardOutputWriterTest.cpp
  142. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/StorableFileTest.cpp
  143. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/io/xml/XmlParserTestWrapper.cpp)
  144. set(TEST_FILES_LOGIC
  145. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateConnectionTest.cpp
  146. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateMachineTest.cpp
  147. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/serialization/SerializableJsonStateTest.cpp
  148. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateConnectionTest.cpp
  149. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateMachineTest.cpp
  150. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateTest.cpp
  151. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/observer/TestDataCar.cpp
  152. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/observer/TestDataMercedesCar.cpp)
  153. set(TEST_FILES_SERIALIZATION
  154. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/JsonTest.cpp)
  155. set(TEST_FILES_TIME
  156. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/DateTest.cpp)
  157. set(TEST_FILES
  158. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestHelper.hpp
  159. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestDataFactory.hpp
  160. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestDataFactory.cpp)
  161. endif ()
  162. ##########################################################
  163. # Build Tests (boxing)
  164. ##########################################################
  165. if (${LS_STD_BUILD_WITH_TESTS})
  166. message("${MODULE_NAME_BOXING}: Building tests...")
  167. add_executable(${MODULE_NAME_BOXING}_test ${TEST_FILES_BOXING})
  168. endif ()
  169. ##########################################################
  170. # Build Tests (core)
  171. ##########################################################
  172. if (${LS_STD_BUILD_WITH_TESTS})
  173. message("${MODULE_NAME_CORE}: Building tests...")
  174. add_executable(${MODULE_NAME_CORE}_test ${TEST_FILES_CORE})
  175. endif ()
  176. ##########################################################
  177. # Build Tests
  178. ##########################################################
  179. if (${LS_STD_BUILD_WITH_TESTS})
  180. message("${PROJECT_NAME}: Building tests...")
  181. add_executable(${PROJECT_NAME}_test
  182. ${TEST_FILES_BOXING}
  183. ${TEST_FILES_CORE}
  184. ${TEST_FILES_EVENT}
  185. ${TEST_FILES_IO}
  186. ${TEST_FILES_LOGIC}
  187. ${TEST_FILES_SERIALIZATION}
  188. ${TEST_FILES_TIME}
  189. ${TEST_FILES})
  190. endif ()
  191. ##########################################################
  192. # Build Library (boxing)
  193. ##########################################################
  194. message("${PROJECT_NAME}: Building ${MODULE_NAME_BOXING} library version ${PROJECT_VERSION}...")
  195. if (${LS_STD_BUILD_STATIC})
  196. add_library("${MODULE_NAME_BOXING}" STATIC ${SOURCE_FILES_BOXING})
  197. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  198. endif ()
  199. if (${LS_STD_BUILD_SHARED})
  200. add_library("${MODULE_NAME_BOXING}" SHARED ${SOURCE_FILES_BOXING})
  201. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  202. endif ()
  203. if (${LS_STD_BUILD_MODULE})
  204. add_library("${MODULE_NAME_BOXING}" MODULE ${SOURCE_FILES_BOXING})
  205. set_target_properties("${MODULE_NAME_BOXING}" PROPERTIES DEBUG_POSTFIX "_d")
  206. endif ()
  207. ##########################################################
  208. # Build Library (core)
  209. ##########################################################
  210. message("${PROJECT_NAME}: Building ${MODULE_NAME_CORE} library version ${PROJECT_VERSION}...")
  211. if (${LS_STD_BUILD_STATIC})
  212. add_library("${MODULE_NAME_CORE}" STATIC ${SOURCE_FILES_CORE})
  213. set_target_properties("${MODULE_NAME_CORE}" PROPERTIES DEBUG_POSTFIX "_d")
  214. endif ()
  215. ##########################################################
  216. # Build Library (event)
  217. ##########################################################
  218. message("${PROJECT_NAME}: Building ${MODULE_NAME_EVENT} library version ${PROJECT_VERSION}...")
  219. if (${LS_STD_BUILD_STATIC})
  220. add_library("${MODULE_NAME_EVENT}" STATIC ${SOURCE_FILES_EVENT})
  221. set_target_properties("${MODULE_NAME_EVENT}" PROPERTIES DEBUG_POSTFIX "_d")
  222. endif ()
  223. ##########################################################
  224. # Build Library (io)
  225. ##########################################################
  226. message("${PROJECT_NAME}: Building ${MODULE_NAME_IO} library version ${PROJECT_VERSION}...")
  227. if (${LS_STD_BUILD_STATIC})
  228. add_library("${MODULE_NAME_IO}" STATIC ${SOURCE_FILES_IO})
  229. set_target_properties("${MODULE_NAME_IO}" PROPERTIES DEBUG_POSTFIX "_d")
  230. endif ()
  231. ##########################################################
  232. # Build Library (logic)
  233. ##########################################################
  234. message("${PROJECT_NAME}: Building ${MODULE_NAME_LOGIC} library version ${PROJECT_VERSION}...")
  235. if (${LS_STD_BUILD_STATIC})
  236. add_library("${MODULE_NAME_LOGIC}" STATIC ${SOURCE_FILES_LOGIC})
  237. set_target_properties("${MODULE_NAME_LOGIC}" PROPERTIES DEBUG_POSTFIX "_d")
  238. endif ()
  239. ##########################################################
  240. # Build Library (time)
  241. ##########################################################
  242. message("${PROJECT_NAME}: Building ${MODULE_NAME_TIME} library version ${PROJECT_VERSION}...")
  243. if (${LS_STD_BUILD_STATIC})
  244. add_library("${MODULE_NAME_TIME}" STATIC ${SOURCE_FILES_TIME})
  245. set_target_properties("${MODULE_NAME_TIME}" PROPERTIES DEBUG_POSTFIX "_d")
  246. endif ()
  247. ##########################################################
  248. # Linking (boxing)
  249. ##########################################################
  250. if (${LS_STD_BUILD_WITH_TESTS})
  251. message("${MODULE_NAME_BOXING}: Linking libraries for test application...")
  252. target_link_libraries(${MODULE_NAME_BOXING}_test
  253. gtest
  254. gmock
  255. gtest_main
  256. "${MODULE_NAME_BOXING}"
  257. "${MODULE_NAME_CORE}")
  258. endif ()
  259. ##########################################################
  260. # Linking (core)
  261. ##########################################################
  262. if (${LS_STD_BUILD_WITH_TESTS})
  263. message("${MODULE_NAME_CORE}: Linking libraries for test application...")
  264. target_link_libraries(${MODULE_NAME_CORE}_test
  265. gtest
  266. gmock
  267. gtest_main
  268. "${MODULE_NAME_CORE}")
  269. endif ()
  270. ##########################################################
  271. # Linking
  272. ##########################################################
  273. if (${LS_STD_BUILD_WITH_TESTS})
  274. message("${PROJECT_NAME}: Linking libraries for test application...")
  275. target_link_libraries(${PROJECT_NAME}_test
  276. gtest
  277. gmock
  278. gtest_main
  279. "${MODULE_NAME_CORE}"
  280. "${MODULE_NAME_BOXING}"
  281. "${MODULE_NAME_EVENT}"
  282. "${MODULE_NAME_IO}"
  283. "${MODULE_NAME_LOGIC}"
  284. "${MODULE_NAME_TIME}")
  285. endif ()