CMakeLists.txt 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. ##########################################################
  2. # Basic
  3. ##########################################################
  4. cmake_minimum_required(VERSION 3.17)
  5. project(ls_std VERSION 2020.3.1)
  6. ##########################################################
  7. # Options
  8. ##########################################################
  9. option(LS_STD_BUILD_WITH_TESTS "Build project with tests..." ON)
  10. option(LS_STD_BUILD_STATIC "Build ls_std static library..." ON)
  11. option(LS_STD_BUILD_SHARED "Build ls_std shared library..." OFF)
  12. option(LS_STD_BUILD_MODULE "Build ls_std module library..." OFF)
  13. ##########################################################
  14. # Compiler Settings
  15. ##########################################################
  16. message("${PROJECT_NAME}: Setting compiler flags...")
  17. set(CMAKE_CXX_STANDARD 11)
  18. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
  19. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  20. ######################################################
  21. # Include Directories
  22. ######################################################
  23. message("${PROJECT_NAME}: Adding include directories...")
  24. if (${LS_STD_BUILD_WITH_TESTS})
  25. include_directories(${CMAKE_CURRENT_SOURCE_DIR}/test)
  26. include_directories(${CMAKE_CURRENT_LIST_DIR}/test/lib/googletest-1.8.1/googletest/include)
  27. endif ()
  28. include_directories(${CMAKE_CURRENT_LIST_DIR}/include)
  29. ######################################################
  30. # Add Other CMake Dependencies
  31. ######################################################
  32. message("${PROJECT_NAME}: Adding additional cmake dependencies...")
  33. if (${LS_STD_BUILD_WITH_TESTS})
  34. add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/test/lib/googletest-1.8.1)
  35. endif ()
  36. ##########################################################
  37. # Source Files
  38. ##########################################################
  39. set(SOURCE_FILES
  40. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/base/Class.cpp
  41. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Integer.cpp
  42. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Boolean.cpp
  43. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Float.cpp
  44. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Double.cpp
  45. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/String.cpp
  46. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/time/Date.cpp
  47. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/File.cpp
  48. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/boxing/Long.cpp
  49. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/FileWriter.cpp
  50. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/FileReader.cpp
  51. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/StorableFile.cpp
  52. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/FileOutputStream.cpp
  53. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/logging/Logger.cpp
  54. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/logging/LogLevel.cpp
  55. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/boxing/SerializableJSONInteger.cpp
  56. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/boxing/SerializableJSONLong.cpp
  57. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/boxing/SerializableJSONString.cpp
  58. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/boxing/SerializableJSONFloat.cpp
  59. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/boxing/SerializableJSONDouble.cpp
  60. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/boxing/SerializableJSONBoolean.cpp
  61. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/StateMachine.cpp
  62. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/State.cpp
  63. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/StateConnection.cpp
  64. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/logic/SerializableJSONStateConnection.cpp
  65. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/logic/SerializableJSONState.cpp
  66. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/serialization/json/logic/SerializableJSONStateMachine.cpp
  67. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XMLAttribute.cpp
  68. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XMLNode.cpp
  69. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/base/Version.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/XMLReader.cpp
  73. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XMLParserMock.cpp
  74. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/StandardOutputWriter.cpp
  75. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/Narrator.cpp
  76. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/logic/IListener.cpp
  77. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/io/xml/XMLParser.cpp
  78. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/Event.cpp
  79. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/EventHandler.cpp
  80. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/event/EventManager.cpp
  81. ${CMAKE_CURRENT_SOURCE_DIR}/source/ls_std/network/Socket.cpp)
  82. if (${LS_STD_BUILD_WITH_TESTS})
  83. set(TEST_FILES
  84. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/IntegerTest.cpp
  85. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/BooleanTest.cpp
  86. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/FloatTest.cpp
  87. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/DoubleTest.cpp
  88. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/StringTest.cpp
  89. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/time/DateTest.cpp
  90. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileTest.cpp
  91. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestHelper.hpp
  92. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/base/ClassTest.cpp
  93. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/utils/STLUtilsTest.cpp
  94. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/boxing/LongTest.cpp
  95. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileWriterTest.cpp
  96. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileReaderTest.cpp
  97. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/utils/RegexUtilsTest.cpp
  98. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/StorableFileTest.cpp
  99. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/FileOutputStreamTest.cpp
  100. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/logging/LoggerTest.cpp
  101. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/JSONTest.cpp
  102. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/boxing/SerializableJSONIntegerTest.cpp
  103. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/boxing/SerializableJSONLongTest.cpp
  104. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/boxing/SerializableJSONStringTest.cpp
  105. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/boxing/SerializableJSONFloatTest.cpp
  106. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/boxing/SerializableJSONDoubleTest.cpp
  107. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/boxing/SerializableJSONBooleanTest.cpp
  108. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateTest.cpp
  109. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateMachineTest.cpp
  110. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/StateConnectionTest.cpp
  111. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/logic/SerializableJSONStateConnectionTest.cpp
  112. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/logic/SerializableJSONStateTest.cpp
  113. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/serialization/json/logic/SerializableJSONStateMachineTest.cpp
  114. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestDataFactory.hpp
  115. ${CMAKE_CURRENT_SOURCE_DIR}/test/TestDataFactory.cpp
  116. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XMLAttributeTest.cpp
  117. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XMLNodeTest.cpp
  118. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/base/VersionTest.cpp
  119. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XMLDeclarationTest.cpp
  120. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XMLDocumentTest.cpp
  121. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XMLReaderTest.cpp
  122. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XMLParserMockTest.cpp
  123. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/observer/TestDataCar.cpp
  124. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/observer/TestDataMercedesCar.cpp
  125. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/logic/NarratorTest.cpp
  126. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/io/xml/XMLParserTest.cpp
  127. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventTest.cpp
  128. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/NewsAgency.cpp
  129. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/DailyNewsAgency.cpp
  130. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/SeriousNewsEvent.cpp
  131. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/GossipNewsEvent.cpp
  132. ${CMAKE_CURRENT_SOURCE_DIR}/test/classes/event/GossipNewsAgency.cpp
  133. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventHandlerTest.cpp
  134. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/event/EventManagerTest.cpp
  135. ${CMAKE_CURRENT_SOURCE_DIR}/test/cases/network/SocketTest.cpp)
  136. endif ()
  137. ##########################################################
  138. # Build Tests
  139. ##########################################################
  140. if (${LS_STD_BUILD_WITH_TESTS})
  141. message("${PROJECT_NAME}: Building tests...")
  142. add_executable(${PROJECT_NAME}_test ${TEST_FILES})
  143. endif ()
  144. ##########################################################
  145. # Build Library
  146. ##########################################################
  147. message("${PROJECT_NAME}: Building library version ${PROJECT_VERSION}...")
  148. if (${LS_STD_BUILD_STATIC})
  149. add_library("${PROJECT_NAME}_${PROJECT_VERSION}_static" STATIC ${SOURCE_FILES})
  150. set_target_properties("${PROJECT_NAME}_${PROJECT_VERSION}_static" PROPERTIES DEBUG_POSTFIX "_d")
  151. endif ()
  152. if (${LS_STD_BUILD_SHARED})
  153. add_library("${PROJECT_NAME}_${PROJECT_VERSION}_shared" SHARED ${SOURCE_FILES})
  154. set_target_properties("${PROJECT_NAME}_${PROJECT_VERSION}_shared" PROPERTIES DEBUG_POSTFIX "_d")
  155. endif ()
  156. if (${LS_STD_BUILD_MODULE})
  157. add_library("${PROJECT_NAME}_${PROJECT_VERSION}_module" MODULE ${SOURCE_FILES})
  158. set_target_properties("${PROJECT_NAME}_${PROJECT_VERSION}_module" PROPERTIES DEBUG_POSTFIX "_d")
  159. endif ()
  160. ##########################################################
  161. # Linking
  162. ##########################################################
  163. if (${LS_STD_BUILD_WITH_TESTS})
  164. message("${PROJECT_NAME}: Linking libraries for test application...")
  165. target_link_libraries(${PROJECT_NAME}_test gtest gtest_main "${PROJECT_NAME}_${PROJECT_VERSION}_static")
  166. endif ()