atomorph/CMakeLists.txt

47 lines
1.3 KiB
CMake

cmake_minimum_required(VERSION 3.16)
project("atomorph")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_compile_options(-Wall -Wextra -Werror)
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)
if (NOT WINDOWS)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
else()
set(CMAKE_POSITION_INDEPENDENT_CODE OFF)
endif()
set(LIBTYPE STATIC)
if (SHARED)
set(LIBTYPE SHARED)
endif (SHARED)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_link_options(-fuse-ld=lld)
endif ()
file(GLOB_RECURSE SRC_FILES "src/*.cpp")
add_library(atomorph ${LIBTYPE} ${SRC_FILES})
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)
if (SHARED)
set_target_properties(atomorph PROPERTIES SUFFIX ".dll")
endif()
endif (WINDOWS)
if (STATICC)
message("Linking dependencies statically.")
set (CMAKE_SHARED_LINKER_FLAGS "-Wl,--as-needed")
set(LINKS -static-libgcc -static-libstdc++ -Wl,-Bstatic -lm -lstdc++ -lpthread -Wl,-Bdynamic ${LINKS})
endif(STATICC)
target_link_libraries(atomorph ${LINKS})