CMakeLists.txt 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. cmake_minimum_required(VERSION 3.12)
  2. project(squirrel
  3. VERSION 3.2
  4. DESCRIPTION "The Squirrel programming language"
  5. HOMEPAGE_URL "http://squirrel-lang.org/"
  6. LANGUAGES C CXX
  7. )
  8. option(DISABLE_STATIC "Avoid building/installing static libraries.")
  9. option(LONG_OUTPUT_NAMES "Use longer names for binaries and libraries: squirrel3 (not sq).")
  10. if (NOT CMAKE_BUILD_TYPE)
  11. set(CMAKE_BUILD_TYPE "Release")
  12. endif ()
  13. include(GNUInstallDirs)
  14. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_BINDIR}")
  15. set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
  16. set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")
  17. set(CMAKE_CXX_STANDARD 11)
  18. if(CMAKE_COMPILER_IS_GNUCXX)
  19. add_compile_options(
  20. "$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti;-fno-exceptions>"
  21. -fno-strict-aliasing
  22. -Wall
  23. -Wextra
  24. -pedantic
  25. -Wcast-qual
  26. "$<$<CONFIG:Release>:-O3>"
  27. "$<$<CONFIG:RelWithDebInfo>:-O3;-g>"
  28. "$<$<CONFIG:MinSizeRel>:-Os>"
  29. "$<$<CONFIG:Debug>:-pie;-gstabs;-g3;-Og>"
  30. )
  31. elseif(MSVC)
  32. set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
  33. add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  34. endif()
  35. # Need to be defined here to be visible to squirrel.pc.in
  36. if(LONG_OUTPUT_NAMES)
  37. set(LIBSQUIRREL_NAME squirrel3)
  38. set(SQSTDLIB_NAME sqstdlib3)
  39. else()
  40. set(LIBSQUIRREL_NAME squirrel)
  41. set(SQSTDLIB_NAME sqstdlib)
  42. endif()
  43. add_subdirectory(squirrel)
  44. add_subdirectory(sqstdlib)
  45. if(NOT SQ_DISABLE_INTERPRETER)
  46. add_subdirectory(sq)
  47. endif()
  48. if(CMAKE_SIZEOF_VOID_P EQUAL 8)
  49. set(tgts)
  50. if(NOT DISABLE_DYNAMIC)
  51. list(APPEND tgts squirrel sqstdlib)
  52. if(NOT SQ_DISABLE_INTERPRETER)
  53. list(APPEND tgts sq)
  54. endif()
  55. endif()
  56. if(NOT DISABLE_STATIC)
  57. list(APPEND tgts squirrel_static sqstdlib_static)
  58. if(NOT SQ_DISABLE_INTERPRETER)
  59. list(APPEND tgts sq_static)
  60. endif()
  61. endif()
  62. foreach(t ${tgts})
  63. target_compile_definitions(${t} PUBLIC -D_SQ64)
  64. endforeach()
  65. endif()
  66. if(NOT DISABLE_DYNAMIC)
  67. set_target_properties(squirrel sqstdlib PROPERTIES SOVERSION 0 VERSION 0.0.0)
  68. endif()
  69. if(NOT SQ_DISABLE_INSTALLER AND NOT SQ_DISABLE_HEADER_INSTALLER)
  70. install(FILES
  71. include/sqconfig.h
  72. include/squirrel.h
  73. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  74. COMPONENT Development
  75. )
  76. install(FILES
  77. include/sqstdaux.h
  78. include/sqstdblob.h
  79. include/sqstdio.h
  80. include/sqstdmath.h
  81. include/sqstdstring.h
  82. include/sqstdsystem.h
  83. DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  84. COMPONENT Development
  85. )
  86. endif()
  87. include(CMakePackageConfigHelpers)
  88. write_basic_package_version_file(
  89. "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/squirrel/squirrel-config-version.cmake"
  90. VERSION "${squirrel_VERSION}"
  91. COMPATIBILITY AnyNewerVersion
  92. )
  93. configure_package_config_file(
  94. "${CMAKE_CURRENT_SOURCE_DIR}/squirrel-config.cmake.in"
  95. "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/squirrel/squirrel-config.cmake"
  96. INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/squirrel"
  97. )
  98. configure_file(
  99. "${CMAKE_CURRENT_SOURCE_DIR}/squirrel.pc.in"
  100. ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
  101. @ONLY
  102. )
  103. if(NOT SQ_DISABLE_INSTALLER AND NOT SQ_DISABLE_CMAKE_INSTALLER)
  104. export(EXPORT squirrel
  105. NAMESPACE squirrel::
  106. FILE "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/squirrel/squirrel-targets.cmake"
  107. )
  108. install(FILES
  109. "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/squirrel/squirrel-config-version.cmake"
  110. "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/cmake/squirrel/squirrel-config.cmake"
  111. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/squirrel"
  112. COMPONENT Development
  113. )
  114. # pc(5) only allows static variant to have extra flags, not an entirely new
  115. # set of flags. While it's uncommon, a way to do it would be to generate a
  116. # ${PROJECT_NAME}_static.pc file.
  117. if(NOT DISABLE_DYNAMIC)
  118. install(
  119. FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
  120. DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
  121. COMPONENT Development
  122. )
  123. endif()
  124. install(EXPORT squirrel
  125. NAMESPACE squirrel::
  126. DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/squirrel"
  127. FILE "squirrel-targets.cmake"
  128. COMPONENT Development
  129. )
  130. endif()