【linux】clion的cmakefile文件的一些写法实例

可以看一下这个


# Initial CMake and project setup
#

# Required CMake version (ExternalProject)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
INCLUDE(ExternalProject)
SET(PROJECT_NAME Khronos)
PROJECT(${PROJECT_NAME})

# Set software version
SET(APPLICATION_VERSION_MAJOR "0")
SET(APPLICATION_VERSION_MINOR "4")
SET(APPLICATION_VERSION_PATCH "0")
SET(APPLICATION_VERSION "${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}")

SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
SET_DIRECTORY_PROPERTIES(PROPERTIES EP_PREFIX ${CMAKE_BINARY_DIR}/library-build)

#
# Setup compiler flags
#

if (NOT CMAKE_BUILD_TYPE)
    message(STATUS "No build type selected, default to Release")
    set(CMAKE_BUILD_TYPE Release FORCE)
endif()

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -std=gnu11 -O0 -fprofile-arcs -ftest-coverage")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -std=gnu11 -O3")

if (GCC_VERSION VERSION_GREATER "4.8")
elsif (GCC_VERSION VERSION_GREATER "4.1.2")
    SET (GCC_COMMON_WARNING_FLAGS "-pedantic -Wall -Wextra -Wconversion -Wfloat-equal -Wformat=2 -Winit-self -Winline -Winvalid-pch -Wlogical-op -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wstack-protector -Wstrict-null-sentinel -Wswitch-default -Wswitch-enum")
    SET (GCC_COMMON_WARNING_FLAGS "${GCC_COMMON_WARNING_FLAGS} -Wno-unused-parameter")
    SET (GCC_CXX_WARNING_FLAGS "-Wctor-dtor-privacy")
else ()
    SET(GCC_COMMON_WARNING_FLAGS "-pedantic -Wall -Wextra -Wconversion -Wfloat-equal -Wformat=2 -Winit-self -Winline -Winvalid-pch -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wstack-protector -Wstrict-null-sentinel -Wswitch-default -Wswitch-enum")
    SET(GCC_COMMON_WARNING_FLAGS "${GCC_COMMON_WARNING_FLAGS} -Wno-unused-parameter")
    SET(GCC_CXX_WARNING_FLAGS "-Wctor-dtor-privacy")
endif ()

#
# Find Doxygen for documentation
#

# add a target to generate API documentation with Doxygen
FIND_PACKAGE(Doxygen)
if (DOXYGEN_FOUND)
    ADD_CUSTOM_TARGET(DOC
        ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Doxyfile
        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/src
        COMMENT "Generating API documentation with Doxygen" VERBATIM
        )
endif ()

#
# Find/install dependencies
#

IF(WIN32)
    INCLUDE(${CMAKE_MODULE_PATH}/Win32-ExternalProjects.txt)
ELSE(UNIX)
    INCLUDE(${CMAKE_MODULE_PATH}/Unix-ExternalProjects.txt)
ENDIF()

#
# Final project settings
#

INCLUDE_DIRECTORIES(include)
ADD_SUBDIRECTORY(src)

ADD_EXECUTABLE(${PROJECT_NAME}
        $
        $
        $
        )

TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBS})

if (DEPENDENCIES)
    MESSAGE (STATUS "Any missing dependencies will be downloaded upon running \"make\"")
    ADD_DEPENDENCIES(${PROJECT_NAME} ${DEPENDENCIES})
endif ()
I'm able to compile everything, but I'm having trouble linking the executable to the libraries:

"C:\Program Files (x86)\CMake\bin\cmake.exe" -HC:\Users\syb0rg\Downloads\Khronos -BC:\Users\syb0rg\Downloads\Khronos\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_progress_start C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\progress.marks
make -f CMakeFiles\Makefile2 all
make[1]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\sphinxbase.dir\build.make CMakeFiles/sphinxbase.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\sphinxbase.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\sphinxbase.dir\build.make CMakeFiles/sphinxbase.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `CMakeFiles/sphinxbase.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 17%] Built target sphinxbase
make -f CMakeFiles\LibSndFile.dir\build.make CMakeFiles/LibSndFile.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\LibSndFile.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\LibSndFile.dir\build.make CMakeFiles/LibSndFile.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `CMakeFiles/LibSndFile.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 35%] Built target LibSndFile
make -f CMakeFiles\pocketsphinx.dir\build.make CMakeFiles/pocketsphinx.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\pocketsphinx.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
make -f CMakeFiles\pocketsphinx.dir\build.make CMakeFiles/pocketsphinx.dir/build
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
make[2]: Nothing to be done for `CMakeFiles/pocketsphinx.dir/build'.
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'
[ 53%] Built target pocketsphinx
make -f CMakeFiles\PortAudio.dir\build.make CMakeFiles/PortAudio.dir/depend
make[2]: Entering directory `C:/Users/syb0rg/Downloads/Khronos/build'
"C:\Program Files (x86)\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build C:\Users\syb0rg\Downloads\Khronos\build\CMakeFiles\PortAudio.dir\DependInfo.cmake --color=
make[2]: Leaving directory `C:/Users/syb0rg/Downloads/Khronos/build'

你可能感兴趣的:(Linux)