Arbutils/CMakeLists.txt

54 lines
2.0 KiB
CMake

cmake_minimum_required(VERSION 3.13)
project(Arbutils)
# 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.
set(CMAKE_CXX_STANDARD 20)
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)
# Set whether we want a static or shared library.
set(LIBTYPE STATIC)
if (SHARED)
set(LIBTYPE SHARED)
endif (SHARED)
# Grab all cpp and hpp files in our source directories.
file(GLOB_RECURSE SRC_FILES "src/*.cpp" "src/*.hpp" "CInterface/*.cpp")
add_library(Arbutils ${LIBTYPE} ${SRC_FILES})
if (TESTS)
# If we want a tests executable, grab all tests source files
file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp")
# And create an executable from it. Also include catch.hpp.
add_executable(ArbutilsTests ${TEST_FILES} extern/catch.hpp)
# And finally link the library to the executable.
target_link_libraries(ArbutilsTests Arbutils)
# Add a compilation definition to the code that we are building a test build.
target_compile_definitions(ArbutilsTests PRIVATE TESTS_BUILD)
endif ()
# If we are building for Windows we need to set some specific variables.
if (WINDOWS)
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)
endif (WINDOWS)
# If we want to link the C and C++ library statically, link those as well.
if (STATICC)
target_link_libraries(Arbutils -static-libgcc -static-libstdc++)
endif(STATICC)
# If we aren't building for Windows, also include an option for installing on unix.
if (NOT WINDOWS)
install(TARGETS Arbutils
CONFIGURATIONS Release
RUNTIME DESTINATION lib)
endif()