Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify CMake code #150

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(EXAMPLES-SOURCES
set(EXAMPLES_SOURCES
mifare-classic-format
mifare-classic-read-ndef
mifare-classic-write-ndef
Expand All @@ -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)
15 changes: 3 additions & 12 deletions libfreefare/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)