You can also require users to have a certain minimum version of CMake (although this can sometimes be a pain for users.) You can specify which version of CMake to emulate when running CMake - so if you have CMake 2.6, you can make a CMakeLists.txt that works like CMake 2.4. It's always good to let people choose their own IDEs/platforms (even if their IDEs/platforms suck a golf ball through a garden hose). However, using CMake, you can specify that you want to create a configuration for a software project that will work for a Make system (Unix), or another IDE like XCode (Mac) or Visual C++ (Windows). Most software projects that are built from source code have to distribute binaries for non-Unix systems (basically, Windows). Recall that linking to shared libraries tells the code where to find the libraries linking to static libraries adds the library code used into the executable.Īdding the following will cause the created Makefiles to be more verbose:Īdvantages and Disadvantages Advantages Cross-Platform The keyword SHARED creates a shared library to create a static library, just remove the keyword "SHARED". So, curl’s header entry should be provided in the vcxproj file: C:\curl\include %(AdditionalIncludeDirectories) 5.2.PROJECT ( mylibrary ) SET ( mylib_SRCS library.cpp ) ADD_LIBRARY ( my SHARED $ )ĪDD_LIBRARY creates a library from the list of source code files in "mylib_SRCS". In the case of Visual Studio, we should introduce the non-standard libraries to the project as an additional dependency. usr/include/x86_64-linux-gnu/curl/curl.h Let’s find the curl.h file with locate: $ locate curl.h Let’s check it out by calling it with the verbose option – v, without the input file: $ cpp -v In the case of GCC, the C Preprocessor cpp looks for headers. So, we need to take it into account when creating a cross-platform program. Moreover, it depends solely on the compiler implementation. In the source code, we don’t need to specify the location of these headers – it’s up to the compiler. We should use it for all standard, system, or third-party libraries. The second form uses brackets to enclose the header file’s name, e.g., #include. So here’s what the folder should contain: C:\curlįinally, we should add the C:\curl\bin folder to the PATH environment variable. For a proper generation of the EXE file, we need curl.h, libcurl.lib, and for running libcurl.dll too. In Windows, we can download the appropriate files and put them into the C:\curl\ folder. Moreover, their locations are known to the GCC tools. On Ubuntu, we can install this library with apt: $ sudo apt install libcurl4-nss-devĪfterwards, we should be provided with both curl header files and shared libraries. Next, we’ll use the curl development library in our program. Let’s assume we’re using the GCC compiler in Linux and Visual Studio in Windows. Since Linux and Windows manage libraries differently, we can handle it with CMake. When creating an executable from the C source code, we often need to provide third-party libraries. Now, we’ll write the corresponding C program, ostest.c: Then, a series of target_compile_definitions commands sets appropriate variables. So, Windows stands for Visual Studio or MinGW GCC under the Windows system. Notably, they describe both the system and the compiler. We rely on the CMake internal code names for platforms, such as Linux, Darwin, or Windows. Target_compile_definitions(ostest PUBLIC "WINDOWS_OS") Target_compile_definitions(ostest PUBLIC "MACOS_OS") Target_compile_definitions(ostest PUBLIC "LINUX_OS") # set variable for the C preprocessor to detect the operatong system To achieve it, we’re going to use CMake’s internal variable CMAKE_SYSTEM_NAME: # CMakeLists file As a result, the instructions for the specific operating system will be compiled. Then the C preprocessor can check if the variable is set, and conditionally arrange the code. For example, under Linux, we’re going to define the variable LINUX_OS, in Windows its name is WINDOW_OS, and so on. So, let’s write a CMakeLists.txt file that defines different variables for each operating system. CMake has the ability to detect the operating system.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |