Merge pull request #856 from michael-loki/cmake_exe

Split cmake files for executables into respective source dirs
This commit is contained in:
Jeff 2019-10-07 05:55:39 -04:00 committed by GitHub
commit a0aea73bcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 103 additions and 108 deletions

View File

@ -198,9 +198,6 @@ endif(NOT GIT_VERSION)
string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}") string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}")
add_definitions("-DGIT_REV=\"${GIT_VERSION_REAL}\"") add_definitions("-DGIT_REV=\"${GIT_VERSION_REAL}\"")
set(EXE lokinet)
set(EXE_SRC daemon/main.cpp)
# HeapAlloc(2) on Windows was significantly revamped in 2009 # HeapAlloc(2) on Windows was significantly revamped in 2009
# but the old algorithm isn't too bad either # but the old algorithm isn't too bad either
# this is _the_ system allocator on BSD UNIX # this is _the_ system allocator on BSD UNIX
@ -216,96 +213,21 @@ if(ANDROID)
set(ANDROID_PLATFORM_SRC android/ifaddrs.c) set(ANDROID_PLATFORM_SRC android/ifaddrs.c)
endif(ANDROID) endif(ANDROID)
set(LIBTUNTAP_SRC_BASE
${TT_ROOT}/tuntap.cpp
${TT_ROOT}/tuntap_log.cpp
${LIBTUNTAP_IMPL})
if(UNIX)
set(LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix.c ${LIBTUNTAP_SRC_BASE})
else()
set(LIBTUNTAP_SRC ${LIBTUNTAP_SRC_BASE})
endif()
set(LIBS ${MALLOC_LIB} ${FS_LIB} ${LIBUV_LIBRARY}) set(LIBS ${MALLOC_LIB} ${FS_LIB} ${LIBUV_LIBRARY})
add_subdirectory(crypto) add_subdirectory(crypto)
add_subdirectory(llarp) add_subdirectory(llarp)
add_subdirectory(libabyss) add_subdirectory(libabyss)
add_subdirectory(daemon)
if (NOT WIN32) enable_testing()
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads ${LIBS})
elseif(NOT MSVC_VERSION)
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp llarp/win32/abyss.rc)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
else()
add_executable(${ABYSS_EXE} ${ABYSS}/main.cpp)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
endif(NOT WIN32)
# Why does abyss not inherit the existing include folders?
target_include_directories(${ABYSS_LIB} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" llarp vendor/nlohmann/include include crypto/include)
target_include_directories(${ABYSS_EXE} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" llarp vendor/nlohmann/include include crypto/include)
# for freebsd
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_directories(${ABYSS_EXE} PRIVATE /usr/local/lib)
target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
add_log_tag(${ABYSS_EXE})
add_log_tag(${ABYSS_LIB})
if(SHADOW)
set(LOKINET_SHADOW shadow-plugin-${SHARED_LIB})
set(LOKINET_SHADOW_LIBS ${SHARED_LIB})
add_shadow_plugin(${LOKINET_SHADOW} ${EXE_SRC})
target_link_libraries(${LOKINET_SHADOW} ${LOKINET_SHADOW_LIBS})
target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include)
else()
if(NOT WIN32)
add_executable(${EXE} ${EXE_SRC})
add_executable(lokinet-rcutil daemon/rcutil.cpp)
elseif(NOT MSVC_VERSION)
add_executable(${EXE} ${EXE_SRC} llarp/win32/version.rc)
add_executable(lokinet-rcutil daemon/rcutil.cpp llarp/win32/version.rc)
else()
add_executable(${EXE} ${EXE_SRC})
add_executable(lokinet-rcutil daemon/rcutil.cpp)
endif(NOT WIN32)
add_log_tag(${EXE})
add_log_tag(lokinet-rcutil)
install(TARGETS ${EXE} RUNTIME DESTINATION bin)
install(TARGETS lokinet-rcutil RUNTIME DESTINATION bin)
if(WIN32)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin)
else()
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(CODE "execute_process(COMMAND setcap cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)")
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_directories(${EXE} PRIVATE /usr/local/lib)
target_link_directories(lokinet-rcutil PRIVATE /usr/local/lib)
endif()
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS})
target_link_libraries(lokinet-rcutil PUBLIC ${EXE_LIBS} ${LIBS})
if (NOT SHADOW)
add_subdirectory(test)
if(ANDROID) if(ANDROID)
add_library(${ANDROID_LIB} SHARED jni/lokinet_android.cpp) add_library(${ANDROID_LIB} SHARED jni/lokinet_android.cpp)
set_property(TARGET ${ANDROID_LIB} PROPERTY CXX_STANDARD 14) set_property(TARGET ${ANDROID_LIB} PROPERTY CXX_STANDARD 14)
add_log_tag(${ANDROID_LIB}) add_log_tag(${ANDROID_LIB})
target_link_libraries(${ANDROID_LIB} ${STATIC_LIB} ${LIBS}) target_link_libraries(${ANDROID_LIB} ${STATIC_LIB} ${LIBS})
endif(ANDROID) endif(ANDROID)
endif(SHADOW)
enable_testing()
if (NOT SHADOW)
add_subdirectory(test)
endif() endif()

