CreatureLib/CMakeLists.txt

86 lines
3.5 KiB
CMake

cmake_minimum_required(VERSION 3.13)
# Make warnings trigger errors.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")
project(CreatureLib)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if (NOT EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
message(WARNING "The file conanbuildinfo.cmake doesn't exist, running conan install.")
string(REPLACE "." ";" VERSION_LIST "${CMAKE_C_COMPILER_VERSION}")
list(GET VERSION_LIST 0 VERSION)
list(GET VERSION_LIST 1 MINOR)
if (NOT MINOR MATCHES 0)
SET(VERSION ${VERSION}.${MINOR})
endif ()
if (NOT WINDOWS)
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing
-s compiler=clang -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION})
else ()
execute_process(COMMAND conan install ${CMAKE_SOURCE_DIR} --install-folder=${CMAKE_BINARY_DIR} --build missing
-s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=${VERSION} -s os=Windows)
endif ()
endif ()
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
if (WINDOWS)
ADD_DEFINITIONS(-D WINDOWS=1)
endif (WINDOWS)
# Create Core library with files in src/Core
file(GLOB_RECURSE CORE_SRC_FILES "src/Core/*.cpp" "src/Core/*.hpp" "CInterface/Core/*.cpp")
add_library(CreatureLibCore SHARED ${CORE_SRC_FILES})
set_target_properties(CreatureLibCore PROPERTIES LINKER_LANGUAGE CXX)
# Create main Library library with files in src/Library
file(GLOB_RECURSE LIBRARY_SRC_FILES "src/Library/*.cpp" "src/Library/*.hpp" "CInterface/Library/*.cpp")
add_library(CreatureLibLibrary SHARED ${LIBRARY_SRC_FILES})
# Create Battling library with files in src/Battling
file(GLOB_RECURSE BATTLING_SRC_FILES "src/Battling/*.cpp" "src/Battling/*.hpp" "CInterface/Battling/*.cpp")
add_library(CreatureLibBattling SHARED ${BATTLING_SRC_FILES})
if (NOT DEFINED CONAN_EXPORTED)
# Create Test executable
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
add_executable(CreatureLibTests ${TEST_FILES} extern/catch.hpp)
endif ()
# Link the core library to the individual other libraries
target_link_libraries(CreatureLibLibrary CreatureLibCore)
target_link_libraries(CreatureLibBattling CreatureLibCore)
# Link the library data to the Battling library
target_link_libraries(CreatureLibBattling CreatureLibLibrary)
target_link_libraries(CreatureLibCore Arbutils)
target_link_libraries(CreatureLibLibrary Arbutils)
target_link_libraries(CreatureLibBattling Arbutils)
if (NOT DEFINED CONAN_EXPORTED)
target_link_libraries(CreatureLibTests CreatureLibLibrary)
target_link_libraries(CreatureLibTests CreatureLibBattling)
endif ()
if (WINDOWS)
MESSAGE(WARNING, "Using Windows Build.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L ${CMAKE_BINARY_DIR}/bin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64 -Wa,-mbig-obj -Wl,-allow-multiple-definition")
# Statically link libraries we need in Windows.
target_link_libraries(CreatureLibCore -static-libgcc -static-libstdc++)
target_link_libraries(CreatureLibLibrary -static-libgcc -static-libstdc++)
target_link_libraries(CreatureLibBattling -static-libgcc -static-libstdc++)
if (NOT DEFINED CONAN_EXPORTED)
target_link_libraries(CreatureLibTests -static-libgcc -static-libstdc++)
endif ()
endif (WINDOWS)
if (NOT DEFINED CONAN_EXPORTED)
MESSAGE(WARNING, "Called from Conan. Not building test build.")
# Add a definition for the test library
target_compile_definitions(CreatureLibTests PRIVATE TESTS_BUILD)
endif ()