ccmakebuild

CMake - Creating a static library


My project Test4 contains two files named:

  1. Structure.h
  2. Structure.c

I am using this project to create a static library that can be used by other software projects.

You can see how my CMake file is configured below:
cmake_minimum_required(VERSION 3.6)
project(Test4)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES Structure.c Structure.h)
add_library(Test4 STATIC ${SOURCE_FILES})

When I build the Test4 project using the CMake configuration file above, no static library is generated. It seems as if nothing happens. Does anyone know what I am doing wrong?

Additionally:

My IDE is JetBrains CLion.


Solution

  • I had the same issue. What I was missing was the location where build files are generated.

    By default, when using CLion, the compiler generates libraries and executables in the cmake-build-* directory. If the setting located at...

    Build > Execution > Deployment > CMake > Configuration

    is set to "Debug", then the generated archive file (.a) file appended with an a, is created under cmake-build-debug.