View File

@ -116,7 +116,7 @@ endif
TARGETS = $(REPO)/lokinet TARGETS = $(REPO)/lokinet
SIGS = $(TARGETS:=.sig) SIGS = $(TARGETS:=.sig)
EXE = $(BUILD_ROOT)/lokinet EXE = $(BUILD_ROOT)/daemon/lokinet
TEST_EXE = $(BUILD_ROOT)/test/testAll TEST_EXE = $(BUILD_ROOT)/test/testAll
ABYSS_EXE = $(BUILD_ROOT)/abyss-main ABYSS_EXE = $(BUILD_ROOT)/abyss-main

View File

@ -1,6 +1,8 @@
function(add_log_tag target) function(add_log_tag target)
get_target_property(TARGET_SRCS ${target} SOURCES) if(TARGET ${target})
foreach(F ${TARGET_SRCS}) get_target_property(TARGET_SRCS ${target} SOURCES)
set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\") foreach(F ${TARGET_SRCS})
endforeach(F) set_source_files_properties(${F} PROPERTIES COMPILE_FLAGS -DLOG_TAG=\\\"${F}\\\")
endforeach(F)
endif()
endfunction() endfunction()

View File

@ -9,8 +9,12 @@ set(ANDROID_LIB ${LIB}android)
set(ABYSS libabyss) set(ABYSS libabyss)
set(ABYSS_LIB abyss) set(ABYSS_LIB abyss)
set(ABYSS_EXE ${ABYSS_LIB}-main) set(ABYSS_EXE ${ABYSS_LIB}-main)
get_filename_component(TT_ROOT "vendor/libtuntap-master" ABSOLUTE) get_filename_component(TT_ROOT "${CMAKE_CURRENT_LIST_DIR}/../vendor/libtuntap-master" ABSOLUTE)
add_definitions(-D${CMAKE_SYSTEM_NAME}) add_definitions(-D${CMAKE_SYSTEM_NAME})
get_filename_component(CORE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include" ABSOLUTE) get_filename_component(CORE_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/include" ABSOLUTE)
get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" ABSOLUTE) get_filename_component(ABYSS_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/${ABYSS}/include" ABSOLUTE)
set(LIBTUNTAP_SRC
${TT_ROOT}/tuntap.cpp
${TT_ROOT}/tuntap_log.cpp)

View File

