Improved cmake

This commit is contained in:
Maxim Biro 2013-08-04 21:38:12 -04:00
parent f03dc44e97
commit 03a2bac319
3 changed files with 32 additions and 27 deletions

View File

@ -2,12 +2,16 @@ cmake_minimum_required(VERSION 2.6.0)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
if(UNIX)
find_package(Curses REQUIRED)
option(SHARED_TOXCORE "Build Core as a shared library")
if(WIN32)
option(SHARED_LIBSODIUM "Links libsodium as a shared library")
else()
option(USE_NACL "Use NaCl library instead of libsodium")
endif()
if(NOT WIN32)
option(USE_NACL "Use NaCl library instead of libsodium")
if(UNIX)
find_package(Curses REQUIRED)
endif()
if(USE_NACL)
@ -17,6 +21,12 @@ if(USE_NACL)
add_definitions(-DVANILLA_NACL)
set(LINK_CRYPTO_LIBRARY ${NACL_LIBRARIES})
else()
find_package(SODIUM REQUIRED)
include_directories(${SODIUM_INCLUDE_DIR})
set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
endif()
#MinGW prints more warnings for -Wall than gcc does, thus causing build to fail
@ -27,23 +37,13 @@ if(NOT WIN32)
endif()
endif()
if(NOT USE_NACL)
find_package(SODIUM REQUIRED)
set(LINK_CRYPTO_LIBRARY ${SODIUM_LIBRARY})
endif()
macro(linkCoreLibraries exe_name)
add_dependencies(${exe_name} toxcore)
if(WIN32)
include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/)
target_link_libraries(${exe_name} toxcore
${CMAKE_SOURCE_DIR}/sodium/lib/libsodium.a
ws2_32)
else()
include_directories(${SODIUM_INCLUDE_DIR})
target_link_libraries(${exe_name} toxcore
${LINK_CRYPTO_LIBRARY})
target_link_libraries(${exe_name} toxcore
${LINK_CRYPTO_LIBRARY})
if(WIN32)
target_link_libraries(${exe_name} ws2_32)
endif()
endmacro()

View File

@ -46,10 +46,16 @@ find_path(SODIUM_INCLUDE_DIR
${SODIUM_ROOT_DIR}/include
)
if(SHARED_LIBSODIUM)
set(WIN32_LIBSODIUM_FILENAME libsodium.dll.a)
else()
set(WIN32_LIBSODIUM_FILENAME libsodium.a)
endif()
find_library(SODIUM_LIBRARY
NAMES
${WIN32_LIBSODIUM_FILENAME}
sodium
libsodium.a
PATHS
${SODIUM_ROOT_DIR}/lib
)

View File

@ -1,12 +1,6 @@
cmake_minimum_required(VERSION 2.6.0)
project(toxcore C)
if(WIN32)
include_directories(${CMAKE_HOME_DIRECTORY}/sodium/include/)
else(WIN32)
include_directories(${SODIUM_INCLUDE_DIR})
endif()
set(core_sources
DHT.c
network.c
@ -16,8 +10,13 @@ set(core_sources
LAN_discovery.c
Messenger.c)
add_library(toxcore SHARED ${core_sources})
target_link_libraries(toxcore ${SODIUM_LIBRARY})
if(SHARED_TOXCORE)
add_library(toxcore SHARED ${core_sources})
else()
add_library(toxcore ${core_sources})
endif()
target_link_libraries(toxcore ${LINK_CRYPTO_LIBRARY})
if(WIN32)
target_link_libraries(toxcore ws2_32)