Skip to content

Commit

Permalink
Use the BUILD_STATIC_LIBS setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mmahnic committed Dec 27, 2019
1 parent 819a76e commit c08c829
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 53 deletions.
16 changes: 13 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ cmake_minimum_required( VERSION 3.1 )

project( Argumentum VERSION 0.2.0 )

option( ARGUMENTUM_BUILD_EXAMPLES "build examples" OFF )
option( ARGUMENTUM_BUILD_TESTS "build tests" OFF )
option( ARGUMENTUM_PEDANTIC "treat warnings as errors (TODO)" OFF )
option( BUILD_STATIC_LIBS "Build static libraries" ON )
option( ARGUMENTUM_BUILD_EXAMPLES "Build examples" OFF )
option( ARGUMENTUM_BUILD_TESTS "Build tests" OFF )
option( ARGUMENTUM_PEDANTIC "Treat warnings as errors (TODO)" OFF )

if( BUILD_SHARED_LIBS )
message( FATAL_ERROR "Shared libries are not supported ATM" )
endif()

set( CMAKE_CXX_STANDARD 17 )
set( CMAKE_DEBUG_POSTFIX d )

include( GNUInstallDirs )

# The name of the published static library target.
set( ARGUMENTUM_STATIC_NAME argumentum-s )

# The name of the internal static library target used for instutil, tests, examples.
set( ARGUMENTUM_INTERNAL_NAME argumentum-si )

add_subdirectory( src )
add_subdirectory( util )
add_subdirectory( include )
Expand Down
12 changes: 7 additions & 5 deletions cmake/InstallConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ write_basic_package_version_file( ${version_file}
COMPATIBILITY AnyNewerVersion
)

install(
EXPORT ${targets_export_name}
NAMESPACE ${cmake_package_name}::
DESTINATION ${cmake_files_install_dir}
)
if( BUILD_STATIC_LIBS )
install(
EXPORT ${targets_export_name}
NAMESPACE ${cmake_package_name}::
DESTINATION ${cmake_files_install_dir}
)
endif()

