You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 11 kB

9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. #Licensed under the MIT license. See LICENSE file in the project root for full license information.
  2. cmake_minimum_required(VERSION 2.8.7)
  3. cmake_policy(SET CMP0048 NEW)
  4. project(json-c VERSION 0.13.1)
  5. include(CheckSymbolExists)
  6. check_symbol_exists(strtoll "stdlib.h" HAVE_STRTOLL)
  7. set(cmake_strtoll "strtoll")
  8. if (NOT HAVE_STRTOLL)
  9. # Use _strtoi64 if strtoll is not available.
  10. check_symbol_exists(_strtoi64 stdlib.h have_strtoi64)
  11. if (have_strtoi64)
  12. set(HAVE_STRTOLL 1)
  13. set(cmake_strtoll "_strtoi64")
  14. # could do the same for strtoull, if needed
  15. endif ()
  16. endif ()
  17. if(MSVC)
  18. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4100 /wd4996 /wd4244 /wd4706 /wd4702 /wd4127 /wd4701")
  19. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4100 /wd4996 /wd4244 /wd4706 /wd4702 /wd4127 /wd4701")
  20. set(cmake_create_config 1)
  21. elseif(MINGW)
  22. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -D_GNU_SOURCE=1")
  23. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -D_GNU_SOURCE=1")
  24. if (MSYS OR CMAKE_GENERATOR STREQUAL "Unix Makefiles")
  25. execute_process(COMMAND echo ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  26. execute_process(COMMAND sh autogen.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  27. execute_process(COMMAND sh ./configure WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  28. file(COPY ./config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/)
  29. file(COPY ./json_config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/)
  30. else()
  31. set(cmake_create_config 1)
  32. endif()
  33. elseif(UNIX)
  34. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
  35. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -D_GNU_SOURCE")
  36. execute_process(COMMAND echo ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  37. execute_process(COMMAND sh autogen.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  38. execute_process(COMMAND ./configure WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
  39. file(COPY ./config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/)
  40. file(COPY ./json_config.h DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/)
  41. endif()
  42. if (cmake_create_config)
  43. file(REMOVE ./config.h) # make sure any stale one is gone
  44. configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
  45. file(COPY ./json_config.h.win32 DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/include/)
  46. file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h.win32 ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h)
  47. endif ()
  48. include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
  49. set(JSON_C_PUBLIC_HEADERS
  50. ./json.h
  51. ${CMAKE_CURRENT_BINARY_DIR}/include/config.h
  52. ${CMAKE_CURRENT_BINARY_DIR}/include/json_config.h
  53. ./arraylist.h
  54. ./debug.h
  55. ./json_c_version.h
  56. ./json_inttypes.h
  57. ./json_object.h
  58. ./json_object_iterator.h
  59. ./json_pointer.h
  60. ./json_tokener.h
  61. ./json_util.h
  62. ./linkhash.h
  63. ./printbuf.h
  64. )
  65. set(JSON_C_HEADERS
  66. ${JSON_C_PUBLIC_HEADERS}
  67. ./json_object_private.h
  68. ./random_seed.h
  69. ./strerror_override.h
  70. ./strerror_override_private.h
  71. ./math_compat.h
  72. ./snprintf_compat.h
  73. ./strdup_compat.h
  74. ./vasprintf_compat.h
  75. )
  76. set(JSON_C_SOURCES
  77. ./arraylist.c
  78. ./debug.c
  79. ./json_c_version.c
  80. ./json_object.c
  81. ./json_object_iterator.c
  82. ./json_pointer.c
  83. ./json_tokener.c
  84. ./json_util.c
  85. ./json_visit.c
  86. ./linkhash.c
  87. ./printbuf.c
  88. ./random_seed.c
  89. ./strerror_override.c
  90. )
  91. add_library(json-c
  92. SHARED
  93. ${JSON_C_SOURCES}
  94. ${JSON_C_HEADERS}
  95. )
  96. add_library(json-c-static
  97. STATIC
  98. ${JSON_C_SOURCES}
  99. ${JSON_C_HEADERS}
  100. )
  101. set_property(TARGET json-c PROPERTY C_STANDARD 99)
  102. set_property(TARGET json-c-static PROPERTY C_STANDARD 99)
  103. set_target_properties(json-c-static PROPERTIES OUTPUT_NAME json-c)
  104. install(TARGETS json-c json-c-static
  105. RUNTIME DESTINATION bin
  106. LIBRARY DESTINATION lib
  107. ARCHIVE DESTINATION lib
  108. )
  109. install(FILES ${JSON_C_PUBLIC_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/json-c )
  110. if (UNIX)
  111. set(prefix ${CMAKE_INSTALL_PREFIX})
  112. set(exec_prefix ${CMAKE_INSTALL_PREFIX}/bin)
  113. set(libdir ${CMAKE_INSTALL_PREFIX}/lib)
  114. set(includedir ${CMAKE_INSTALL_PREFIX}/include)
  115. set(VERSION ${PROJECT_VERSION})
  116. configure_file(json-c.pc.in json-c.pc @ONLY)
  117. set(INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig" CACHE PATH "Installation directory for pkgconfig (.pc) files")
  118. install(FILES ${CMAKE_BINARY_DIR}/json-c.pc DESTINATION "${INSTALL_PKGCONFIG_DIR}")
  119. endif ()
  120. # ------------------------- Begin Generic CMake Variable Logging ------------------
  121. # if you are building in-source, this is the same as CMAKE_SOURCE_DIR, otherwise
  122. # this is the top level directory of your build tree
  123. MESSAGE( STATUS "CMAKE_BINARY_DIR: " ${CMAKE_BINARY_DIR} )
  124. # if you are building in-source, this is the same as CMAKE_CURRENT_SOURCE_DIR, otherwise this
  125. # is the directory where the compiled or generated files from the current CMakeLists.txt will go to
  126. MESSAGE( STATUS "CMAKE_CURRENT_BINARY_DIR: " ${CMAKE_CURRENT_BINARY_DIR} )
  127. # this is the directory, from which cmake was started, i.e. the top level source directory
  128. MESSAGE( STATUS "CMAKE_SOURCE_DIR: " ${CMAKE_SOURCE_DIR} )
  129. # this is the directory where the currently processed CMakeLists.txt is located in
  130. MESSAGE( STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR} )
  131. # contains the full path to the top level directory of your build tree
  132. MESSAGE( STATUS "PROJECT_BINARY_DIR: " ${PROJECT_BINARY_DIR} )
  133. # contains the full path to the root of your project source directory,
  134. # i.e. to the nearest directory where CMakeLists.txt contains the PROJECT() command
  135. MESSAGE( STATUS "PROJECT_SOURCE_DIR: " ${PROJECT_SOURCE_DIR} )
  136. # set this variable to specify a common place where CMake should put all executable files
  137. # (instead of CMAKE_CURRENT_BINARY_DIR)
  138. MESSAGE( STATUS "EXECUTABLE_OUTPUT_PATH: " ${EXECUTABLE_OUTPUT_PATH} )
  139. # set this variable to specify a common place where CMake should put all libraries
  140. # (instead of CMAKE_CURRENT_BINARY_DIR)
  141. MESSAGE( STATUS "LIBRARY_OUTPUT_PATH: " ${LIBRARY_OUTPUT_PATH} )
  142. # tell CMake to search first in directories listed in CMAKE_MODULE_PATH
  143. # when you use FIND_PACKAGE() or INCLUDE()
  144. MESSAGE( STATUS "CMAKE_MODULE_PATH: " ${CMAKE_MODULE_PATH} )
  145. # this is the complete path of the cmake which runs currently (e.g. /usr/local/bin/cmake)
  146. MESSAGE( STATUS "CMAKE_COMMAND: " ${CMAKE_COMMAND} )
  147. # this is the CMake installation directory
  148. MESSAGE( STATUS "CMAKE_ROOT: " ${CMAKE_ROOT} )
  149. # this is the filename including the complete path of the file where this variable is used.
  150. MESSAGE( STATUS "CMAKE_CURRENT_LIST_FILE: " ${CMAKE_CURRENT_LIST_FILE} )
  151. # this is linenumber where the variable is used
  152. MESSAGE( STATUS "CMAKE_CURRENT_LIST_LINE: " ${CMAKE_CURRENT_LIST_LINE} )
  153. # this is used when searching for include files e.g. using the FIND_PATH() command.
  154. MESSAGE( STATUS "CMAKE_INCLUDE_PATH: " ${CMAKE_INCLUDE_PATH} )
  155. # this is used when searching for libraries e.g. using the FIND_LIBRARY() command.
  156. MESSAGE( STATUS "CMAKE_LIBRARY_PATH: " ${CMAKE_LIBRARY_PATH} )
  157. # the complete system name, e.g. "Linux-2.4.22", "FreeBSD-5.4-RELEASE" or "Windows 5.1"
  158. MESSAGE( STATUS "CMAKE_SYSTEM: " ${CMAKE_SYSTEM} )
  159. # the short system name, e.g. "Linux", "FreeBSD" or "Windows"
  160. MESSAGE( STATUS "CMAKE_SYSTEM_NAME: " ${CMAKE_SYSTEM_NAME} )
  161. # only the version part of CMAKE_SYSTEM
  162. MESSAGE( STATUS "CMAKE_SYSTEM_VERSION: " ${CMAKE_SYSTEM_VERSION} )
  163. # the processor name (e.g. "Intel(R) Pentium(R) M processor 2.00GHz")
  164. MESSAGE( STATUS "CMAKE_SYSTEM_PROCESSOR: " ${CMAKE_SYSTEM_PROCESSOR} )
  165. # is TRUE on all UNIX-like OS's, including Apple OS X and CygWin
  166. MESSAGE( STATUS "UNIX: " ${UNIX} )
  167. # is TRUE on Windows, including CygWin
  168. MESSAGE( STATUS "WIN32: " ${WIN32} )
  169. # is TRUE on Apple OS X
  170. MESSAGE( STATUS "APPLE: " ${APPLE} )
  171. # is TRUE when using the MinGW compiler in Windows
  172. MESSAGE( STATUS "MINGW: " ${MINGW} )
  173. # is TRUE on Windows when using the CygWin version of cmake
  174. MESSAGE( STATUS "CYGWIN: " ${CYGWIN} )
  175. # is TRUE on Windows when using a Borland compiler
  176. MESSAGE( STATUS "BORLAND: " ${BORLAND} )
  177. # Microsoft compiler
  178. MESSAGE( STATUS "MSVC: " ${MSVC} )
  179. MESSAGE( STATUS "MSVC_IDE: " ${MSVC_IDE} )
  180. MESSAGE( STATUS "MSVC60: " ${MSVC60} )
  181. MESSAGE( STATUS "MSVC70: " ${MSVC70} )
  182. MESSAGE( STATUS "MSVC71: " ${MSVC71} )
  183. MESSAGE( STATUS "MSVC80: " ${MSVC80} )
  184. MESSAGE( STATUS "CMAKE_COMPILER_2005: " ${CMAKE_COMPILER_2005} )
  185. # set this to true if you don't want to rebuild the object files if the rules have changed,
  186. # but not the actual source files or headers (e.g. if you changed the some compiler switches)
  187. MESSAGE( STATUS "CMAKE_SKIP_RULE_DEPENDENCY: " ${CMAKE_SKIP_RULE_DEPENDENCY} )
  188. # since CMake 2.1 the install rule depends on all, i.e. everything will be built before installing.
  189. # If you don't like this, set this one to true.
  190. MESSAGE( STATUS "CMAKE_SKIP_INSTALL_ALL_DEPENDENCY: " ${CMAKE_SKIP_INSTALL_ALL_DEPENDENCY} )
  191. # If set, runtime paths are not added when using shared libraries. Default it is set to OFF
  192. MESSAGE( STATUS "CMAKE_SKIP_RPATH: " ${CMAKE_SKIP_RPATH} )
  193. # set this to true if you are using makefiles and want to see the full compile and link
  194. # commands instead of only the shortened ones
  195. MESSAGE( STATUS "CMAKE_VERBOSE_MAKEFILE: " ${CMAKE_VERBOSE_MAKEFILE} )
  196. # this will cause CMake to not put in the rules that re-run CMake. This might be useful if
  197. # you want to use the generated build files on another machine.
  198. MESSAGE( STATUS "CMAKE_SUPPRESS_REGENERATION: " ${CMAKE_SUPPRESS_REGENERATION} )
  199. # A simple way to get switches to the compiler is to use ADD_DEFINITIONS().
  200. # But there are also two variables exactly for this purpose:
  201. # the compiler flags for compiling C sources
  202. MESSAGE( STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS} )
  203. # the compiler flags for compiling C++ sources
  204. MESSAGE( STATUS "CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} )
  205. # Choose the type of build. Example: SET(CMAKE_BUILD_TYPE Debug)
  206. MESSAGE( STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE} )
  207. # if this is set to ON, then all libraries are built as shared libraries by default.
  208. MESSAGE( STATUS "BUILD_SHARED_LIBS: " ${BUILD_SHARED_LIBS} )
  209. # the compiler used for C files
  210. MESSAGE( STATUS "CMAKE_C_COMPILER: " ${CMAKE_C_COMPILER} )
  211. # the compiler used for C++ files
  212. MESSAGE( STATUS "CMAKE_CXX_COMPILER: " ${CMAKE_CXX_COMPILER} )
  213. # if the compiler is a variant of gcc, this should be set to 1
  214. MESSAGE( STATUS "CMAKE_COMPILER_IS_GNUCC: " ${CMAKE_COMPILER_IS_GNUCC} )
  215. # if the compiler is a variant of g++, this should be set to 1
  216. MESSAGE( STATUS "CMAKE_COMPILER_IS_GNUCXX : " ${CMAKE_COMPILER_IS_GNUCXX} )
  217. # the tools for creating libraries
  218. MESSAGE( STATUS "CMAKE_AR: " ${CMAKE_AR} )
  219. MESSAGE( STATUS "CMAKE_RANLIB: " ${CMAKE_RANLIB} )
  220. #
  221. #MESSAGE( STATUS ": " ${} )
  222. # ------------------------- End of Generic CMake Variable Logging ------------------