@ -7,6 +7,7 @@ include(CheckLibraryExists)
add_definitions(-DUNIX) add_definitions(-DUNIX)
add_definitions(-DPOSIX) add_definitions(-DPOSIX)
list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix.c)
if (STATIC_LINK_RUNTIME OR STATIC_LINK) if (STATIC_LINK_RUNTIME OR STATIC_LINK)
set(LIBUV_USE_STATIC ON) set(LIBUV_USE_STATIC ON)
@ -30,7 +31,7 @@ endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(FS_LIB stdc++fs) set(FS_LIB stdc++fs)
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE) list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-linux.c)
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android") elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
find_library(FS_LIB NAMES c++fs c++experimental stdc++fs) find_library(FS_LIB NAMES c++fs c++experimental stdc++fs)
if(FS_LIB STREQUAL FS_LIB-NOTFOUND) if(FS_LIB STREQUAL FS_LIB-NOTFOUND)
@ -38,14 +39,14 @@ elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
add_definitions(-DLOKINET_USE_CPPBACKPORT) add_definitions(-DLOKINET_USE_CPPBACKPORT)
set(FS_LIB cppbackport) set(FS_LIB cppbackport)
endif() endif()
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-linux.c ABSOLUTE) list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-linux.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD") elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-openbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD") elseif (${CMAKE_SYSTEM_NAME} MATCHES "NetBSD")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c) list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-netbsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly") elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" OR ${CMAKE_SYSTEM_NAME} MATCHES "DragonFly")
find_library(FS_LIB NAMES c++experimental) find_library(FS_LIB NAMES c++experimental)
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c) list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-freebsd.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "iOS") elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "iOS")
find_library(FS_LIB NAMES c++fs c++experimental stdc++fs) find_library(FS_LIB NAMES c++fs c++experimental stdc++fs)
if(FS_LIB STREQUAL FS_LIB-NOTFOUND) if(FS_LIB STREQUAL FS_LIB-NOTFOUND)
@ -53,9 +54,9 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin" OR ${CMAKE_SYSTEM_NAME} MATCHES "i
add_definitions(-DLOKINET_USE_CPPBACKPORT) add_definitions(-DLOKINET_USE_CPPBACKPORT)
set(FS_LIB cppbackport) set(FS_LIB cppbackport)
endif() endif()
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c) list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-darwin.c ${TT_ROOT}/tuntap-unix-bsd.c)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS") elseif (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
set(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-unix-sunos.c) list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-unix-sunos.c)
# Apple C++ screws up name decorations in stdc++fs, causing link to fail # Apple C++ screws up name decorations in stdc++fs, causing link to fail
# Samsung does not build c++experimental or c++fs in their Apple libc++ pkgsrc build # Samsung does not build c++experimental or c++fs in their Apple libc++ pkgsrc build
if (LIBUV_USE_STATIC) if (LIBUV_USE_STATIC)

View File

@ -21,17 +21,17 @@ if(NOT MSVC_VERSION)
# to .r[o]data section one after the other! # to .r[o]data section one after the other!
add_compile_options(-fno-ident -Wa,-mbig-obj) add_compile_options(-fno-ident -Wa,-mbig-obj)
link_libraries( -lws2_32 -liphlpapi -lshlwapi -ldbghelp ) link_libraries( -lws2_32 -liphlpapi -lshlwapi -ldbghelp )
add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500) add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500)
# Wait a minute, if we're not Microsoft C++, nor a Clang paired with Microsoft C++, # Wait a minute, if we're not Microsoft C++, nor a Clang paired with Microsoft C++,
# then the only possible option has to be GNU or a GNU-linked Clang! # then the only possible option has to be GNU or a GNU-linked Clang!
set(FS_LIB stdc++fs) set(FS_LIB stdc++fs)
endif() endif()
if(EMBEDDED_CFG) if(EMBEDDED_CFG)
link_libatomic() link_libatomic()
endif() endif()
get_filename_component(LIBTUNTAP_IMPL ${TT_ROOT}/tuntap-windows.c ABSOLUTE) list(APPEND LIBTUNTAP_SRC ${TT_ROOT}/tuntap-windows.c)
get_filename_component(EV_SRC "llarp/ev/ev_win32.cpp" ABSOLUTE) get_filename_component(EV_SRC "llarp/ev/ev_win32.cpp" ABSOLUTE)
add_definitions(-DWIN32_LEAN_AND_MEAN -DWIN32 -DWINVER=0x0500) add_definitions(-DWIN32_LEAN_AND_MEAN -DWIN32 -DWINVER=0x0500)
set(EXE_LIBS ${STATIC_LIB} ${FS_LIB} ws2_32 iphlpapi) set(EXE_LIBS ${STATIC_LIB} ${FS_LIB} ws2_32 iphlpapi)

41
daemon/CMakeLists.txt Normal file
View File

@ -0,0 +1,41 @@
set(EXE lokinet)
set(EXE_SRC main.cpp)
if(SHADOW)
set(LOKINET_SHADOW shadow-plugin-${SHARED_LIB})
set(LOKINET_SHADOW_LIBS ${SHARED_LIB})
add_shadow_plugin(${LOKINET_SHADOW} ${EXE_SRC})
target_link_libraries(${LOKINET_SHADOW} ${LOKINET_SHADOW_LIBS})
target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include)
else()
if(NOT WIN32)
add_executable(${EXE} ${EXE_SRC})
add_executable(lokinet-rcutil rcutil.cpp)
elseif(NOT MSVC_VERSION)
add_executable(${EXE} ${EXE_SRC} llarp/win32/version.rc)
add_executable(lokinet-rcutil rcutil.cpp llarp/win32/version.rc)
else()
add_executable(${EXE} ${EXE_SRC})
add_executable(lokinet-rcutil rcutil.cpp)
endif(NOT WIN32)
add_log_tag(${EXE})
add_log_tag(lokinet-rcutil)
install(TARGETS ${EXE} RUNTIME DESTINATION bin)
install(TARGETS lokinet-rcutil RUNTIME DESTINATION bin)
if(WIN32)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin)
else()
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
install(CODE "execute_process(COMMAND setcap cap_net_admin,cap_net_bind_service=+eip ${CMAKE_INSTALL_PREFIX}/bin/lokinet)")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_directories(${EXE} PRIVATE /usr/local/lib)
target_link_directories(lokinet-rcutil PRIVATE /usr/local/lib)
endif()
target_link_libraries(${EXE} PUBLIC ${EXE_LIBS} ${LIBS})
target_link_libraries(lokinet-rcutil PUBLIC ${EXE_LIBS} ${LIBS})
endif(SHADOW)

