Added CMake option for statically linking the binary.

This commit is contained in:
Patrick Lühne 2016-11-24 22:46:44 +01:00
parent f11097180a
commit 78511d9929
Signed by: patrick
GPG Key ID: 05F3611E97A70ABF
3 changed files with 36 additions and 9 deletions

View File

@ -2,8 +2,7 @@ cmake_minimum_required(VERSION 2.6)
project(anthem CXX) project(anthem CXX)
option(ANTHEM_BUILD_TESTS "Build unit tests" OFF) option(ANTHEM_BUILD_TESTS "Build unit tests" OFF)
option(ANTHEM_BUILD_STATIC "Build static binaries" OFF)
find_package(Boost 1.55.0 COMPONENTS program_options iostreams system filesystem REQUIRED)
set(CMAKE_CXX_FLAGS "-Wall -Wpedantic") set(CMAKE_CXX_FLAGS "-Wall -Wpedantic")
set(CMAKE_CXX_FLAGS_DEBUG "-g") set(CMAKE_CXX_FLAGS_DEBUG "-g")
@ -16,9 +15,23 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(ANTHEM_BUILD_STATIC)
set(CMAKE_EXE_LINKER_FLAGS "-static")
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
# Remove -Wl,-Bdynamic
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
endif()
set(CLASP_BUILD_APP OFF CACHE BOOL "whether or not to build the clasp application") set(CLASP_BUILD_APP OFF CACHE BOOL "whether or not to build the clasp application")
set(CLASP_BUILD_TEST OFF CACHE BOOL "whether or not to build clasp unit tests (requires CppUnit)") set(CLASP_BUILD_TEST OFF CACHE BOOL "whether or not to build clasp unit tests (requires CppUnit)")
if(ANTHEM_BUILD_STATIC)
set(CLINGO_BUILD_SHARED OFF CACHE BOOL "build clingo library shared") set(CLINGO_BUILD_SHARED OFF CACHE BOOL "build clingo library shared")
else()
set(CLINGO_BUILD_SHARED ON CACHE BOOL "build clingo library shared")
endif()
set(CLINGO_BUILD_WITH_LUA OFF CACHE BOOL "enable lua support") set(CLINGO_BUILD_WITH_LUA OFF CACHE BOOL "enable lua support")
set(CLINGO_BUILD_WITH_PYTHON OFF CACHE BOOL "enable python support") set(CLINGO_BUILD_WITH_PYTHON OFF CACHE BOOL "enable python support")
set(LIB_POTASSCO_BUILD_APP OFF CACHE BOOL "whether or not to build lpconvert tool") set(LIB_POTASSCO_BUILD_APP OFF CACHE BOOL "whether or not to build lpconvert tool")

View File

@ -1,5 +1,7 @@
set(target anthem-app) set(target anthem-app)
find_package(Boost 1.55.0 COMPONENTS program_options system filesystem REQUIRED)
file(GLOB core_sources "*.cpp") file(GLOB core_sources "*.cpp")
file(GLOB core_headers "*.h") file(GLOB core_headers "*.h")
@ -8,6 +10,16 @@ set(sources
${core_headers} ${core_headers}
) )
set(includes
${Boost_INCLUDE_DIRS}
)
set(libraries
${Boost_LIBRARIES}
anthem
)
add_executable(${target} ${sources}) add_executable(${target} ${sources})
target_link_libraries(${target} anthem) target_include_directories(${target} PRIVATE ${includes})
target_link_libraries(${target} PRIVATE ${libraries})
set_target_properties(${target} PROPERTIES OUTPUT_NAME anthem) set_target_properties(${target} PROPERTIES OUTPUT_NAME anthem)

View File

@ -16,17 +16,19 @@ set(sources
set(includes set(includes
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
${Boost_INCLUDE_DIRS}
) )
set(libraries set(libraries
${Boost_LIBRARIES}
libclasp libclasp
libclingo libclingo
libgringo libgringo
pthread
) )
if(ANTHEM_BUILD_STATIC)
add_library(${target} STATIC ${sources})
else()
add_library(${target} ${sources}) add_library(${target} ${sources})
endif()
target_include_directories(${target} PUBLIC ${includes}) target_include_directories(${target} PUBLIC ${includes})
target_link_libraries(${target} ${libraries}) target_link_libraries(${target} ${libraries})