|
| 1 | +project (efsw) |
| 2 | + |
| 3 | +cmake_minimum_required(VERSION 2.8) |
| 4 | + |
| 5 | +option (VERBOSE "Build efsw with verbose mode.") |
| 6 | +option (STATIC_LIB "Build efsw as a static library") |
| 7 | +option (BUILD_TEST_APP "Build the test app") |
| 8 | + |
| 9 | +if (VERBOSE) |
| 10 | + add_definitions(-DEFSW_VERBOSE) |
| 11 | +endif() |
| 12 | + |
| 13 | +set(SRCS |
| 14 | + src/efsw/Debug.cpp |
| 15 | + src/efsw/DirectorySnapshot.cpp |
| 16 | + src/efsw/DirectorySnapshotDiff.cpp |
| 17 | + src/efsw/DirWatcherGeneric.cpp |
| 18 | + src/efsw/FileInfo.cpp |
| 19 | + src/efsw/FileSystem.cpp |
| 20 | + src/efsw/FileWatcher.cpp |
| 21 | + src/efsw/FileWatcherCWrapper.cpp |
| 22 | + src/efsw/FileWatcherFSEvents.cpp |
| 23 | + src/efsw/FileWatcherGeneric.cpp |
| 24 | + src/efsw/FileWatcherImpl.cpp |
| 25 | + src/efsw/FileWatcherInotify.cpp |
| 26 | + src/efsw/FileWatcherKqueue.cpp |
| 27 | + src/efsw/FileWatcherWin32.cpp |
| 28 | + src/efsw/Log.cpp |
| 29 | + src/efsw/Mutex.cpp |
| 30 | + src/efsw/String.cpp |
| 31 | + src/efsw/System.cpp |
| 32 | + src/efsw/Thread.cpp |
| 33 | + src/efsw/Watcher.cpp |
| 34 | + src/efsw/WatcherFSEvents.cpp |
| 35 | + src/efsw/WatcherGeneric.cpp |
| 36 | + src/efsw/WatcherInotify.cpp |
| 37 | + src/efsw/WatcherKqueue.cpp |
| 38 | + src/efsw/WatcherWin32.cpp) |
| 39 | + |
| 40 | +include_directories(include src) |
| 41 | + |
| 42 | +if (WIN32) |
| 43 | + list (APPEND SRCS |
| 44 | + src/efsw/platform/win/FileSystemImpl.cpp |
| 45 | + src/efsw/platform/win/MutexImpl.cpp |
| 46 | + src/efsw/platform/win/SystemImpl.cpp |
| 47 | + src/efsw/platform/win/ThreadImpl.cpp) |
| 48 | +else () |
| 49 | + list (APPEND SRCS |
| 50 | + src/efsw/platform/posix/FileSystemImpl.cpp |
| 51 | + src/efsw/platform/posix/MutexImpl.cpp |
| 52 | + src/efsw/platform/posix/SystemImpl.cpp |
| 53 | + src/efsw/platform/posix/ThreadImpl.cpp) |
| 54 | +endif() |
| 55 | + |
| 56 | +if (APPLE) |
| 57 | + list (REMOVE_ITEM SRCS |
| 58 | + "src/efsw/WatcherInotify.cpp" |
| 59 | + "src/efsw/WatcherWin32.cpp" |
| 60 | + "src/efsw/FileWatcherInotify.cpp" |
| 61 | + "src/efsw/FileWatcherWin32.cpp") |
| 62 | + |
| 63 | + exec_program(uname ARGS -v OUTPUT_VARIABLE OSX_VERSION) |
| 64 | + string(REGEX MATCH "[0-9]+" OSX_VERSION ${OSX_VERSION}) |
| 65 | + if (NOT OSX_VERSION GREATER 9) |
| 66 | + add_definitions(-DEFSW_FSEVENTS_NOT_SUPPORTED) |
| 67 | + endif() |
| 68 | +elseif (WIN32) |
| 69 | + list (REMOVE_ITEM SRCS |
| 70 | + "src/efsw/WatcherKqueue.cpp" |
| 71 | + "src/efsw/WatcherFSEvents.cpp" |
| 72 | + "src/efsw/WatcherInotify.cpp" |
| 73 | + "src/efsw/FileWatcherKqueue.cpp" |
| 74 | + "src/efsw/FileWatcherInotify.cpp" |
| 75 | + "src/efsw/FileWatcherFSEvents.cpp") |
| 76 | +elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") |
| 77 | + list (REMOVE_ITEM SRCS |
| 78 | + "src/efsw/WatcherKqueue.cpp" |
| 79 | + "src/efsw/WatcherFSEvents.cpp" |
| 80 | + "src/efsw/WatcherWin32.cpp" |
| 81 | + "src/efsw/FileWatcherKqueue.cpp" |
| 82 | + "src/efsw/FileWatcherWin32.cpp" |
| 83 | + "src/efsw/FileWatcherFSEvents.cpp") |
| 84 | + |
| 85 | + if (NOT EXISTS "/usr/include/sys/inotify.h" AND NOT EXISTS "/usr/local/include/sys/inotify.h") |
| 86 | + add_definitions(-DEFSW_INOTIFY_NOSYS) |
| 87 | + endif() |
| 88 | +elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") |
| 89 | + list (REMOVE_ITEM SRCS |
| 90 | + "src/efsw/WatcherInotify.cpp" |
| 91 | + "src/efsw/WatcherWin32.cpp" |
| 92 | + "src/efsw/WatcherFSEvents.cpp" |
| 93 | + "src/efsw/FileWatcherInotify.cpp" |
| 94 | + "src/efsw/FileWatcherWin32.cpp" |
| 95 | + "src/efsw/FileWatcherFSEvents.cpp") |
| 96 | +endif() |
| 97 | + |
| 98 | +if (MSVC) |
| 99 | + add_definitions(-D_SCL_SECURE_NO_WARNINGS) |
| 100 | +else () |
| 101 | + add_definitions(-Wall -Wno-long-long) |
| 102 | +endif() |
| 103 | + |
| 104 | +if (${CMAKE_BUILD_TYPE} MATCHES "Debug") |
| 105 | + add_definitions(-DDEBUG) |
| 106 | +elseif (${CMAKE_BUILD_TYPE} MATCHES "Release") |
| 107 | + add_definitions(-DNDEBUG) |
| 108 | +endif() |
| 109 | + |
| 110 | +if (STATIC_LIB) |
| 111 | + add_library(efsw STATIC ${SRCS}) |
| 112 | +else() |
| 113 | + add_library(efsw SHARED ${SRCS}) |
| 114 | +endif() |
| 115 | + |
| 116 | +if (APPLE) |
| 117 | + set(MAC_LIBS "-framework CoreFoundation" "-framework CoreServices") |
| 118 | + target_link_libraries(efsw ${MAC_LIBS}) |
| 119 | +elseif (NOT (${CMAKE_SYSTEM_NAME} MATCHES "Haiku") AND NOT WIN32) |
| 120 | + target_link_libraries(efsw pthread) |
| 121 | +endif() |
| 122 | + |
| 123 | +set(LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib") |
| 124 | +install(TARGETS efsw LIBRARY DESTINATION ${LIB_DESTINATION} ARCHIVE DESTINATION ${LIB_DESTINATION} RUNTIME DESTINATION ${LIB_DESTINATION}) |
| 125 | +file (GLOB HDRS "include/efsw/*.h" "include/efsw/*.hpp") |
| 126 | +install (FILES ${HDRS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/efsw) |
| 127 | + |
| 128 | +if (BUILD_TEST_APP) |
| 129 | + add_executable(efsw-test src/test/efsw-test.cpp) |
| 130 | + target_link_libraries(efsw-test efsw) |
| 131 | +endif() |
0 commit comments