configure_package_config_file(
${config_file_in}
Expand Down
2 changes: 1 addition & 1 deletion doc/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The recommended way to consume the library is build and link the static
library. A dynamic version is planned.

The library will also be available in VCPKG ([pull request](TODO)).
The library will also be available in VCPKG ([pull request](https://github.com/microsoft/vcpkg/pull/9477)).

If building is not an option, the library can be used as header-only by cloning
the repository and using the appropriate include path.
Expand Down
26 changes: 13 additions & 13 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

include_directories( ../include )
set ( ARGUMENTUM_EXAMPLE_LIB ${ARGUMENTUM_STATIC_NAME} )
set( argumentum_example_lib ${ARGUMENTUM_INTERNAL_NAME} )

# The library is currently header-only.
set(PARSER_SOURCES
Expand All @@ -11,47 +11,47 @@ add_executable( basic
basic.cpp
)
target_link_libraries( basic
${ARGUMENTUM_EXAMPLE_LIB}
${argumentum_example_lib}
)
add_dependencies( basic ${ARGUMENTUM_EXAMPLE_LIB} )
add_dependencies( basic ${argumentum_example_lib} )

add_executable( basic_action
basic_action.cpp
)
target_link_libraries( basic_action
${ARGUMENTUM_EXAMPLE_LIB}
${argumentum_example_lib}
)
add_dependencies( basic_action ${ARGUMENTUM_EXAMPLE_LIB} )
add_dependencies( basic_action ${argumentum_example_lib} )

add_executable( basic_struct
basic_struct.cpp
)
target_link_libraries( basic_struct
${ARGUMENTUM_EXAMPLE_LIB}
${argumentum_example_lib}
)
add_dependencies( basic_struct ${ARGUMENTUM_EXAMPLE_LIB} )
add_dependencies( basic_struct ${argumentum_example_lib} )

add_executable( basic_command
basic_command.cpp
)
target_link_libraries( basic_command
${ARGUMENTUM_EXAMPLE_LIB}
${argumentum_example_lib}
)
add_dependencies( basic_command ${ARGUMENTUM_EXAMPLE_LIB} )
add_dependencies( basic_command ${argumentum_example_lib} )

add_executable( example1
example1.cpp
)
target_link_libraries( example1
${ARGUMENTUM_EXAMPLE_LIB}
${argumentum_example_lib}
)
add_dependencies( example1 ${ARGUMENTUM_EXAMPLE_LIB} )
add_dependencies( example1 ${argumentum_example_lib} )

add_executable( example2
example2.cpp
)
target_link_libraries( example2
${ARGUMENTUM_EXAMPLE_LIB}
${argumentum_example_lib}
)
add_dependencies( example2 ${ARGUMENTUM_EXAMPLE_LIB} )
add_dependencies( example2 ${argumentum_example_lib} )

31 changes: 23 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@

set( static_library_name ${ARGUMENTUM_STATIC_NAME} )
set( internal_library_name ${ARGUMENTUM_INTERNAL_NAME} )
set( target_list_name ${PROJECT_NAME}Targets )

add_library( ${static_library_name} STATIC
# The published static library
if ( BUILD_STATIC_LIBS )
add_library( ${static_library_name} STATIC
argparser.cpp
)
if( ARGUMENTUM_PEDANTIC )
target_compile_options( ${static_library_name} PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall>
$<$<CXX_COMPILER_ID:MSVC>:/WX /permissive- /Za>
)
endif()

install( TARGETS ${static_library_name}
EXPORT ${target_list_name}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

# The static library used for internal purposes: instutil, tests, examples.
add_library( ${internal_library_name} STATIC
argparser.cpp
)
if( ARGUMENTUM_PEDANTIC )
target_compile_options( ${static_library_name} PRIVATE
target_compile_options( ${internal_library_name} PRIVATE
$<$<CXX_COMPILER_ID:GNU>:-Werror -Wall>
$<$<CXX_COMPILER_ID:MSVC>:/WX /permissive- /Za>
)
endif()

install( TARGETS ${static_library_name}
EXPORT ${target_list_name}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

include_directories( ../include )
set ( argumentum_test_lib ${ARGUMENTUM_STATIC_NAME} )
set ( argumentum_test_lib ${ARGUMENTUM_INTERNAL_NAME} )

find_package( GTest REQUIRED )
find_package( Threads REQUIRED )
Expand Down
43 changes: 22 additions & 21 deletions test/staticlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@

include_directories( ../../include )
if ( BUILD_STATIC_LIBS )
include_directories( ../../include )

find_package( GTest REQUIRED )
find_package( Threads REQUIRED )
find_package( GTest REQUIRED )
find_package( Threads REQUIRED )

add_executable( staticLibraryTest
runtest.cpp
../testutil.cpp
basic_command_t.cpp
)
add_executable( staticLibraryTest
runtest.cpp
../testutil.cpp
basic_command_t.cpp
)

target_link_libraries( staticLibraryTest
${GTEST_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${ARGUMENTUM_STATIC_NAME}
)
add_dependencies( staticLibraryTest ${ARGUMENTUM_STATIC_NAME} )

add_test(
NAME
staticlib
COMMAND
${CMAKE_BINARY_DIR}/test/staticlib/staticLibraryTest
)
target_link_libraries( staticLibraryTest
${GTEST_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${ARGUMENTUM_STATIC_NAME}
)
add_dependencies( staticLibraryTest ${ARGUMENTUM_STATIC_NAME} )

add_test(
NAME
staticlib
COMMAND
${CMAKE_BINARY_DIR}/test/staticlib/staticLibraryTest
)
endif()
2 changes: 1 addition & 1 deletion util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

include_directories( ../include )
set ( argumentum_util_lib ${ARGUMENTUM_STATIC_NAME} )
set ( argumentum_util_lib ${ARGUMENTUM_INTERNAL_NAME} )

set(CMAKE_CXX_STANDARD 17)

Expand Down

0 comments on commit c08c829

Please sign in to comment.