2

Ok so my intention is to create dynamic libraries for mac, windows and linux to be used with Java (both 32 and 64 bit).

I am using Jetbrains products for everything and in my mind I envisioned that, with TeamCity I could have build agents for each platform (which I have set up already) that would then produce the libraries for each platform.

My CMake project is made in CLion. I am a little bit confused by CMake though.

This is currently my cmakelists.txt:

cmake_minimum_required(VERSION 3.7)

project(TestProject)
set(CMAKE_CXX_STANDARD 14)

function(build bits)
    message("Building ${bits} bits...")
    set(CMAKE_BUILD_TYPE Release)

    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin${bits}")
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "bin${bits}")

    if (WIN32)
        include_directories("C:/Program Files/Java/jdk1.8.0_121/include" "C:/Program Files/Java/jdk1.8.0_121/include/win32")
    endif (WIN32)

    #Includes for linux and mac here

    set(SOURCE_FILES src/main.cpp)
    set(EXEC_SOURCE_FILES ${SOURCE_FILES} src/main.cpp)
    add_library(TestProject SHARED ${SOURCE_FILES})
endfunction()

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
    build(64)
else (CMAKE_SIZEOF_VOID_P EQUAL 8)
    build(32)
endif (CMAKE_SIZEOF_VOID_P EQUAL 8)

I'm confused by the concept of CMake, so far, I thought it was kind of like a setup generator, and you then run it on the machine you want to set your progam up on, but I don't understand why then it is already creating my dll library.

That is the behavior I want though, I don't want a setup to run on a machine, I want my .dll and .so files prepped and ready to go and that's it.

Anyways, to get to the question, is the produced library actually usable for distribution? If so, how do I make it generate the .so file on linux, and the .dll file on windows with the same cmakelists.txt? Furthermore, do dependencies get added into the library?

Lastly, does it matter what compiler CMake will use? I have clang on mac, cygwin and mingw-64 on windows, and I think there's just gcc on ubuntu.

I might be too stupid or something, but I can't seem to understand CMake.

Summary list of my requirements:

  • Library needs to be built in 32 and 64 bits (for 32 and 64 bits Java) Compiling 32 and 64 bit
  • It needs to be built as .dll and .so
  • If there are dependencies, they should be put alongside the dll/so in the output folder or better yet, if possible, put them inside my one dll/so.

I've been trying to fit bits and pieces of information together from all over, but I can't get it the way I want it.

Finally, I apologize if this is not an appropriate question but I don't know where else to ask. If there is a better place, let me know and I will delete and repost there.

Limnic
  • 1,826
  • 1
  • 20
  • 45
  • **Too many questions** in one post. `I thought it was kind of like a setup generator, and you then run it on the machine you want to set your progam up on` - Generally, only `CMakeLists.txt` **itself** is supposed to be "portable". After processing this file with `cmake` on a machine, the project created **can be built only on the same machine**. And after installation, this project can be run only on the *same machine*, or on a machine with the **same layout** of (non-system) libraries. There are some exceptions in the above process, but you definitely cannot create `.dll` and `.so` at once. – Tsyvarev Jun 03 '17 at 15:26
  • @Tsyvarev What do you mean with "cannot create a `.dll` and `.so` at once"? I don't want it to build on the same machine, but I want my Linux machine to build my `.so`, my mac to build my `.dylib`, and my windows to build my `.dll` with the same `CMakeLists.txt`. So as long as I don't have non-system dependencies I don't have to worry about having the same layout except for the same operating system? – Limnic Jun 03 '17 at 16:38
  • Run `cmake` on your Linux machine, then build created project, say, with `Makefile`, and you will get `.so`. Run `cmake` on Windows, then build project created, say, with CLion, and you will get `.dll`. For being able to build the project one one machine (e.g. Windows) and get deliverables for other machine (e.g. Linux) you need to have *cross-compiler* and a build tool, which can run it. – Tsyvarev Jun 03 '17 at 17:06
  • Ah thanks, so it's just a matter of first building the setup (cmake) on the machine, then actually running the setup on that same machine (with makefile or something) and collecting the produced result? And repeat that for every OS I want? – Limnic Jun 03 '17 at 17:08
  • 1
    Yes, you need repeat that on every OS you want. – Tsyvarev Jun 03 '17 at 17:15

0 Answers0