CreatureLib/CMakeLists.txt

65 lines
2.5 KiB
CMake
Raw Normal View History

cmake_minimum_required(VERSION 3.13)
2019-10-06 11:50:52 +00:00
project(CreatureLib)
2020-07-17 11:12:21 +00:00
# Enable all warnings, and make them error when occurring.
add_compile_options(-Wall -Wextra -Werror)
# We like new stuff, so set the c++ standard to c++20.
2020-06-26 15:08:23 +00:00
set(CMAKE_CXX_STANDARD 20)
2019-10-06 11:50:52 +00:00
2020-07-17 11:12:21 +00:00
option(WINDOWS "Whether the build target is Windows or not." OFF)
option(SHARED "Whether we should build a shared library, instead of a static one." OFF)
option(TESTS "Whether the test executable should be build as well." OFF)
option(STATICC "Whether gcc and stdc++ should be linked statically to the library." OFF)
2020-05-03 10:45:12 +00:00
2020-07-17 11:12:21 +00:00
include(CmakeConanSetup.cmake)
SetupConan()
2020-07-17 11:12:21 +00:00
# Set whether we want a static or shared library.
set(LIBTYPE STATIC)
if (SHARED)
set(LIBTYPE SHARED)
endif (SHARED)
2019-10-06 11:50:52 +00:00
2019-10-17 12:33:25 +00:00
# Create main Library library with files in src/Library
file(GLOB_RECURSE LIBRARY_SRC_FILES "src/Library/*.cpp" "src/Library/*.hpp" "CInterface/Library/*.cpp" "CInterface/Core.*")
2019-10-06 11:50:52 +00:00
add_library(CreatureLibLibrary SHARED ${LIBRARY_SRC_FILES})
2019-10-17 12:33:25 +00:00
# Create Battling library with files in src/Battling
file(GLOB_RECURSE BATTLING_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp" "CInterface/Battling/*.cpp" "CInterface/Core.*")
2019-10-17 12:33:25 +00:00
add_library(CreatureLibBattling SHARED ${BATTLING_SRC_FILES})
2020-07-17 11:12:21 +00:00
# If we are building for Windows we need to set some specific variables.
2019-10-06 11:50:52 +00:00
if (WINDOWS)
2020-07-17 11:12:21 +00:00
MESSAGE(WARNING, "Using Windows Build.")
# Add a definition for the compiler, so we can use it in C++ as well.
ADD_DEFINITIONS(-D WINDOWS=1)
# -m64: Build a 64 bit library
add_compile_options(-m64)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,-allow-multiple-definition")
2020-05-02 13:55:31 +00:00
endif (WINDOWS)
2020-07-17 11:12:21 +00:00
# Set up links to all relevant libraries.
SET(_LIBRARYLINKS Arbutils)
SET(_BATTLINGLINKS CreatureLibLibrary Arbutils)
# If we need to link the C libraries statically, do so.
2020-05-02 13:55:31 +00:00
if (STATICC)
2020-05-03 10:45:12 +00:00
message(STATUS "Linking C statically.")
SET(_LIBRARYLINKS ${_LIBRARYLINKS} -static-libgcc -static-libstdc++)
SET(_BATTLINGLINKS ${_BATTLINGLINKS} -static-libgcc -static-libstdc++)
2020-05-02 13:55:31 +00:00
endif ()
2020-07-17 11:12:21 +00:00
# And link the libraries together
2020-05-02 13:55:31 +00:00
target_link_libraries(CreatureLibLibrary PUBLIC ${_LIBRARYLINKS})
target_link_libraries(CreatureLibBattling PUBLIC ${_BATTLINGLINKS})
2019-10-06 11:50:52 +00:00
2020-07-17 11:12:21 +00:00
if (TESTS)
2020-05-02 13:55:31 +00:00
# Create Test executable
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
add_executable(CreatureLibTests ${TEST_FILES} extern/catch.hpp)
2020-07-17 11:12:21 +00:00
target_link_libraries(CreatureLibTests PUBLIC CreatureLibLibrary CreatureLibBattling Arbutils)
2020-05-02 13:55:31 +00:00
# Add a definition for the test library
target_compile_definitions(CreatureLibTests PRIVATE TESTS_BUILD)
2020-05-02 13:55:31 +00:00
endif ()