diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c921e36..ef90af0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,8 @@ add_definitions("-std=c99") find_package(LIBNFC REQUIRED) find_package(OpenSSL REQUIRED) +include(GNUInstallDirs) + IF(WIN32) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/config.h) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32) @@ -52,23 +54,12 @@ set(LIBS ${LIBS} ${LIBNFC_LIBRARIES} ${OPENSSL_LIBRARIES}) option(WITH_DEBUG "Extra debug information is outputted when this is turned on" OFF) -if(DEFINED CMAKE_INSTALL_LIBDIR) - set(libdir ${CMAKE_INSTALL_LIBDIR}) -else(DEFINED CMAKE_INSTALL_LIBDIR) - set(CMAKE_INSTALL_LIBDIR lib) - set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) -endif(DEFINED CMAKE_INSTALL_LIBDIR) - -if(DEFINED INCLUDE_INSTALL_DIR) - set(includedir ${INCLUDE_INSTALL_DIR}) -else(DEFINED INCLUDE_INSTALL_DIR) - set(INCLUDE_INSTALL_DIR include) - set(includedir ${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR}) -endif(DEFINED INCLUDE_INSTALL_DIR) - -if(NOT DEFINED SHARE_INSTALL_PREFIX) - set(SHARE_INSTALL_PREFIX share) -endif(NOT DEFINED SHARE_INSTALL_PREFIX) +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix \${prefix}) +set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR}) +set(libdir \${prefix}/${CMAKE_INSTALL_LIBDIR}) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libfreefare.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libfreefare.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libfreefare.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) add_subdirectory(libfreefare) add_subdirectory(examples) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 575bafe4..364e753d 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,4 +1,4 @@ -set(EXAMPLES-SOURCES +set(EXAMPLES_SOURCES mifare-classic-format mifare-classic-read-ndef mifare-classic-write-ndef @@ -21,8 +21,8 @@ set(EXAMPLES-SOURCES include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libfreefare) # Examples -foreach(source ${EXAMPLES-SOURCES}) +foreach(source ${EXAMPLES_SOURCES}) add_executable(${source} ${source}.c) target_link_libraries(${source} freefare) - install(TARGETS ${source} RUNTIME DESTINATION bin COMPONENT examples) + install(TARGETS ${source} RUNTIME COMPONENT examples) endforeach(source) diff --git a/libfreefare/CMakeLists.txt b/libfreefare/CMakeLists.txt index 871fef70..68dc2242 100644 --- a/libfreefare/CMakeLists.txt +++ b/libfreefare/CMakeLists.txt @@ -20,19 +20,10 @@ set(LIBRARY_SOURCES include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -add_library(freefare SHARED ${LIBRARY_SOURCES}) +add_library(freefare ${LIBRARY_SOURCES}) target_link_libraries(freefare ${LIBS}) set(installheaders freefare.h) -install(FILES ${installheaders} DESTINATION ${INCLUDE_INSTALL_DIR}/freefare COMPONENT headers) -if(WIN32) - # On Windows the shared (runtime) library should be either in the same - # directory as the excutables or in the path, we add it to same directory - install(TARGETS freefare RUNTIME DESTINATION bin COMPONENT libraries) - - # At compile time we need the .LIB file, we place it in the lib directory - install(TARGETS freefare ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT headers) -else(WIN32) - install(TARGETS freefare LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries) -endif(WIN32) +install(FILES ${installheaders} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/freefare COMPONENT headers) +install(TARGETS freefare LIBRARY COMPONENT libraries)