Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 3.38 KB | None | 0 0
  1. cmake_minimum_required (VERSION 2.6)
  2. project (contactbook)
  3. set(CMAKE_BUILD_TYPE Debug)
  4. #set(CMAKE_VERBOSE_MAKEFILE on)
  5. set(CMAKE_C_STANDARD 99)
  6. set (CMAKE_C_FLAGS "--std=gnu99 ${CMAKE_C_FLAGS}")
  7. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  8. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
  9. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
  10.  
  11. include_directories(contactbook include)
  12.  
  13. #libraries
  14. add_library(contact-static STATIC lib/contact.c)
  15. add_library(contact-shared SHARED lib/contact.c)
  16.  
  17. add_executable(contactbook src/main.c)
  18. target_link_libraries(contactbook contact-static)
  19.  
  20. add_executable(contactbook-static src/main.c)
  21. target_link_libraries(contactbook-static contact-static)
  22. add_dependencies(contactbook-static contact-static)
  23.  
  24. add_executable(contactbook-shared src/main.c)
  25. add_dependencies(contactbook-shared contact-shared)
  26. target_link_libraries(contactbook-shared contact-shared)
  27.  
  28. add_executable(contactbook-dynamic src/main.c)
  29. target_link_libraries(contactbook-dynamic contact-shared)
  30. target_compile_definitions(contactbook-dynamic PRIVATE DYNLIB=true)
  31. target_compile_options(contactbook-dynamic PRIVATE -rdynamic)
  32. target_link_libraries(contactbook-dynamic dl)
  33.  
  34. add_definitions("-Wall")
  35. install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
  36.  
  37. #test
  38. add_custom_target(
  39.         tests
  40.         COMMAND sh ./test-runner.sh
  41.         DEPENDS contactbook-static contactbook-shared contactbook-dynamic
  42. )
  43.  
  44. #optimization levels
  45. add_library(contact-O0 STATIC EXCLUDE_FROM_ALL lib/contact.c)
  46. add_library(contact-O1 STATIC EXCLUDE_FROM_ALL lib/contact.c)
  47. add_library(contact-O2 STATIC EXCLUDE_FROM_ALL lib/contact.c)
  48. add_library(contact-O3 STATIC EXCLUDE_FROM_ALL lib/contact.c)
  49. add_library(contact-Os STATIC EXCLUDE_FROM_ALL lib/contact.c)
  50. target_compile_options(contact-O0 PRIVATE "-O0")
  51. target_compile_options(contact-O1 PRIVATE "-O1")
  52. target_compile_options(contact-O2 PRIVATE "-O2")
  53. target_compile_options(contact-O3 PRIVATE "-O3")
  54. target_compile_options(contact-Os PRIVATE "-Os")
  55. add_executable(contactbook-O0 EXCLUDE_FROM_ALL src/main.c)
  56. add_executable(contactbook-O1 EXCLUDE_FROM_ALL src/main.c)
  57. add_executable(contactbook-O2 EXCLUDE_FROM_ALL src/main.c)
  58. add_executable(contactbook-O3 EXCLUDE_FROM_ALL src/main.c)
  59. add_executable(contactbook-Os EXCLUDE_FROM_ALL src/main.c)
  60. target_link_libraries(contactbook-O0 contact-O0)
  61. target_link_libraries(contactbook-O1 contact-O1)
  62. target_link_libraries(contactbook-O2 contact-O2)
  63. target_link_libraries(contactbook-O3 contact-O3)
  64. target_link_libraries(contactbook-Os contact-Os)
  65. target_compile_options(contactbook-O0 PRIVATE "-O0")
  66. target_compile_options(contactbook-O1 PRIVATE "-O1")
  67. target_compile_options(contactbook-O2 PRIVATE "-O2")
  68. target_compile_options(contactbook-O3 PRIVATE "-O3")
  69. target_compile_options(contactbook-Os PRIVATE "-Os")
  70.  
  71. add_custom_target(
  72.         optimizations
  73.         DEPENDS contactbook-O0 contactbook-O1 contactbook-O2 contactbook-O3 contactbook-Os
  74. )
  75. add_custom_target(
  76.         optimization-tests
  77.         COMMAND sh ./optimization-test-runner.sh
  78.         DEPENDS optimizations
  79. )
  80.  
  81. #purpose-bugged build
  82. add_library(contact-bugged STATIC EXCLUDE_FROM_ALL lib/contact.c)
  83. add_executable(contactbook-bugged EXCLUDE_FROM_ALL src/main.c)
  84. target_compile_definitions(contactbook-bugged PRIVATE BUGGED=true)
  85. target_link_libraries(contactbook-bugged contact-bugged)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement