hosseinmoein / DataFrame

C++ DataFrame for statistical, Financial, and ML analysis -- in modern C++ using native types and contiguous memory storage
https://hosseinmoein.github.io/DataFrame/
BSD 3-Clause "New" or "Revised" License
2.44k stars 309 forks source link

how to write cmakelists.txt after install on windows? #161

Closed xkungfu closed 2 years ago

xkungfu commented 2 years ago

I have installed DataFrame by below steps:


cd I:\CXXlibs\DATAFRAME\DataFrame-2022-01-18\build
cmake .. -G "MinGW Makefiles"
cmake --build .
make install

and the installed files like below:


+---include
|   \---DataFrame
|       |   DataFrame.h
|       |   DataFrameExports.h
|       |   DataFrameFinancialVisitors.h
|       |   DataFrameMLVisitors.h
|       |   DataFrameOperators.h
|       |   DataFrameStatsVisitors.h
|       |   DataFrameTransformVisitors.h
|       |   DataFrameTypes.h
|       |   RandGen.h
|       |
|       +---Internals
|       |       DataFrame.tcc
|       |       DataFrame_functors.h
|       |       DataFrame_get.tcc
|       |       DataFrame_join.tcc
|       |       DataFrame_misc.tcc
|       |       DataFrame_opt.tcc
|       |       DataFrame_private_decl.h
|       |       DataFrame_read.tcc
|       |       DataFrame_set.tcc
|       |       DataFrame_shift.tcc
|       |       DataFrame_standalone.tcc
|       |       DataFrame_visit.tcc
|       |       DataFrame_write.tcc
|       |       RandGen.tcc
|       |
|       +---Utils
|       |       Aggregenerator.h
|       |       DateTime.h
|       |       FixedSizePriorityQueue.h
|       |       FixedSizeString.h
|       |       ThreadGranularity.h
|       |       Utils.h
|       |
|       \---Vectors
|               HeteroPtrView.h
|               HeteroPtrView.tcc
|               HeteroVector.h
|               HeteroVector.tcc
|               HeteroView.h
|               HeteroView.tcc
|               VectorPtrView.h
|               VectorView.h
|
\---lib
    |   libDataFrame.a
    |
    +---cmake
    |   \---DataFrame
    |           DataFrameConfig.cmake
    |           DataFrameConfigVersion.cmake
    |           DataFrameTargets-noconfig.cmake
    |           DataFrameTargets.cmake
    |
    \---pkgconfig
            DataFrame.pc

I think I can use DataFrame now. but how to write my first cmakelists.txt?

I tried write one like below, it is to be sure it would not work, because I am a newbie and have not any clue.

cmake_minimum_required(VERSION 3.21)
project(dataframetest)
set(CMAKE_CXX_STANDARD 17)

include_directories("I:/CXXlibs/DATAFRAME/DataFrame-2022-01-18/cmakeinstalled/include")
include_directories("I:/CXXlibs/DATAFRAME/DataFrame-2022-01-18/cmakeinstalled/lib")

add_executable(hello_world hello_world.cc)

find_library(DataFrame "libDataFrame.a")
add_library(DataFrame)
add_library(DataFrame::DataFrame ALIAS DataFrame)

target_link_libraries(hello_world PRIVATE DataFrame)

can you tell me how to modify this to work? and why there isn't a dll file?

thanks!


windows 10 mingw8.0.0 gcc 9.3.1 qt 5.15.2

xkungfu commented 2 years ago

cmake_minimum_required(VERSION 3.21) project(dataframetest) set(CMAKE_CXX_STANDARD 17)

include_directories("I:/CXXlibs/DATAFRAME/DataFrame-2022-01-18/cmakeinstalled/include") include_directories("I:/CXXlibs/DATAFRAME/DataFrame-2022-01-18/cmakeinstalled/lib")

set(CMAKE_PREFIX_PATH I:/CXXlibs/DATAFRAME/DataFrame-2022-01-18/cmakeinstalled/lib/cmake/DataFrame) find_package(DataFrame REQUIRED)

add_executable(hello_world hello_world.cc)

target_link_libraries(hello_world PRIVATE DataFrame)

target_link_libraries(hello_world PRIVATE DataFrame::DataFrame)

I found the problem. this version works ok.

sorry for naive question.

hosseinmoein commented 2 years ago

np, I am also not a cmake expert. @SpaceIm might be able to provide better suggestions

xkungfu commented 2 years ago

maybe there are some problem in my code, but I don't know. hope @SpaceIm to give a better one. thank you.

SpaceIm commented 2 years ago

Yes, basic usage of CMake while using find_package() in your own CMakeLists to discover properly installed external libs:

cmake_minimum_required(VERSION 3.21)
project(dataframetest)

set(CMAKE_CXX_STANDARD 17)

find_package(DataFrame REQUIRED CONFIG)

add_executable(hello_world hello_world.cc)
target_link_libraries(hello_world PRIVATE DataFrame::DataFrame)

then configure and build your project with CMake (assume MinGW on Windows here):

mkdir build
cd build
cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="<path/to/installed/externalib1>;<path/to/installed/externalib2>;...;<path/to/installed/externalibN>"
cmake --build .

So yes here just populate CMAKE_PREFIX_PATH with root path of DataFrame install location (or the path of the folder of DataFrameConfig.cmake, it also works, the idea is that CMake must be able to see DataFrameConfig.cmake through find_package()). Do not hardcode CMAKE_PREFIX_PATH in your CMakeLists, inject it externally since it's completly specific to your local machine (some IDE provide user config files to set CMake variables to inject, it's very convenient, you can also use a CMakePresets.json I think, an advanced solution, see for example https://www.qt.io/blog/new-features-in-cmake-3.19).

CMAKE_PREFIX_PATH is required only for libraries installed in non-standard location on your system (it's OS specific for CMake, see CMake documentation), and indeed usually you don't want to install external libs for local dev in system location.

xkungfu commented 2 years ago

Yes, basic usage of CMake while using find_package() in your own CMakeLists to discover properly installed external libs:

cmake_minimum_required(VERSION 3.21)
project(dataframetest)

set(CMAKE_CXX_STANDARD 17)

find_package(DataFrame REQUIRED CONFIG)

add_executable(hello_world hello_world.cc)
target_link_libraries(hello_world PRIVATE DataFrame::DataFrame)

then configure and build your project with CMake (assume MinGW on Windows here):

mkdir build
cd build
cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="<path/to/installed/externalib1>;<path/to/installed/externalib2>;...;<path/to/installed/externalibN>"
cmake --build .

So yes here just populate CMAKE_PREFIX_PATH with root path of DataFrame install location (or the path of the folder of DataFrameConfig.cmake, it also works, the idea is that CMake must be able to see DataFrameConfig.cmake through find_package()). Do not hardcode CMAKE_PREFIX_PATH in your CMakeLists, inject it externally since it's completly specific to your local machine (some IDE provide user config files to set CMake variables to inject, it's very convenient, you can also use a CMakePresets.json I think, an advanced solution, see for example https://www.qt.io/blog/new-features-in-cmake-3.19).

CMAKE_PREFIX_PATH is required only for libraries installed in non-standard location on your system (it's OS specific for CMake, see CMake documentation), and indeed usually you don't want to install external libs for local dev in system location.

very clear and detailed explanation. I learned a very useful new knowledge. thanks a lot!