CMakeLists.txt__static_build 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. cmake_minimum_required(VERSION 3.0)
  2. project(ex1
  3. VERSION 0.1
  4. LANGUAGES CXX)
  5. ###########
  6. # Debug or Release
  7. ###########
  8. if (NOT CMAKE_BUILD_TYPE)
  9. ## set default to Debug
  10. set(CMAKE_BUILD_TYPE RelWithDebInfo) # override with -DCMAKE_BUILD_TYPE=Release
  11. message("==> CMAKE_BUILD_TYPE empty. Changing it to Debug.")
  12. else()
  13. message("==> CMAKE_BUILD_TYPE == ${CMAKE_BUILD_TYPE}.")
  14. endif()
  15. ## set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -DGLIBCXX_FORCE_NEW")
  16. ## https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_macros.html
  17. ## During Debug, use debug version of libstdc++ (asserts on access to invalid iterators, etc!)
  18. ## set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
  19. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG")
  20. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
  21. ##############
  22. # C++ Standard
  23. ##############
  24. # set(CMAKE_CXX_STANDARD 14)
  25. # C++17 gives me transform
  26. set(CMAKE_CXX_STANDARD 17)
  27. set(CMAKE_CXX_EXTENSIONS ON)
  28. # The old fix for getting logging to work/link properly.
  29. # ADD_DEFINITIONS(-DBOOST_LOG_DYN_LINK)
  30. # This seems to work for static linking the boost libraries
  31. set(Boost_USE_STATIC_LIBS ON)
  32. # add log_setup log
  33. FIND_PACKAGE( Boost 1.71 COMPONENTS program_options log_setup log REQUIRED )
  34. INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
  35. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/yaml-cpp)
  36. message("***")
  37. message("*** ERROR/MISSING *** please run: git clone https://github.com/jbeder/yaml-cpp.git --depth 1")
  38. message("***")
  39. endif()
  40. add_subdirectory(yaml-cpp)
  41. if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/googletest)
  42. message("***")
  43. message("*** ERROR/MISSING *** please run: git clone https://github.com/google/googletest.git --depth 1")
  44. message("***")
  45. endif()
  46. add_subdirectory(googletest)
  47. option(gtest_build_samples "Build gtest's sample programs." OFF)
  48. option(gtest_disable_pthreads "Disable uses of pthreads in gtest." OFF)
  49. ### TESTS
  50. add_executable(test-galaxy test-galaxy.cpp galaxy.cpp config.cpp utils.cpp buysell.cpp)
  51. add_dependencies(test-galaxy gtest)
  52. target_link_libraries(test-galaxy gtest_main ${Boost_LIBRARIES} yaml-cpp)
  53. add_executable(test-director test-director.cpp galaxy.cpp utils.cpp buysell.cpp director.cpp dispatchers.cpp boxes.cpp scripts.cpp config.cpp)
  54. add_dependencies(test-director gtest)
  55. target_link_libraries(test-director gtest_main ${Boost_LIBRARIES} yaml-cpp)
  56. enable_testing()
  57. add_test(NAME test-galaxy
  58. COMMAND test-galaxy)
  59. add_test(NAME test-director
  60. COMMAND test-director)
  61. # dispatchers.cpp
  62. ADD_EXECUTABLE( twproxy twproxy.cpp utils.cpp session.cpp boxes.cpp director.cpp galaxy.cpp dispatchers.cpp scripts.cpp buysell.cpp config.cpp)
  63. #Static start
  64. set_target_properties(twproxy PROPERTIES LINK_SEARCH_START_STATIC 1)
  65. set_target_properties(twproxy PROPERTIES LINK_SEARCH_END_STATIC 1)
  66. set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
  67. #Static Libs
  68. #Set Linker flags
  69. set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
  70. TARGET_LINK_LIBRARIES( twproxy -static ${Boost_LIBRARIES} pthread.a yaml-cpp)
  71. # target_link_libraries(test -static)
  72. # private does nothing here
  73. # TARGET_LINK_LIBRARIES( twproxy PRIVATE ${Boost_LIBRARIES} pthread yaml-cpp)
  74. target_precompile_headers(twproxy PRIVATE pch.hpp)