package compiler and linker metadata toolkit

CMakeLists.txt 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. # CMake configuration for pkgconf
  2. #
  3. # Caution: this assumes you don't set CMAKE_BUILD_TYPE
  4. #
  5. # FIXME: this isn't a native cmake approach, it's just a straight translation
  6. # of configure.ac + Makefile.am, barely good enough to work on Linux, Mac, and Windows.
  7. # Require recent cmake, but not so recent that Ubuntu 16.04 users have to upgrade.
  8. CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1 FATAL_ERROR)
  9. PROJECT(pkgconf C)
  10. SET(PACKAGE_BUGREPORT http://github.com/pkgconf/pkgconf/issues)
  11. SET(PACKAGE_NAME pkgconf)
  12. SET(PACKAGE_VERSION 1.3.7)
  13. SET(LIBPKGCONF_VERSION "3.0.0")
  14. SET(LIBPKGCONF_SOVERSION 3)
  15. #-------- GNU directory variables ---------
  16. SET(abs_top_srcdir ${pkgconf_SOURCE_DIR})
  17. SET(prefix ${CMAKE_INSTALL_PREFIX})
  18. SET(exec_prefix ${prefix})
  19. SET(datarootdir ${prefix}/share)
  20. SET(datadir ${datarootdir})
  21. SET(libdir ${prefix}/lib)
  22. SET(includedir ${prefix}/include)
  23. #-------- User-settable options ---------
  24. # FIXME: this is overridden in get_default_pkgconfig_path() on windows, but not in test_env.sh.in?!
  25. SET(pkg_config_dir "${libdir}/pkgconfig:${datadir}/pkgconfig" CACHE STRING "specify the places where pc files will be found")
  26. SET(PKGCONFIGDIR "${pkg_config_dir}")
  27. SET(pkg_default_dir "${PKGCONFIGDIR}") # c'mon, make up your mind
  28. SET(personality_dir "${libdir}/pkgconfig/personality.d:${datadir}/pkgconfig/personality.d" CACHE STRING "specify the places where personality files will be found")
  29. SET(system_libdir "${libdir}" CACHE STRING "specify the system library directory (default LIBDIR)")
  30. SET(SYSTEM_LIBDIR "${system_libdir}")
  31. SET(system_includedir "${includedir}" CACHE STRING "specify the system include directory (default INCLUDEDIR)")
  32. SET(SYSTEM_INCLUDEDIR "${system_includedir}")
  33. #-------- Probe system ---------
  34. INCLUDE (CheckIncludeFiles)
  35. CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
  36. INCLUDE (CheckFunctionExists)
  37. CHECK_FUNCTION_EXISTS(strlcpy HAVE_STRLCPY)
  38. CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
  39. CHECK_FUNCTION_EXISTS(strndup HAVE_STRNDUP)
  40. CHECK_FUNCTION_EXISTS(cygwin_conv_path HAVE_CYGWIN_CONV_PATH)
  41. #-------- Generate source files ---------
  42. CONFIGURE_FILE(libpkgconf/config.h.cmake.in libpkgconf/config.h @ONLY)
  43. #-------- Configure common compiler options --------
  44. IF (MSVC)
  45. # Make warnings fatal... but ignore C4996: 'strdup' two different ways
  46. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4996")
  47. # Ignore warning C4996: 'strncpy'
  48. ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS=1")
  49. ELSE()
  50. INCLUDE(CheckCCompilerFlag)
  51. CHECK_C_COMPILER_FLAG("-Wall" COMPILER_HAS_WALL)
  52. IF (COMPILER_HAS_WALL)
  53. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
  54. ENDIF()
  55. CHECK_C_COMPILER_FLAG("-Wextra" COMPILER_HAS_WEXTRA)
  56. IF (COMPILER_HAS_WEXTRA)
  57. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
  58. ENDIF()
  59. CHECK_C_COMPILER_FLAG("-Wformat=2" COMPILER_HAS_WFORMAT)
  60. IF (COMPILER_HAS_WFORMAT)
  61. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2")
  62. ENDIF()
  63. CHECK_C_COMPILER_FLAG("-std=gnu99" COMPILER_HAS_STD_GNU99)
  64. CHECK_C_COMPILER_FLAG("-std=c99" COMPILER_HAS_STD_C99)
  65. IF (COMPILER_HAS_STD_GNU99)
  66. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
  67. ELSEIF (COMPILER_HAS_STD_C99)
  68. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
  69. ENDIF()
  70. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g")
  71. ENDIF()
  72. INCLUDE_DIRECTORIES(${pkgconf_SOURCE_DIR} ${pkgconf_BINARY_DIR})
  73. ADD_DEFINITIONS(-DPERSONALITY_PATH=\"${personality_dir}\")
  74. ADD_DEFINITIONS(-DPKG_DEFAULT_PATH=\"${pkg_default_dir}\")
  75. ADD_DEFINITIONS(-DSYSTEM_INCLUDEDIR=\"${system_includedir}\")
  76. ADD_DEFINITIONS(-DSYSTEM_LIBDIR=\"${system_libdir}\")
  77. #-------- Build and install library --------
  78. # Place shared libraries in same place as binary, for ease of setting PATH in test_env.sh
  79. set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${pkgconf_BINARY_DIR})
  80. ADD_SUBDIRECTORY(libpkgconf)
  81. #-------- Build and install executable --------
  82. INCLUDE_DIRECTORIES(${libpkgconf_BINARY_DIR})
  83. SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Icli")
  84. ADD_EXECUTABLE(pkgconf cli/main.c cli/getopt_long.c cli/renderer-msvc.c)
  85. TARGET_LINK_LIBRARIES(pkgconf libpkgconf)
  86. INSTALL(TARGETS pkgconf DESTINATION bin)
  87. #-------- Tests ---------
  88. ENABLE_TESTING()
  89. # Handy that these files need configuring; cygwin atf doesn't like windows line endings, and NEWLINE_STYLE helps.
  90. FOREACH(file Kyuafile tests/Kyuafile tests/test_env.sh)
  91. CONFIGURE_FILE(${file}.in ${file} @ONLY NEWLINE_STYLE UNIX)
  92. ENDFOREACH()
  93. SET(test_scripts
  94. tests/basic
  95. tests/builtins
  96. tests/conflicts
  97. tests/framework
  98. tests/parser
  99. tests/provides
  100. tests/regress
  101. tests/requires
  102. tests/sysroot
  103. tests/version
  104. )
  105. # Handy that these files need configuring; cygwin atf doesn't like windows line endings, and NEWLINE_STYLE helps.
  106. FOREACH(file ${test_scripts})
  107. CONFIGURE_FILE(${file}.sh ${file} @ONLY NEWLINE_STYLE UNIX)
  108. ENDFOREACH()
  109. ADD_TEST(kyua kyua --config=none test)