pkgconf/CMakeLists.txt

136 lines
4.7 KiB
CMake
Raw Normal View History

2017-06-06 03:54:57 +00:00
# CMake configuration for pkgconf
#
# Caution: this assumes you don't set CMAKE_BUILD_TYPE
#
# FIXME: this isn't a native cmake approach, it's just a straight translation
# of configure.ac + Makefile.am, barely good enough to work on Linux, Mac, and Windows.
# Require recent cmake, but not so recent that Ubuntu 16.04 users have to upgrade.
CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1 FATAL_ERROR)
2017-06-04 22:17:51 +00:00
PROJECT(pkgconf C)
SET(PACKAGE_BUGREPORT http://github.com/pkgconf/pkgconf/issues)
SET(PACKAGE_NAME pkgconf)
2019-01-14 20:12:32 +00:00
SET(PACKAGE_VERSION 1.6.0)
2018-01-05 17:18:19 +00:00
SET(LIBPKGCONF_VERSION "3.0.0")
SET(LIBPKGCONF_SOVERSION 3)
2017-06-06 03:54:57 +00:00
#-------- GNU directory variables ---------
SET(abs_top_srcdir ${pkgconf_SOURCE_DIR})
SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(exec_prefix ${prefix})
SET(datarootdir ${prefix}/share)
SET(datadir ${datarootdir})
SET(libdir ${prefix}/lib)
SET(includedir ${prefix}/include)
#-------- User-settable options ---------
# FIXME: this is overridden in get_default_pkgconfig_path() on windows, but not in test_env.sh.in?!
SET(pkg_config_dir "${libdir}/pkgconfig:${datadir}/pkgconfig" CACHE STRING "specify the places where pc files will be found")
SET(PKGCONFIGDIR "${pkg_config_dir}")
SET(pkg_default_dir "${PKGCONFIGDIR}") # c'mon, make up your mind
2018-06-14 19:45:33 +00:00
SET(personality_dir "${libdir}/pkgconfig/personality.d:${datadir}/pkgconfig/personality.d" CACHE STRING "specify the places where personality files will be found")
2017-06-06 03:54:57 +00:00
SET(system_libdir "${libdir}" CACHE STRING "specify the system library directory (default LIBDIR)")
SET(SYSTEM_LIBDIR "${system_libdir}")
SET(system_includedir "${includedir}" CACHE STRING "specify the system include directory (default INCLUDEDIR)")
SET(SYSTEM_INCLUDEDIR "${system_includedir}")
#-------- Probe system ---------
2017-06-04 22:17:51 +00:00
INCLUDE (CheckIncludeFiles)
CHECK_INCLUDE_FILES(sys/stat.h HAVE_SYS_STAT_H)
INCLUDE (CheckFunctionExists)
CHECK_FUNCTION_EXISTS(strlcpy HAVE_STRLCPY)
CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
CHECK_FUNCTION_EXISTS(strndup HAVE_STRNDUP)
CHECK_FUNCTION_EXISTS(cygwin_conv_path HAVE_CYGWIN_CONV_PATH)
2017-06-06 03:54:57 +00:00
#-------- Generate source files ---------
2017-06-04 22:17:51 +00:00
CONFIGURE_FILE(libpkgconf/config.h.cmake.in libpkgconf/config.h @ONLY)
2017-06-06 03:54:57 +00:00
#-------- Configure common compiler options --------
2017-06-04 22:17:51 +00:00
IF (MSVC)
# Make warnings fatal... but ignore C4996: 'strdup' two different ways
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX /wd4996")
# Ignore warning C4996: 'strncpy'
ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS=1")
2017-06-04 22:17:51 +00:00
ELSE()
INCLUDE(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-Wall" COMPILER_HAS_WALL)
IF (COMPILER_HAS_WALL)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
ENDIF()
CHECK_C_COMPILER_FLAG("-Wextra" COMPILER_HAS_WEXTRA)
IF (COMPILER_HAS_WEXTRA)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wextra")
ENDIF()
CHECK_C_COMPILER_FLAG("-Wformat=2" COMPILER_HAS_WFORMAT)
IF (COMPILER_HAS_WFORMAT)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat=2")
ENDIF()
CHECK_C_COMPILER_FLAG("-std=gnu99" COMPILER_HAS_STD_GNU99)
CHECK_C_COMPILER_FLAG("-std=c99" COMPILER_HAS_STD_C99)
IF (COMPILER_HAS_STD_GNU99)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
ELSEIF (COMPILER_HAS_STD_C99)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
ENDIF()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2 -g")
2017-06-04 22:17:51 +00:00
ENDIF()
INCLUDE_DIRECTORIES(${pkgconf_SOURCE_DIR} ${pkgconf_BINARY_DIR})
2018-06-14 19:45:33 +00:00
ADD_DEFINITIONS(-DPERSONALITY_PATH=\"${personality_dir}\")
2017-06-06 03:54:57 +00:00
ADD_DEFINITIONS(-DPKG_DEFAULT_PATH=\"${pkg_default_dir}\")
ADD_DEFINITIONS(-DSYSTEM_INCLUDEDIR=\"${system_includedir}\")
ADD_DEFINITIONS(-DSYSTEM_LIBDIR=\"${system_libdir}\")
#-------- Build and install library --------
2017-06-04 22:17:51 +00:00
# Place shared libraries in same place as binary, for ease of setting PATH in test_env.sh
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${pkgconf_BINARY_DIR})
2017-06-04 22:17:51 +00:00
ADD_SUBDIRECTORY(libpkgconf)
2017-06-06 03:54:57 +00:00
#-------- Build and install executable --------
2017-06-04 22:17:51 +00:00
INCLUDE_DIRECTORIES(${libpkgconf_BINARY_DIR})
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Icli")
ADD_EXECUTABLE(pkgconf cli/main.c cli/getopt_long.c cli/renderer-msvc.c)
2017-06-04 22:17:51 +00:00
TARGET_LINK_LIBRARIES(pkgconf libpkgconf)
2017-06-05 02:32:08 +00:00
INSTALL(TARGETS pkgconf DESTINATION bin)
2017-06-04 22:17:51 +00:00
2017-06-06 03:54:57 +00:00
#-------- Tests ---------
2017-06-04 22:17:51 +00:00
ENABLE_TESTING()
2017-06-06 03:54:57 +00:00
# Handy that these files need configuring; cygwin atf doesn't like windows line endings, and NEWLINE_STYLE helps.
FOREACH(file Kyuafile tests/Kyuafile tests/test_env.sh)
CONFIGURE_FILE(${file}.in ${file} @ONLY NEWLINE_STYLE UNIX)
ENDFOREACH()
2017-06-04 22:17:51 +00:00
SET(test_scripts
tests/basic
tests/builtins
tests/conflicts
tests/framework
tests/parser
tests/provides
tests/regress
tests/requires
tests/sysroot
tests/version
)
# Handy that these files need configuring; cygwin atf doesn't like windows line endings, and NEWLINE_STYLE helps.
2017-06-04 22:17:51 +00:00
FOREACH(file ${test_scripts})
CONFIGURE_FILE(${file}.sh ${file} @ONLY NEWLINE_STYLE UNIX)
2017-06-04 22:17:51 +00:00
ENDFOREACH()
ADD_TEST(kyua kyua --config=none test)