clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

CMakeLists.txt (5367B)


      1 cmake_minimum_required(VERSION 3.17)
      2 enable_testing()
      3 
      4 # Extract the version from header file
      5 file(READ "include/clap/version.h" clap_version_header)
      6 string(REGEX MATCH "CLAP_VERSION_MAJOR ([0-9]+)" _ ${clap_version_header})
      7 set(CLAP_VERSION_MAJOR ${CMAKE_MATCH_1})
      8 string(REGEX MATCH "CLAP_VERSION_MINOR ([0-9]+)" _ ${clap_version_header})
      9 set(CLAP_VERSION_MINOR ${CMAKE_MATCH_1})
     10 string(REGEX MATCH "CLAP_VERSION_REVISION ([0-9]+)" _ ${clap_version_header})
     11 set(CLAP_VERSION_REVISION ${CMAKE_MATCH_1})
     12 
     13 message(STATUS "CLAP version: ${CLAP_VERSION_MAJOR}.${CLAP_VERSION_MINOR}.${CLAP_VERSION_REVISION}")
     14 
     15 project(CLAP LANGUAGES C CXX VERSION ${CLAP_VERSION_MAJOR}.${CLAP_VERSION_MINOR}.${CLAP_VERSION_REVISION})
     16 
     17 option(CLAP_BUILD_TESTS "Should CLAP build tests and the like?" OFF)
     18 
     19 # If you use clap as a submodule of your plugin you need some interface projects
     20 # to allow you to link
     21 add_library(clap INTERFACE)
     22 target_include_directories(clap INTERFACE
     23     $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
     24     $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
     25 
     26 # `clap-core` is deprecated, please `clap` instead.
     27 add_library(clap-core ALIAS clap)
     28 
     29 include(GNUInstallDirs)
     30 install(DIRECTORY "include/clap" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
     31 install(TARGETS clap EXPORT clap INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
     32 install(EXPORT clap DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/clap" FILE "clap-config.cmake")
     33 
     34 include(CMakePackageConfigHelpers)
     35 write_basic_package_version_file(
     36     "${CMAKE_CURRENT_BINARY_DIR}/clap-config-version.cmake"
     37     VERSION "${PROJECT_VERSION}"
     38     COMPATIBILITY AnyNewerVersion)
     39 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/clap-config-version.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/clap")
     40 
     41 # In addition to the above generated `clap-config.cmake` file, we'll also
     42 # provide a pkg-config file to make it easier to consume this library in a
     43 # portable way
     44 configure_file(clap.pc.in "${CMAKE_CURRENT_BINARY_DIR}/clap.pc" @ONLY)
     45 install(FILES "${CMAKE_CURRENT_BINARY_DIR}/clap.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
     46 
     47 # clap-tests should always be available, to avoid build failing here and there
     48 # because the target doesn't exists
     49 add_custom_target(clap-tests)
     50 
     51 if (${CLAP_BUILD_TESTS})
     52     message(STATUS "Including CLAP tests, compile tests, and versions")
     53     include(CheckIncludeFile)
     54 
     55     macro(clap_compile_cpp SUFFIX EXT STDC STDCPP)
     56         add_executable(clap-compile-${SUFFIX} EXCLUDE_FROM_ALL src/main.${EXT})
     57         target_link_libraries(clap-compile-${SUFFIX} clap)
     58         set_target_properties(clap-compile-${SUFFIX} PROPERTIES
     59             C_STANDARD ${STDC}
     60             CXX_STANDARD ${STDCPP})
     61         add_test(NAME test-clap-compile-${SUFFIX} COMMAND clap-compile-${SUFFIX})
     62         add_dependencies(clap-tests clap-compile-${SUFFIX})
     63 
     64         if (${EXT} STREQUAL "cc")
     65             target_compile_definitions(clap-compile-${SUFFIX} PRIVATE CLAP_COMPILE_TEST_CXX_VERSION=${STDCPP})
     66         endif()
     67 
     68         if (${CMAKE_C_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
     69             target_compile_options(clap-compile-${SUFFIX} PRIVATE -Wall -Wextra -pedantic)
     70         endif()
     71 
     72         if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
     73             target_compile_options(clap-compile-${SUFFIX} PRIVATE -Werror=pragma-pack)
     74         endif()
     75     endmacro()
     76 
     77     clap_compile_cpp(c11    c 11 11)
     78     clap_compile_cpp(cpp11 cc 11 11)
     79     clap_compile_cpp(cpp14 cc 11 14)
     80     if(${CMAKE_VERSION} VERSION_LESS "3.21")
     81        message(STATUS "Skipping C17 tests due to older CMAKE_VERSION ${CMAKE_VERSION}")
     82     else()
     83       clap_compile_cpp(c17    c 17 17)
     84     endif()
     85     clap_compile_cpp(cpp17 cc 17 17)
     86     clap_compile_cpp(cpp20 cc 17 20)
     87 
     88     check_include_file(threads.h CLAP_HAS_THREADS_H)
     89 
     90     add_library(clap-plugin-template MODULE EXCLUDE_FROM_ALL src/plugin-template.c)
     91     target_link_libraries(clap-plugin-template PRIVATE clap)
     92     set_target_properties(clap-plugin-template PROPERTIES C_STANDARD 11)
     93     add_dependencies(clap-tests clap-plugin-template)
     94 
     95     if(CLAP_HAS_THREADS_H)
     96         target_compile_definitions(clap-plugin-template PRIVATE CLAP_HAS_THREADS_H)
     97     endif()
     98 
     99     if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
    100         target_link_libraries(clap-plugin-template PRIVATE -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/linux-my_plug.version)
    101         target_link_libraries(clap-plugin-template PRIVATE -Wl,-z,defs)
    102         set_target_properties(clap-plugin-template PROPERTIES SUFFIX ".clap" PREFIX "")
    103     elseif(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
    104         target_link_options(clap-plugin-template PRIVATE -exported_symbols_list ${CMAKE_CURRENT_SOURCE_DIR}/src/macos-symbols.txt)
    105 
    106         set_target_properties(clap-plugin-template PROPERTIES
    107                     BUNDLE True
    108                     BUNDLE_EXTENSION clap
    109                     MACOSX_BUNDLE_GUI_IDENTIFIER com.my_company.my_plug
    110                     MACOSX_BUNDLE_BUNDLE_NAME my_plug
    111                     MACOSX_BUNDLE_BUNDLE_VERSION "1"
    112                     MACOSX_BUNDLE_SHORT_VERSION_STRING "1"
    113                     MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/src/plugins.plist.in
    114                     )
    115     elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
    116         set_target_properties(clap-plugin-template PROPERTIES SUFFIX ".clap" PREFIX "")
    117     endif()
    118 endif()