View File

@ -12,5 +12,5 @@ RUN make NINJA=ninja STATIC_LINK=ON BUILD_TYPE=Release
FROM alpine:latest FROM alpine:latest
COPY --from=builder /src/build/lokinet / COPY --from=builder /src/build/daemon/lokinet /
COPY --from=builder /src/build/lokinet-rcutil / COPY --from=builder /src/build/daemon/lokinet-rcutil /

View File

@ -13,7 +13,7 @@ RUN ./lokinet-bootstrap ${bootstrap}
FROM alpine:latest FROM alpine:latest
COPY lokinet-docker.ini /root/.lokinet/lokinet.ini COPY lokinet-docker.ini /root/.lokinet/lokinet.ini
COPY --from=builder /src/build/lokinet . COPY --from=builder /src/build/daemon/lokinet .
COPY --from=builder /root/.lokinet/bootstrap.signed /root/.lokinet/ COPY --from=builder /root/.lokinet/bootstrap.signed /root/.lokinet/
CMD ["./lokinet"] CMD ["./lokinet"]

View File

@ -4,6 +4,25 @@ add_library(${ABYSS_LIB} "${CMAKE_CURRENT_SOURCE_DIR}/src/md5.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp") "${CMAKE_CURRENT_SOURCE_DIR}/src/server.cpp")
target_include_directories(${ABYSS_LIB} PUBLIC include) target_include_directories(${ABYSS_LIB} PUBLIC include)
if(NOT WIN32) target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB})
target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB} ${LIBUV_LIBRARY})
if(NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL iOS)
target_link_libraries(${ABYSS_LIB} PUBLIC ${LIBUV_LIBRARY})
add_executable(${ABYSS_EXE} main.cpp)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} Threads::Threads ${LIBS})
elseif(MSVC_VERSION)
add_executable(${ABYSS_EXE} main.cpp)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
elseif(NOT CMAKE_SYSTEM_NAME STREQUAL iOS)
add_executable(${ABYSS_EXE} main.cpp llarp/win32/abyss.rc)
target_link_libraries(${ABYSS_EXE} PUBLIC ${ABYSS_LIB} ${STATIC_LIB} ws2_32)
endif() endif()
# for freebsd
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_directories(${ABYSS_EXE} PRIVATE /usr/local/lib)
target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
add_log_tag(${ABYSS_EXE})
add_log_tag(${ABYSS_LIB})

View File

@ -31,7 +31,9 @@ add_subdirectory(${libuv_SOURCE_DIR} ${libuv_BINARY_DIR})
include("${LOKINET_ROOT}/cmake/basic_definitions.cmake") include("${LOKINET_ROOT}/cmake/basic_definitions.cmake")
set(LIBUV_IN_SOURCE ON) set(LIBUV_IN_SOURCE ON)
set(LIBUV_LIBRARY uv_a)
include("${LOKINET_ROOT}/cmake/unix.cmake") include("${LOKINET_ROOT}/cmake/unix.cmake")
unset(LIBTUNTAP_SRC)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
@ -51,6 +53,10 @@ include_directories("${libuv_SOURCE_DIR}/include")
add_loki_dir(vendor/gtest) add_loki_dir(vendor/gtest)
add_subdirectory(${ABSEIL_DIR} "vendor/abseil-cpp") add_subdirectory(${ABSEIL_DIR} "vendor/abseil-cpp")
if (FS_LIB STREQUAL "cppbackport")
add_loki_dir(vendor)
endif()
add_loki_dir(crypto) add_loki_dir(crypto)
add_loki_dir(llarp) add_loki_dir(llarp)
add_loki_dir(libabyss) add_loki_dir(libabyss)