2020-02-26 12:02:02 +00:00
|
|
|
cmake_minimum_required(VERSION 3.13)
|
2020-02-26 11:57:18 +00:00
|
|
|
project(Arbutils)
|
|
|
|
|
2020-07-17 10:15:32 +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 13:56:00 +00:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
2020-02-26 11:57:18 +00:00
|
|
|
|
2020-07-17 10:15:32 +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-02 13:30:25 +00:00
|
|
|
|
2020-07-17 10:15:32 +00:00
|
|
|
# Set whether we want a static or shared library.
|
2020-05-02 13:30:25 +00:00
|
|
|
set(LIBTYPE STATIC)
|
2020-05-02 10:31:04 +00:00
|
|
|
if (SHARED)
|
2020-07-17 10:15:32 +00:00
|
|
|
set(LIBTYPE SHARED)
|
|
|
|
endif (SHARED)
|
2020-02-26 11:57:18 +00:00
|
|
|
|
2020-07-17 10:15:32 +00:00
|
|
|
# Grab all cpp and hpp files in our source directories.
|
2020-07-19 09:08:05 +00:00
|
|
|
file(GLOB_RECURSE SRC_FILES "src/*.cpp" "src/*.hpp" "CInterface/*.cpp" "CInterface/*.hpp")
|
2020-07-17 10:15:32 +00:00
|
|
|
add_library(Arbutils ${LIBTYPE} ${SRC_FILES})
|
2020-07-12 13:06:20 +00:00
|
|
|
|
2020-07-17 10:15:32 +00:00
|
|
|
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.
|
2020-07-12 13:06:20 +00:00
|
|
|
add_executable(ArbutilsTests ${TEST_FILES} extern/catch.hpp)
|
2020-07-17 10:15:32 +00:00
|
|
|
# And finally link the library to the executable.
|
2020-07-12 13:06:20 +00:00
|
|
|
target_link_libraries(ArbutilsTests Arbutils)
|
2020-07-17 10:15:32 +00:00
|
|
|
# Add a compilation definition to the code that we are building a test build.
|
|
|
|
target_compile_definitions(ArbutilsTests PRIVATE TESTS_BUILD)
|
|
|
|
endif ()
|
2020-07-12 13:06:20 +00:00
|
|
|
|
2020-07-17 10:15:32 +00:00
|
|
|
# If we are building for Windows we need to set some specific variables.
|
2020-07-10 12:12:22 +00:00
|
|
|
if (WINDOWS)
|
|
|
|
MESSAGE(WARNING, "Using Windows Build.")
|
2020-07-17 10:15:32 +00:00
|
|
|
# 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)
|
2020-07-10 12:12:22 +00:00
|
|
|
endif (WINDOWS)
|
|
|
|
|
2020-07-17 10:15:32 +00:00
|
|
|
# If we want to link the C and C++ library statically, link those as well.
|
2020-07-10 12:12:22 +00:00
|
|
|
if (STATICC)
|
2020-07-12 11:36:20 +00:00
|
|
|
target_link_libraries(Arbutils -static-libgcc -static-libstdc++)
|
2020-07-12 13:06:20 +00:00
|
|
|
endif(STATICC)
|
2020-02-26 11:57:18 +00:00
|
|
|
|
2020-07-17 10:15:32 +00:00
|
|
|
# If we aren't building for Windows, also include an option for installing on unix.
|
2020-03-11 10:50:56 +00:00
|
|
|
if (NOT WINDOWS)
|
|
|
|
install(TARGETS Arbutils
|
|
|
|
CONFIGURATIONS Release
|
|
|
|
RUNTIME DESTINATION lib)
|
|
|
|
endif()
|