Skip to content

Instantly share code, notes, and snippets.

@e2
Created April 16, 2016 23:14
Show Gist options
  • Save e2/5e1a35ffef7d6b58247554dbc8cee50e to your computer and use it in GitHub Desktop.
Save e2/5e1a35ffef7d6b58247554dbc8cee50e to your computer and use it in GitHub Desktop.
set(TUP_LABEL $ENV{TUP_LABEL})
cmake_minimum_required(VERSION 3.2.2)
project(tup)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSQLITE_TEMP_STORE=2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSQLITE_THREADSAFE=0")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSQLITE_OMIT_LOAD_EXTENSION")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DLUA_USE_MKSTEMP")
# fuse needs this to compile
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
include_directories("${CMAKE_SOURCE_DIR}/src")
set(sources
"${CMAKE_SOURCE_DIR}/src/compat/dummy.c"
"${CMAKE_SOURCE_DIR}/src/inih/ini.c"
"${CMAKE_SOURCE_DIR}/src/tup/bin.c"
"${CMAKE_SOURCE_DIR}/src/tup/colors.c"
"${CMAKE_SOURCE_DIR}/src/tup/config.c"
"${CMAKE_SOURCE_DIR}/src/tup/create_name_file.c"
"${CMAKE_SOURCE_DIR}/src/tup/db.c"
"${CMAKE_SOURCE_DIR}/src/tup/debug.c"
"${CMAKE_SOURCE_DIR}/src/tup/delete_name_file.c"
"${CMAKE_SOURCE_DIR}/src/tup/dircache.c"
"${CMAKE_SOURCE_DIR}/src/tup/entry.c"
"${CMAKE_SOURCE_DIR}/src/tup/environ.c"
"${CMAKE_SOURCE_DIR}/src/tup/estring.c"
"${CMAKE_SOURCE_DIR}/src/tup/file.c"
"${CMAKE_SOURCE_DIR}/src/tup/flock/fcntl.c"
"${CMAKE_SOURCE_DIR}/src/tup/fslurp.c"
"${CMAKE_SOURCE_DIR}/src/tup/graph.c"
"${CMAKE_SOURCE_DIR}/src/tup/init.c"
"${CMAKE_SOURCE_DIR}/src/tup/lock.c"
"${CMAKE_SOURCE_DIR}/src/tup/luaparser.c"
"${CMAKE_SOURCE_DIR}/src/tup/tup/main.c"
"${CMAKE_SOURCE_DIR}/src/tup/monitor/inotify.c"
"${CMAKE_SOURCE_DIR}/src/tup/option.c"
"${CMAKE_SOURCE_DIR}/src/tup/parser.c"
"${CMAKE_SOURCE_DIR}/src/tup/path.c"
"${CMAKE_SOURCE_DIR}/src/tup/pel_group.c"
"${CMAKE_SOURCE_DIR}/src/tup/platform.c"
"${CMAKE_SOURCE_DIR}/src/tup/privs.c"
"${CMAKE_SOURCE_DIR}/src/tup/progress.c"
"${CMAKE_SOURCE_DIR}/src/tup/send_event.c"
"${CMAKE_SOURCE_DIR}/src/tup/server/fuse_fs.c"
"${CMAKE_SOURCE_DIR}/src/tup/server/fuse_server.c"
"${CMAKE_SOURCE_DIR}/src/tup/server/master_fork.c"
"${CMAKE_SOURCE_DIR}/src/tup/string_tree.c"
"${CMAKE_SOURCE_DIR}/src/tup/timespan.c"
"${CMAKE_SOURCE_DIR}/src/tup/tupid_tree.c"
"${CMAKE_SOURCE_DIR}/src/tup/updater.c"
"${CMAKE_SOURCE_DIR}/src/tup/vardb.c"
"${CMAKE_SOURCE_DIR}/src/tup/thread_tree.c"
"${CMAKE_SOURCE_DIR}/src/tup/vardict.c"
"${CMAKE_SOURCE_DIR}/src/tup/variant.c"
"${CMAKE_SOURCE_DIR}/src/tup/varsed.c"
"${CMAKE_SOURCE_DIR}/src/tup/if_stmt.c"
)
# Copy lua_builtin to build dir so it can be used in next step (below)
set(lua_builtin_src ${CMAKE_SOURCE_DIR}/src/luabuiltin/builtin.lua)
set(lua_builtin ${CMAKE_CURRENT_BINARY_DIR}/builtin.lua)
add_custom_command(
OUTPUT ${lua_builtin}
COMMAND ${CMAKE_COMMAND} -E copy ${lua_builtin_src} ${lua_builtin}
DEPENDS ${lua_builtin_src}
)
# Create lua_builtin header
set(lua /usr/bin/lua5.2)
set(lua_xxd ${CMAKE_SOURCE_DIR}/src/luabuiltin/xxd.lua)
set(gen_lua_builtin_h ${CMAKE_CURRENT_BINARY_DIR}/luabuiltin/luabuiltin.h)
add_custom_command(
OUTPUT ${gen_lua_builtin_h}
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/luabuiltin
COMMAND ${lua} ${lua_xxd} builtin.lua ${gen_lua_builtin_h}
DEPENDS ${lua_xxd} ${lua_builtin}
)
set(TUP_VERSION ${TUP_LABEL})
set(version_c ${CMAKE_CURRENT_BINARY_DIR}/version.c)
configure_file(${CMAKE_SOURCE_DIR}/src/tup/tup/version.c.template ${version_c} @ONLY)
add_executable(tup
${sources}
${gen_lua_builtin_h}
${version_c}
)
include_directories("${CMAKE_CURRENT_BINARY_DIR}")
install(TARGETS tup RUNTIME DESTINATION bin)
include(GNUInstallDirs)
find_package(Threads)
find_package(PkgConfig REQUIRED)
pkg_check_modules(FUSE fuse=>2.9.4)
target_include_directories(tup PUBLIC ${FUSE_INCLUDE_DIRS})
link_directories(${FUSE_LIBRARY_DIRS})
pkg_check_modules(SQLITE3 sqlite3>=3.8.11)
target_include_directories(tup PUBLIC ${SQLITE3_INCLUDE_DIRS})
link_directories( ${SQLITE3_LIBRARY_DIRS})
find_package(Lua REQUIRED)
target_link_libraries(tup
${SQLITE3_LIBRARIES}
${LUA_LIBRARIES}
${FUSE_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
m
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment