better cmake
This commit is contained in:
parent
729d23a1e9
commit
28461d9bbf
@ -1,23 +1,57 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
project(flags-cpp)
|
||||
|
||||
set(CMAKE_CXX_COMPILER clang++)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20 -Wall -Wextra -Werror")
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS true)
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable -Wno-unused-private-field")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-variable -Wno-unused-private-field")
|
||||
|
||||
if(DEBUG)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -DDEBUG")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -DDEBUG")
|
||||
endif()
|
||||
|
||||
file(GLOB_RECURSE SOURCES "${CMAKE_SOURCE_DIR}/src/flags-cpp/*.cpp")
|
||||
file(GLOB_RECURSE HEADERS "${CMAKE_SOURCE_DIR}/inc/flags-cpp/*.h")
|
||||
|
||||
include_directories("${CMAKE_SOURCE_DIR}/inc")
|
||||
|
||||
add_library(flags-cpp OBJECT ${SOURCES})
|
||||
set_target_properties(flags-cpp PROPERTIES POSITION_INDEPENDENT_CODE 1)
|
||||
target_include_directories(flags-cpp PUBLIC "${CMAKE_SOURCE_DIR}/inc")
|
||||
|
||||
add_library(flags-cpp-static STATIC $<TARGET_OBJECTS:flags-cpp>)
|
||||
set_target_properties(flags-cpp-static PROPERTIES OUTPUT_NAME flags-cpp)
|
||||
target_include_directories(flags-cpp-static PUBLIC "${CMAKE_SOURCE_DIR}/inc")
|
||||
|
||||
add_library(flags-cpp-shared SHARED $<TARGET_OBJECTS:flags-cpp>)
|
||||
target_link_libraries(flags-cpp-shared -static-libgcc -static-libstdc++)
|
||||
set_target_properties(flags-cpp-shared PROPERTIES OUTPUT_NAME flags-cpp)
|
||||
target_include_directories(flags-cpp-shared PUBLIC "${CMAKE_SOURCE_DIR}/inc")
|
||||
|
||||
add_executable(example "${CMAKE_SOURCE_DIR}/src/main.cpp")
|
||||
target_link_libraries(example flags-cpp-shared)
|
||||
|
||||
install(TARGETS
|
||||
flags-cpp-static
|
||||
flags-cpp-shared
|
||||
RUNTIME
|
||||
COMPONENT Runtime
|
||||
LIBRARY
|
||||
COMPONENT Runtime
|
||||
ARCHIVE
|
||||
COMPONENT Development
|
||||
)
|
||||
install(FILES ${HEADERS} DESTINATION include/flags-cpp COMPONENT Development)
|
||||
|
||||
install(TARGETS
|
||||
flags-cpp-static
|
||||
flags-cpp-shared
|
||||
EXPORT flags-cpp-targets
|
||||
DESTINATION lib
|
||||
)
|
||||
|
||||
install(EXPORT flags-cpp-targets
|
||||
FILE FlagsCppConfig.cmake
|
||||
DESTINATION lib/cmake/FlagsCpp
|
||||
)
|
Loading…
Reference in New Issue
Block a user