Skip to content

Commit

Permalink
CMake: add install target and other improvements:
Browse files Browse the repository at this point in the history
- Add options BUILD_TESTING and BUILD_PROGRAMS.
- Set CMAKE_DEBUG_POSTFIX.
- Use CMAKE_CXX_FLAGS_DEBUG instead of checking CMAKE_BUILD_TYPE.
- Don't set optimization flags (reversed).
- Don't add -pthread.
  • Loading branch information
tamaskenez committed Sep 4, 2019
1 parent e7c5da0 commit 2573a7f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
cmake_minimum_required(VERSION 3.9)
project(csv)

option(BUILD_TESTING "Build tests" ON)
option(BUILD_PROGRAMS "Build programs" ON)

if(CSV_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${CSV_CXX_STANDARD})
else()
set(CMAKE_CXX_STANDARD 17)
endif(CSV_CXX_STANDARD)

set(CMAKE_DEBUG_POSTFIX _d)

message("Building CSV library using C++${CMAKE_CXX_STANDARD}")

# Defines CSV_HAS_CXX17 in compatibility.hpp
Expand All @@ -17,18 +22,11 @@ if(MSVC)
# See: https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
set(CMAKE_CXX_FLAGS "/EHsc /Zc:__cplusplus")

if(CMAKE_BUILD_TYPE MATCHES Debug)
# /Wall emits warnings about the C++ standard library
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
# /Wall emits warnings about the C++ standard library
set(CMAKE_CXX_FLAGS_DEBUG "/W4")
else()
# Ignore Visual Studio pragma regions
set(CMAKE_CXX_FLAGS "-pthread -Wno-unknown-pragmas")
if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Og -g")
endif()
set(CMAKE_CXX_FLAGS "-Wno-unknown-pragmas")
endif(MSVC)

set(CSV_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR})
Expand All @@ -48,7 +46,9 @@ endif()
add_subdirectory(${CSV_SOURCE_DIR})

## Executables
add_subdirectory("programs")
if(BUILD_PROGRAMS)
add_subdirectory("programs")
endif()

## Developer settings
if (CSV_DEVELOPER)
Expand All @@ -75,6 +75,8 @@ if (CSV_DEVELOPER)
endif()

## Tests
enable_testing()
add_subdirectory("tests")
if(BUILD_TESTING)
enable_testing()
add_subdirectory("tests")
endif()
endif()
31 changes: 30 additions & 1 deletion include/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,33 @@ target_sources(csv
row_buffer.cpp
)

set_target_properties(csv PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties(csv PROPERTIES LINKER_LANGUAGE CXX)

if(CSV_DEVELOPER)
target_include_directories(csv
PUBLIC
$<INSTALL_INTERFACE:include>
)

install(TARGETS csv EXPORT csv-targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)

set(NAMESPACE "vincentlaucsb")
set(PKG_NAME "${NAMESPACE}-csv")

install(EXPORT csv-targets
DESTINATION lib/cmake/${PKG_NAME}
NAMESPACE "${NAMESPACE}::"
FILE ${PKG_NAME}-config.cmake
)

install(DIRECTORY ../external ../internal
DESTINATION include/${PKG_NAME}
FILES_MATCHING PATTERN *.h PATTERN *.hpp
)

install(FILES ../csv.hpp DESTINATION include/${PKG_NAME})
endif()

0 comments on commit 2573a7f

Please sign in to comment.