Skip to content

Commit 7ae4e57

Browse files
committed
Simplify CMake code
1 parent c2b0cfa commit 7ae4e57

File tree

3 files changed

+14
-32
lines changed

3 files changed

+14
-32
lines changed

CMakeLists.txt

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ add_definitions("-std=c99")
1818
find_package(LIBNFC REQUIRED)
1919
find_package(OpenSSL REQUIRED)
2020

21+
include(GNUInstallDirs)
22+
2123
IF(WIN32)
2224
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
2325
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32)
@@ -52,23 +54,12 @@ set(LIBS ${LIBS} ${LIBNFC_LIBRARIES} ${OPENSSL_LIBRARIES})
5254

5355
option(WITH_DEBUG "Extra debug information is outputted when this is turned on" OFF)
5456

55-
if(DEFINED CMAKE_INSTALL_LIBDIR)
56-
set(libdir ${CMAKE_INSTALL_LIBDIR})
57-
else(DEFINED CMAKE_INSTALL_LIBDIR)
58-
set(CMAKE_INSTALL_LIBDIR lib)
59-
set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
60-
endif(DEFINED CMAKE_INSTALL_LIBDIR)
61-
62-
if(DEFINED INCLUDE_INSTALL_DIR)
63-
set(includedir ${INCLUDE_INSTALL_DIR})
64-
else(DEFINED INCLUDE_INSTALL_DIR)
65-
set(INCLUDE_INSTALL_DIR include)
66-
set(includedir ${CMAKE_INSTALL_PREFIX}/${INCLUDE_INSTALL_DIR})
67-
endif(DEFINED INCLUDE_INSTALL_DIR)
68-
69-
if(NOT DEFINED SHARE_INSTALL_PREFIX)
70-
set(SHARE_INSTALL_PREFIX share)
71-
endif(NOT DEFINED SHARE_INSTALL_PREFIX)
57+
set(prefix ${CMAKE_INSTALL_PREFIX})
58+
set(exec_prefix \${prefix})
59+
set(libdir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
60+
set(includedir \${prefix}/${CMAKE_INSTALL_INCLUDEDIR})
61+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libfreefare.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libfreefare.pc @ONLY)
62+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libfreefare.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
7263

7364
add_subdirectory(libfreefare)
7465
add_subdirectory(examples)

examples/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(EXAMPLES-SOURCES
1+
set(EXAMPLES_SOURCES
22
mifare-classic-format
33
mifare-classic-read-ndef
44
mifare-classic-write-ndef
@@ -21,8 +21,8 @@ set(EXAMPLES-SOURCES
2121
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../libfreefare)
2222

2323
# Examples
24-
foreach(source ${EXAMPLES-SOURCES})
24+
foreach(source ${EXAMPLES_SOURCES})
2525
add_executable(${source} ${source}.c)
2626
target_link_libraries(${source} freefare)
27-
install(TARGETS ${source} RUNTIME DESTINATION bin COMPONENT examples)
27+
install(TARGETS ${source} RUNTIME COMPONENT examples)
2828
endforeach(source)

libfreefare/CMakeLists.txt

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,10 @@ set(LIBRARY_SOURCES
2020

2121
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
2222

23-
add_library(freefare SHARED ${LIBRARY_SOURCES})
23+
add_library(freefare ${LIBRARY_SOURCES})
2424
target_link_libraries(freefare ${LIBS})
2525

2626
set(installheaders freefare.h)
27-
install(FILES ${installheaders} DESTINATION ${INCLUDE_INSTALL_DIR}/freefare COMPONENT headers)
2827

29-
if(WIN32)
30-
# On Windows the shared (runtime) library should be either in the same
31-
# directory as the excutables or in the path, we add it to same directory
32-
install(TARGETS freefare RUNTIME DESTINATION bin COMPONENT libraries)
33-
34-
# At compile time we need the .LIB file, we place it in the lib directory
35-
install(TARGETS freefare ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT headers)
36-
else(WIN32)
37-
install(TARGETS freefare LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
38-
endif(WIN32)
28+
install(FILES ${installheaders} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/freefare COMPONENT headers)
29+
install(TARGETS freefare LIBRARY COMPONENT libraries)

0 commit comments

Comments
 (0)