feat: initial commit
This commit is contained in:
commit
c18a85f1cc
7 changed files with 153 additions and 0 deletions
56
CMakeLists.txt
Normal file
56
CMakeLists.txt
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
project(merk LANGUAGES C CXX)
|
||||
|
||||
# Standards
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
option(BUILD_SHARED_LIBS "Build shared libraries by default" OFF)
|
||||
|
||||
# Collect all source files under src/ (recursively).
|
||||
# CONFIGURE_DEPENDS makes CMake re-scan when files are added/removed.
|
||||
file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS
|
||||
"${CMAKE_SOURCE_DIR}/src/*.c"
|
||||
"${CMAKE_SOURCE_DIR}/src/*.cc"
|
||||
"${CMAKE_SOURCE_DIR}/src/*.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/*.cxx")
|
||||
|
||||
# Decide: executable (if src/main.* exists) or library (otherwise).
|
||||
set(MAIN_CANDIDATES
|
||||
"${CMAKE_SOURCE_DIR}/src/main.c"
|
||||
"${CMAKE_SOURCE_DIR}/src/main.cc"
|
||||
"${CMAKE_SOURCE_DIR}/src/main.cpp"
|
||||
"${CMAKE_SOURCE_DIR}/src/main.cxx")
|
||||
set(HAVE_MAIN FALSE)
|
||||
foreach(f IN LISTS MAIN_CANDIDATES)
|
||||
if(EXISTS "${f}")
|
||||
set(HAVE_MAIN TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
if(HAVE_MAIN)
|
||||
add_executable(merk ${PROJECT_SOURCES})
|
||||
set(TARGET_NAME merk)
|
||||
else()
|
||||
add_library(${PROJECT_NAME} ${PROJECT_SOURCES})
|
||||
set(TARGET_NAME ${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
# Public headers live in ./include
|
||||
target_include_directories(${TARGET_NAME}
|
||||
PUBLIC "${CMAKE_SOURCE_DIR}/include"
|
||||
)
|
||||
|
||||
# Sensible warnings
|
||||
if(MSVC)
|
||||
target_compile_options(${TARGET_NAME} PRIVATE /W4 /permissive-)
|
||||
else()
|
||||
target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -Wpedantic)
|
||||
endif()
|
||||
|
||||
# Put built artifacts under build/bin and build/lib
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue