Browse Source

fix: Adapt CMake scripts to new project file structure

We've also solved several issues related to Linux/Windows build errors.
The CMake script can generate the amalgamation distribution, and we can
choose whether to use the amalgamation or not.
pull/31/head
Tom G. Huang 6 years ago
parent
commit
24af833794
  1. 73
      CMakeLists.txt
  2. 66
      examples/CMakeLists.txt
  3. 38
      examples/CMakeLists.txt.sample
  4. 43
      src/CMakeLists.txt
  5. 31
      tests/CMakeLists.txt

73
CMakeLists.txt

@ -1,7 +1,7 @@
################################################################################
# This file is part of the argtable3 library.
#
# Copyright (C) 2019 Tom G. Huang
# Copyright (C) 2016-2019 Tom G. Huang
# <tomghuang@gmail.com>
# All rights reserved.
#
@ -28,34 +28,73 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.0)
file(STRINGS "version.txt" VERSION)
project(argtable3 VERSION "${VERSION}")
set(ARGTABLE3_PROJECT_NAME "argtable3")
set(ARGTABLE3_PACKAGE_NAME "Argtable3")
file(STRINGS "version.txt" ARGTABLE3_VERSION)
option(CONAN "Enable Conan dependency manager" ON)
option(BUILD_SHARED_LIBS "Build shared library when enabled, static otherwise" ON)
option(argtable3_build_tests "Build argtable3 unit tests." ON)
option(argtable3_build_examples "Build argtable3 examples." ON)
project(${ARGTABLE3_PROJECT_NAME} VERSION "${ARGTABLE3_VERSION}")
if (CONAN AND EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
option(ARGTABLE3_ENABLE_CONAN "Enable Conan dependency manager" OFF)
option(ARGTABLE3_ENABLE_TESTS "Enable unit tests" ON)
option(ARGTABLE3_USE_AMALGAMATION "Use the amalgamation distribution" OFF)
if(ARGTABLE3_ENABLE_CONAN AND EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake")
conan_basic_setup(TARGETS)
string(REPLACE ";" ":" LINK_FLAGS "${CONAN_LIB_DIRS}")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-rpath-link,${LINK_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath-link,${LINK_FLAGS}")
endif ()
add_subdirectory(src)
endif()
if(argtable3_build_tests)
if(ARGTABLE3_ENABLE_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
if(argtable3_build_examples)
add_subdirectory(examples)
if(ARGTABLE3_USE_AMALGAMATION)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/dist/argtable3.c")
execute_process(
COMMAND "${CMAKE_SOURCE_DIR}/tools/build" dist
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/tools"
)
endif()
set(ARGTABLE3_SRC_FILES
${CMAKE_SOURCE_DIR}/dist/argtable3.c
)
else()
set(ARGTABLE3_SRC_FILES
${CMAKE_SOURCE_DIR}/src/arg_cmd.c
${CMAKE_SOURCE_DIR}/src/arg_date.c
${CMAKE_SOURCE_DIR}/src/arg_dbl.c
${CMAKE_SOURCE_DIR}/src/arg_dstr.c
${CMAKE_SOURCE_DIR}/src/arg_end.c
${CMAKE_SOURCE_DIR}/src/arg_file.c
${CMAKE_SOURCE_DIR}/src/arg_hashtable.c
${CMAKE_SOURCE_DIR}/src/arg_int.c
${CMAKE_SOURCE_DIR}/src/arg_lit.c
${CMAKE_SOURCE_DIR}/src/arg_rem.c
${CMAKE_SOURCE_DIR}/src/arg_rex.c
${CMAKE_SOURCE_DIR}/src/arg_str.c
${CMAKE_SOURCE_DIR}/src/arg_utils.c
${CMAKE_SOURCE_DIR}/src/argtable3.c
${CMAKE_SOURCE_DIR}/src/getopt_long.c
)
endif()
install(EXPORT ${PROJECT_NAME}-config DESTINATION lib/cmake/${PROJECT_NAME})
# Platform specific settings for installation
if(UNIX)
include(GNUInstallDirs)
set(ARGTABLE3_INSTALL_LIBDIR ${CMAKE_INSTALL_LIBDIR})
set(ARGTABLE3_INSTALL_INCLUDEDIR ${CMAKE_INSTALL_INCLUDEDIR})
set(ARGTABLE3_INSTALL_CMAKEDIR ${ARGTABLE3_LIBDIR}/cmake)
elseif(WIN32)
set(ARGTABLE3_INSTALL_LIBDIR "lib")
set(ARGTABLE3_INSTALL_INCLUDEDIR "include")
set(ARGTABLE3_INSTALL_CMAKEDIR "cmake")
endif(UNIX)
add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(examples)

66
examples/CMakeLists.txt

@ -1,7 +1,7 @@
################################################################################
# This file is part of the argtable3 library.
#
# Copyright (C) 2016-2017 Tom G. Huang
# Copyright (C) 2016-2019 Tom G. Huang
# <tomghuang@gmail.com>
# All rights reserved.
#
@ -28,36 +28,50 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_executable(echo echo.c ${ARGTABLE3_SRC_FILES})
target_include_directories(echo PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(echo m)
endif()
add_executable(echo echo.c)
target_link_libraries(echo argtable3)
add_executable(ls ls.c)
target_link_libraries(ls argtable3)
add_executable(multisyntax multisyntax.c)
target_link_libraries(multisyntax argtable3)
add_executable(ls ls.c ${ARGTABLE3_SRC_FILES})
target_include_directories(ls PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(ls m)
endif()
add_executable(mv mv.c)
target_link_libraries(mv argtable3)
add_executable(multisyntax multisyntax.c ${ARGTABLE3_SRC_FILES})
target_include_directories(multisyntax PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(multisyntax m)
endif()
add_executable(myprog myprog.c)
target_link_libraries(myprog argtable3)
add_executable(mv mv.c ${ARGTABLE3_SRC_FILES})
target_include_directories(mv PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(mv m)
endif()
add_executable(myprog_C89 myprog_C89.c)
target_link_libraries(myprog_C89 argtable3)
add_executable(myprog myprog.c ${ARGTABLE3_SRC_FILES})
target_include_directories(myprog PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(myprog m)
endif()
add_executable(testargtable3 testargtable3.c)
target_link_libraries(testargtable3 argtable3)
add_executable(myprog_C89 myprog_C89.c ${ARGTABLE3_SRC_FILES})
target_include_directories(myprog_C89 PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(myprog_C89 m)
endif()
add_executable(uname uname.c)
target_link_libraries(uname argtable3)
add_executable(testargtable3 testargtable3.c ${ARGTABLE3_SRC_FILES})
target_include_directories(testargtable3 PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(testargtable3 m)
endif()
install(DIRECTORY "${CMAKE_CURRENT_LIST_DIR}" DESTINATION share/argtable3
PATTERN CMakeLists.txt* EXCLUDE)
install(FILES "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt.sample" DESTINATION share/argtable3/examples
RENAME CMakeLists.txt)
add_executable(uname uname.c ${ARGTABLE3_SRC_FILES})
target_include_directories(uname PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(uname m)
endif()

38
examples/CMakeLists.txt.sample

@ -1,38 +0,0 @@
################################################################################
# This file is part of the argtable3 library.
#
# Copyright (C) 2018 Tom G. Huang
# <tomghuang@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of STEWART HEITMANN nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
cmake_minimum_required(VERSION 3.0)
project(ArgTable3Sample)
find_package(argtable3 REQUIRED)
add_executable(testargtable3 testargtable3.c)
target_link_libraries(testargtable3 argtable3)

43
src/CMakeLists.txt

@ -1,7 +1,36 @@
add_library(argtable3 argtable3.c)
target_include_directories(argtable3 PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}>
$<INSTALL_INTERFACE:include>
)
install(TARGETS argtable3 EXPORT ${PROJECT_NAME}-config DESTINATION lib)
install(FILES "${CMAKE_CURRENT_LIST_DIR}/argtable3.h" DESTINATION include)
################################################################################
# This file is part of the argtable3 library.
#
# Copyright (C) 2016-2019 Tom G. Huang
# <tomghuang@gmail.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of STEWART HEITMANN nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL STEWART HEITMANN BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
add_library(argtable3 SHARED ${ARGTABLE3_SRC_FILES})
target_include_directories(argtable3 PRIVATE ${CMAKE_SOURCE_DIR}/src)
install(TARGETS argtable3 EXPORT ${ARGTABLE3_PACKAGE_NAME}Config DESTINATION ${ARGTABLE3_INSTALL_LIBDIR})
install(FILES "${CMAKE_CURRENT_LIST_DIR}/argtable3.h" DESTINATION ${ARGTABLE3_INSTALL_INCLUDEDIR})
install(EXPORT ${ARGTABLE3_PACKAGE_NAME}Config DESTINATION ${ARGTABLE3_INSTALL_CMAKEDIR})

31
tests/CMakeLists.txt

@ -28,13 +28,6 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
################################################################################
cmake_minimum_required(VERSION 2.8.0)
project(tests)
include_directories(
${PROJECT_SOURCE_DIR}
)
set(TEST_SRC_FILES
testall.c
testarglit.c
@ -48,23 +41,13 @@ set(TEST_SRC_FILES
testargdstr.c
testargcmd.c
CuTest.c
../src/arg_cmd.c
../src/arg_date.c
../src/arg_dbl.c
../src/arg_dstr.c
../src/arg_end.c
../src/arg_file.c
../src/arg_hashtable.c
../src/arg_int.c
../src/arg_lit.c
../src/arg_rem.c
../src/arg_rex.c
../src/arg_str.c
../src/arg_utils.c
../src/argtable3.c
../src/getopt_long.c
${ARGTABLE3_SRC_FILES}
)
add_executable(testall ${TEST_SRC_FILES})
target_include_directories(testall PRIVATE ../src)
add_test(NAME testall COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} "$<TARGET_FILE:testall>")
target_include_directories(testall PRIVATE ${CMAKE_SOURCE_DIR}/src)
if(UNIX)
target_link_libraries(testall m)
endif()
add_test(NAME testall COMMAND "$<TARGET_FILE:testall>")

Loading…
Cancel
Save